結果
問題 | No.281 門松と魔法(1) |
ユーザー | pekempey |
提出日時 | 2015-09-19 00:51:37 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,092 bytes |
コンパイル時間 | 1,280 ms |
コンパイル使用メモリ | 160,008 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 19:33:17 |
合計ジャッジ時間 | 2,931 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 1 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 1 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,820 KB |
testcase_17 | AC | 2 ms
6,816 KB |
testcase_18 | AC | 2 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 2 ms
6,820 KB |
testcase_22 | AC | 2 ms
6,816 KB |
testcase_23 | AC | 2 ms
6,816 KB |
testcase_24 | AC | 1 ms
6,816 KB |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 1 ms
6,820 KB |
testcase_27 | AC | 2 ms
6,816 KB |
testcase_28 | AC | 2 ms
6,816 KB |
testcase_29 | AC | 2 ms
6,816 KB |
testcase_30 | AC | 2 ms
6,816 KB |
testcase_31 | AC | 2 ms
6,820 KB |
testcase_32 | AC | 2 ms
6,816 KB |
testcase_33 | AC | 2 ms
6,816 KB |
testcase_34 | AC | 2 ms
6,820 KB |
testcase_35 | AC | 2 ms
6,820 KB |
testcase_36 | AC | 2 ms
6,820 KB |
testcase_37 | AC | 1 ms
6,816 KB |
testcase_38 | AC | 2 ms
6,820 KB |
testcase_39 | AC | 2 ms
6,816 KB |
testcase_40 | AC | 2 ms
6,816 KB |
testcase_41 | AC | 1 ms
6,816 KB |
testcase_42 | AC | 2 ms
6,820 KB |
testcase_43 | AC | 2 ms
6,816 KB |
testcase_44 | AC | 1 ms
6,820 KB |
testcase_45 | AC | 1 ms
6,820 KB |
testcase_46 | AC | 1 ms
6,820 KB |
testcase_47 | AC | 2 ms
6,820 KB |
testcase_48 | AC | 1 ms
6,820 KB |
testcase_49 | AC | 2 ms
6,816 KB |
testcase_50 | AC | 1 ms
6,816 KB |
testcase_51 | WA | - |
testcase_52 | AC | 2 ms
6,816 KB |
testcase_53 | AC | 2 ms
6,816 KB |
testcase_54 | AC | 2 ms
6,820 KB |
testcase_55 | AC | 2 ms
6,816 KB |
testcase_56 | WA | - |
ソースコード
#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 (h2 == th1) th1 = g(th1), cand++; ll c = f(h3, h1); cand += c; ll th3 = max(0ll, h3 - c * d); if (th1 == h2 || h2 == th3 || th3 == th1) cand = inf; cerr << cand << endl; chmin(ans, cand); } { ll th3 = h1; ll cand = 0; if (th3 == h2) th3 = g(th3), cand++; ll c = f(h1, h2); 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; }