結果
問題 | No.281 門松と魔法(1) |
ユーザー |
|
提出日時 | 2015-09-18 23:29:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,886 bytes |
コンパイル時間 | 1,439 ms |
コンパイル使用メモリ | 159,972 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 19:28:43 |
合計ジャッジ時間 | 2,793 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 WA * 2 |
ソースコード
#include <bits/stdc++.h> #define rep(i, a) rep2 (i, 0, a) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) repr2 (i, 0, a) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define chmin(a, b) ((b) < a && (a = (b), true)) #define chmax(a, b) (a < (b) && (a = (b), true)) #define rng(a) (a).begin(), (a).end() using namespace std; typedef long long ll; int main() { ll d, h1, h2, h3; cin >> d >> h1 >> h2 >> h3; if (h1 < h2 && h2 > h3 && h1 != h3) { cout << 0 << endl; return 0; } if (h1 > h2 && h2 < h3 && h1 != h3) { cout << 0 << endl; return 0; } if (d == 0) { cout << -1 << endl; return 0; } const ll inf = 1e18; auto f = [&](ll a, ll b) { if (a < b) return inf; return (a - b + d) / d; }; auto g = [&](ll a) { return max(0ll, a - d); }; ll ans = inf; { ll th1 = h1; ll cand = 0; if (th1 == h3) th1 = g(th1), cand++; ll c = f(h2, min(th1, h3)); cand += c; ll th2 = max(0ll, h2 - c * d); if (th1 == th2 || th2 == h3 || h3 == th1) cand = inf; cerr << cand << endl; chmin(ans, cand); } { ll th3 = h3; ll cand = 0; if (h2 == th3) th3 = g(th3), cand++; ll c = f(h1, h3); cand += c; ll th1 = max(0ll, h1 - c * d); if (th1 == h2 || h2 == th3 || th3 == th1) cand = inf; cerr << cand << endl; chmin(ans, cand); } { ll th1 = h1; ll cand = 0; if (th1 == h2) th1 = g(th1), cand++; ll c = f(h3, h2); cand += c; ll th3 = max(0ll, h3 - c * d); if (th1 == h2 || h2 == th3 || th3 == th1) cand = inf; cerr << cand << endl; chmin(ans, cand); } if (ans >= inf) ans = -1; cout << ans << endl; }