結果

問題 No.1352 Three Coins
コンテスト
ユーザー rin204
提出日時 2022-03-21 21:41:09
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 514 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 510 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 73,088 KB
最終ジャッジ日時 2026-04-25 15:43:09
合計ジャッジ時間 4,326 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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