結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
![]() |
提出日時 | 2015-09-18 23:55:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,782 bytes |
コンパイル時間 | 422 ms |
コンパイル使用メモリ | 55,132 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-06 19:30:53 |
合計ジャッジ時間 | 1,907 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 48 WA * 9 |
ソースコード
//最高位はたたかない。k位にするものはk-1位より短くなるまで叩く。ただし負になったらGEND。 #include <iostream> #define LL long long using namespace std; LL d; LL h[4]; int main() { LL H[4]; LL N[4]; LL ans = 1145141919893810; cin >> d; cin >> h[1] >> h[2] >> h[3]; //d == 0の場合は別途処理 if( d == 0 ){ bool ok = false; ok |= ( h[1] < h[3] && h[3] < h[2] ); ok |= ( h[3] < h[1] && h[1] < h[2] ); ok |= ( h[2] < h[1] && h[1] < h[3] ); ok |= ( h[2] < h[3] && h[3] < h[1] ); if( ok ) cout << 0 << endl; else cout << -1 << endl; return 0; } //h[1] < h[3] < h[2] N[2] = 0; H[2] = h[2]; N[3] = max((LL)0, (h[3] - H[2] + d)/d); H[3] = h[3] - N[3] * d; N[1] = max((LL)0, (h[1] - H[3] + d)/d); H[1] = h[1] - N[1] * d; if( H[1] < H[3] && H[3] < H[2] && H[1] >= 0 ) ans = min(ans, N[1] + N[2] + N[3]); //h[3] < h[1] < h[2] N[2] = 0; H[2] = h[2]; N[1] = max((LL)0, (h[1] - H[2] + d)/d); H[1] = h[1] - N[1] * d; N[3] = max((LL)0, (h[3] - H[1] + d)/d); H[3] = h[3] - N[3] * d; if( H[3] < H[1] && H[1] < H[2] && H[3] >= 0 ) ans = min(ans, N[1] + N[2] + N[3]); //h[2] < h[1] < h[3] N[3] = 0; H[3] = h[3]; N[1] = max((LL)0, (h[1] - H[3] + d)/d); H[1] = h[1] - N[1] * d; N[2] = max((LL)0, (h[2] - H[1] + d)/d); H[2] = h[2] - N[2] * d; if( H[2] < H[1] && H[1] < H[3] && H[2] >= 0 ) ans = min(ans, N[1] + N[2] + N[3]); //h[2] < h[3] < h[1] N[1] = 0; H[1] = h[1]; N[3] = max((LL)0, (h[3] - H[1] + d)/d); H[3] = h[3] - N[3] * d; N[2] = max((LL)0, (h[2] - H[3] + d)/d); H[2] = h[2] - N[2] * d; if( H[2] < H[3] && H[3] < H[1] && H[2] >= 0 ) ans = min(ans, N[1] + N[2] + N[3]); if( ans == 1145141919893810 ) cout << -1 << endl; else cout << ans << endl; return 0; }