結果
| 問題 |
No.1352 Three Coins
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 22:07:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,236 bytes |
| コンパイル時間 | 308 ms |
| コンパイル使用メモリ | 81,756 KB |
| 実行使用メモリ | 71,476 KB |
| 最終ジャッジ日時 | 2025-04-15 22:09:02 |
| 合計ジャッジ時間 | 3,373 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 WA * 2 |
ソースコード
import math
A, B, C = map(int, input().split())
def gcd_three(a, b, c):
return math.gcd(math.gcd(a, b), c)
g = gcd_three(A, B, C)
if g != 1:
print("INF")
else:
if A == 1 or B == 1 or C == 1:
print(0)
else:
m = min(A, B, C)
max_limit = 10**6
dp = [False] * (max_limit + 1)
dp[0] = True
consecutive = 0
max_i = 0
found = False
for i in range(1, max_limit + 1):
can_form = False
if i - A >= 0 and dp[i - A]:
can_form = True
if not can_form and i - B >= 0 and dp[i - B]:
can_form = True
if not can_form and i - C >= 0 and dp[i - C]:
can_form = True
if can_form:
dp[i] = True
consecutive += 1
if consecutive == m:
max_i = i
found = True
break
else:
consecutive = 0
if not found:
print("INF")
else:
count = 0
upper = max_i - m
for i in range(1, upper + 1):
if not dp[i]:
count += 1
print(count)
lam6er