結果
| 問題 | No.281 門松と魔法(1) |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-10-25 14:37:19 |
| 言語 | PyPy3 (8.0.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 32 ms / 1,000 ms |
| + 103µs | |
| コード長 | 1,044 bytes |
| 記録 | |
| コンパイル時間 | 81 ms |
| コンパイル使用メモリ | 64,564 KB |
| 実行使用メモリ | 53,652 KB |
| 最終ジャッジ日時 | 2026-10-25 14:37:44 |
| 合計ジャッジ時間 | 4,449 ms |
|
ジャッジサーバーID (参考情報) |
judge6_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 58 |
ソースコード
def ceildiv(a: int, b: int) -> int:
return (a + b - 1) // b
def is_kadomatu(a, b, c) -> bool:
if a == c: return False
return (a < b > c) or (a > b < c)
INF = 1 << 60
D = int(input())
H1 = int(input())
H2 = int(input())
H3 = int(input())
if D == 0:
if is_kadomatu(H1, H2, H3):
print(0)
else:
print(-1)
exit()
# a > b > c にするのに必要な操作回数
def f(a, b, c):
res = 0
if a <= b:
x = ceildiv(b-a, D)
res += x
b = max(0, b - x * D)
if a == b:
res += 1
b = max(0, b - D)
if b <= c:
x = ceildiv(c-b, D)
res += x
c = max(0, c - x * D)
if b == c:
res += 1
c = max(0, c - D)
if a > b > c >= 0:
return res
return INF
ans = INF
# 真ん中が一番低い、または一番高い
for a, b, c in [(H2, H1, H3), (H2, H3, H1), (H1, H3, H2), (H3, H1, H2)]:
res = f(a, b, c)
ans = min(ans, res)
if ans == INF:
print(-1)
else:
print(ans)
norioc