結果
| 問題 | No.1352 Three Coins | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-03-21 21:41:09 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 86 ms / 2,000 ms | 
| コード長 | 514 bytes | 
| コンパイル時間 | 197 ms | 
| コンパイル使用メモリ | 81,920 KB | 
| 実行使用メモリ | 72,832 KB | 
| 最終ジャッジ日時 | 2024-10-09 12:34:26 | 
| 合計ジャッジ時間 | 3,466 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 34 | 
ソースコード
from math import gcd
from heapq import *
a, b, c = map(int, input().split())
if gcd(a, gcd(b, c)) != 1:
    print("INF")
    exit()
    
a, b, c = sorted([a, b, c])
inf = 1 << 30
dist = [inf] * a
dist[0] = 0
hq = [(0, 0)]
while hq:
    d, pos = heappop(hq)
    if dist[pos] < d:
        continue
    i = d * a + pos
    for x in [b, c]:
        ni = i + x
        nd = ni // a
        npos = ni - a * nd
        if dist[npos] > nd:
            dist[npos] = nd
            heappush(hq, (nd, npos))
print(sum(dist))
            
            
            
        