結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:44:37 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,118 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 82,664 KB |
| 実行使用メモリ | 54,572 KB |
| 最終ジャッジ日時 | 2025-06-12 16:44:42 |
| 合計ジャッジ時間 | 4,150 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 WA * 7 |
ソースコード
d = int(input())
h1 = int(input())
h2 = int(input())
h3 = int(input())
if d == 0:
a, b, c = h1, h2, h3
if a != b and b != c and a != c and ((b > a and b > c) or (b < a and b < c)):
print(0)
else:
print(-1)
exit()
def generate_candidates(h, d_val):
if d_val == 0:
return [(h, 0)]
candidates = []
seen = set()
max_k = (h + d_val - 1) // d_val # Ceiling division
for k in [0, 1, 2, max_k]:
new_h = max(0, h - k * d_val)
if new_h not in seen:
seen.add(new_h)
candidates.append((new_h, k))
return candidates
c1 = generate_candidates(h1, d)
c2 = generate_candidates(h2, d)
c3 = generate_candidates(h3, d)
min_operations = float('inf')
for (a, ka) in c1:
for (b, kb) in c2:
for (c, kc) in c3:
if a == b or b == c or a == c:
continue
if (b > a and b > c) or (b < a and b < c):
total = ka + kb + kc
if total < min_operations:
min_operations = total
print(min_operations if min_operations != float('inf') else -1)
gew1fw