結果

問題 No.126 2基のエレベータ
ユーザー 👑 KazunKazun
提出日時 2022-01-10 05:31:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 70,656 KB
最終ジャッジ日時 2024-04-26 20:00:45
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
69,504 KB
testcase_01 AC 51 ms
62,208 KB
testcase_02 AC 41 ms
57,472 KB
testcase_03 AC 45 ms
60,160 KB
testcase_04 AC 56 ms
62,592 KB
testcase_05 AC 43 ms
57,088 KB
testcase_06 AC 43 ms
57,856 KB
testcase_07 AC 54 ms
63,104 KB
testcase_08 AC 54 ms
63,232 KB
testcase_09 AC 56 ms
63,232 KB
testcase_10 AC 43 ms
52,608 KB
testcase_11 AC 45 ms
57,984 KB
testcase_12 AC 46 ms
57,728 KB
testcase_13 AC 44 ms
57,984 KB
testcase_14 AC 58 ms
64,128 KB
testcase_15 AC 62 ms
68,864 KB
testcase_16 AC 64 ms
69,888 KB
testcase_17 AC 61 ms
69,120 KB
testcase_18 AC 53 ms
63,360 KB
testcase_19 AC 39 ms
52,608 KB
testcase_20 AC 64 ms
70,016 KB
testcase_21 AC 53 ms
62,464 KB
testcase_22 AC 55 ms
63,488 KB
testcase_23 AC 49 ms
60,544 KB
testcase_24 AC 52 ms
62,720 KB
testcase_25 AC 52 ms
63,232 KB
testcase_26 AC 70 ms
69,744 KB
testcase_27 AC 66 ms
68,864 KB
testcase_28 AC 69 ms
70,656 KB
testcase_29 AC 61 ms
68,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush,heappop

def check(d,t):
    a,b,s=t
    if d<T.get((a,b,s),inf):
        T[(a,b,s)]=d
        heappush(Q,(d,(a,b,s)))

A,B,S=map(int,input().split())

inf=10**9
T={(A,B,S):0}
Q=[(0,(A,B,S))]

while True:
    d,(a,b,s)=heappop(Q)
    if s==0:
        break

    if s==1:
        check(d+abs(a-1)+abs(1-0),(0,b,0))

    if a==s:
        for k in range(101):
            check(d+abs(a-k),(k,b,k))
    elif b==s:
        for k in range(1,101):
            check(d+abs(b-k),(a,k,k))
    else:
        if abs(a-s)<=abs(b-s):
            check(d+abs(a-s),(s,b,s))
        else:
            check(d+abs(b-s),(a,s,s))

print(d)
0