結果

問題 No.1352 Three Coins
ユーザー lam6er
提出日時 2025-04-16 15:43:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,338 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 154,756 KB
最終ジャッジ日時 2025-04-16 15:46:39
合計ジャッジ時間 4,098 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

# Read input
A, B, C = map(int, input().split())

# Compute GCD of A, B, C
gcd_ab = math.gcd(A, B)
gcd_abc = math.gcd(gcd_ab, C)

if gcd_abc != 1:
    print("INF")
else:
    m = min(A, B, C)
    max_limit = (A + B + C) * max(A, B, C)
    dp = [False] * (max_limit + 1)
    dp[0] = True  # 0 can be formed with x=y=z=0
    current_consecutive = 0
    found = False
    stop_point = max_limit  # Initialize to max_limit in case loop completes without finding

    for i in range(1, max_limit + 1):
        can_form = False
        if i >= A and dp[i - A]:
            can_form = True
        elif i >= B and dp[i - B]:
            can_form = True
        elif i >= C and dp[i - C]:
            can_form = True
        
        if can_form:
            dp[i] = True
            current_consecutive += 1
            if current_consecutive == m:
                stop_point = i
                found = True
                break
        else:
            current_consecutive = 0

    if not found:
        # This case should theoretically not occur as per problem constraints
        print(0)
    else:
        start = stop_point - m + 1
        # Count numbers from 1 to start-1 that cannot be formed
        count = 0
        for num in range(1, start):
            if not dp[num]:
                count += 1
        print(count)
0