結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
|
提出日時 | 2016-07-17 06:11:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 34 ms / 1,000 ms |
コード長 | 1,026 bytes |
コンパイル時間 | 98 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-11-06 20:46:57 |
合計ジャッジ時間 | 3,270 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
#!/usr/bin/python3 inf = float('inf') def bye(s): print(s) exit(0) def ok(x, y, z): ok1 = x > y and y < z ok2 = x < y and y > z return x!=z and (ok1 or ok2) def count(my, your, d): if your==0: return inf if my < your: return 0 return (my - your + d) // d def cut(my, d, times): return max(0, my-d*times) d = int(input()) h1 = int(input()) h2 = int(input()) h3 = int(input()) assert 0 <= d <= 10**9 assert 0 <= h1 <= 10**9 assert 0 <= h2 <= 10**9 assert 0 <= h3 <= 10**9 if ok(h1, h2, h3): bye('0') if d==0: bye('-1') r1 = 0 x, y, z = h1, h2, h3 if x==z: x = cut(x, d, 1) r1 += 1 p = count(x, y, d) r1 += p x = cut(x, d, p) q = count(z, y, d) r1 += q z = cut(z, d, q) if not ok(x, y, z): r1 = inf r2 = 0 x, y, z = h1, h2, h3 if x==z: x = cut(x, d, 1) r2 += 1 p = count(y, x, d) r2 += p y = cut(y, d, p) q = count(y, z, d) r2 += q y = cut(y, d, q) if not ok(x, y, z): r2 = inf res = min(r1, r2) if res >= inf: res = -1 print(res)