結果
問題 |
No.1352 Three Coins
|
ユーザー |
![]() |
提出日時 | 2025-04-15 22:06:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 172 ms / 2,000 ms |
コード長 | 1,338 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 81,764 KB |
実行使用メモリ | 155,412 KB |
最終ジャッジ日時 | 2025-04-15 22:08:26 |
合計ジャッジ時間 | 3,357 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
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)