結果

問題 No.1352 Three Coins
ユーザー lam6er
提出日時 2025-04-16 15:38:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 81,520 KB
実行使用メモリ 70,976 KB
最終ジャッジ日時 2025-04-16 15:43:47
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0