結果
| 問題 | No.1352 Three Coins | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-04-15 22:09:09 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,236 bytes | 
| コンパイル時間 | 200 ms | 
| コンパイル使用メモリ | 81,992 KB | 
| 実行使用メモリ | 71,316 KB | 
| 最終ジャッジ日時 | 2025-04-15 22:10:35 | 
| 合計ジャッジ時間 | 2,920 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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)
            
            
            
        