結果

問題 No.2695 Warp Zone
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-03-25 12:59:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,197 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,016 KB
最終ジャッジ日時 2024-03-25 12:59:30
合計ジャッジ時間 14,281 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,596 KB
testcase_01 AC 40 ms
55,596 KB
testcase_02 AC 40 ms
55,596 KB
testcase_03 AC 1,179 ms
77,824 KB
testcase_04 AC 1,197 ms
78,016 KB
testcase_05 AC 1,178 ms
77,736 KB
testcase_06 AC 1,176 ms
77,816 KB
testcase_07 AC 1,184 ms
77,700 KB
testcase_08 AC 72 ms
73,444 KB
testcase_09 AC 452 ms
77,740 KB
testcase_10 AC 41 ms
55,596 KB
testcase_11 AC 183 ms
76,828 KB
testcase_12 AC 587 ms
77,604 KB
testcase_13 AC 40 ms
55,596 KB
testcase_14 AC 694 ms
77,712 KB
testcase_15 AC 458 ms
77,792 KB
testcase_16 AC 160 ms
76,820 KB
testcase_17 AC 276 ms
77,660 KB
testcase_18 AC 892 ms
77,688 KB
testcase_19 AC 66 ms
70,472 KB
testcase_20 AC 759 ms
77,800 KB
testcase_21 AC 739 ms
77,708 KB
testcase_22 AC 340 ms
77,620 KB
testcase_23 AC 572 ms
77,688 KB
testcase_24 AC 41 ms
55,596 KB
testcase_25 AC 41 ms
55,596 KB
testcase_26 AC 40 ms
55,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
from collections import defaultdict
H,W,N=map(int,input().split())
ABCD=[tuple(map(int,input().split())) for _ in range(N)]

dist=defaultdict(int)
pos=(1,1)
dist[pos]=0
Q=[]
heapq.heapify(Q)
heapq.heappush(Q,(dist[pos],pos))
while len(Q):
    e,(i,j)=heapq.heappop(Q)
    for (a,b,c,d) in ABCD:
        if (i,j)==(a,b):
            if dist.get((c,d)) is None or e+1<dist[(c,d)]:
                dist[(c,d)]=e+1
                heapq.heappush(Q,(dist[(c,d)],(c,d)))
        else:
            dd=abs(i-a)+abs(j-b)
            if dist.get((a,b)) is None or e+dd<dist[(a,b)]:
                dist[(a,b)]=e+dd
                heapq.heappush(Q,(dist[(a,b)],(a,b)))
    dd=abs(i-H)+abs(j-W)
    if dist.get((H,W)) is None or e+dd<dist[(H,W)]:
        dist[(H,W)]=e+dd
        heapq.heappush(Q,(dist[(H,W)],(H,W)))
print(dist[(H,W)])

0