結果

問題 No.2695 Warp Zone
ユーザー titiatitia
提出日時 2024-03-22 23:05:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,484 KB
最終ジャッジ日時 2024-03-22 23:05:14
合計ジャッジ時間 5,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 41 ms
53,460 KB
testcase_02 AC 43 ms
53,460 KB
testcase_03 AC 222 ms
78,484 KB
testcase_04 AC 224 ms
78,268 KB
testcase_05 AC 223 ms
78,384 KB
testcase_06 AC 213 ms
77,772 KB
testcase_07 AC 217 ms
78,160 KB
testcase_08 AC 62 ms
65,872 KB
testcase_09 AC 185 ms
77,860 KB
testcase_10 AC 42 ms
53,460 KB
testcase_11 AC 156 ms
77,144 KB
testcase_12 AC 184 ms
77,604 KB
testcase_13 AC 43 ms
53,460 KB
testcase_14 AC 186 ms
77,628 KB
testcase_15 AC 169 ms
77,448 KB
testcase_16 AC 130 ms
76,864 KB
testcase_17 AC 151 ms
77,168 KB
testcase_18 AC 215 ms
77,648 KB
testcase_19 AC 59 ms
63,788 KB
testcase_20 AC 198 ms
77,688 KB
testcase_21 AC 188 ms
77,780 KB
testcase_22 AC 159 ms
77,496 KB
testcase_23 AC 174 ms
77,540 KB
testcase_24 AC 43 ms
53,460 KB
testcase_25 AC 42 ms
53,460 KB
testcase_26 AC 43 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from operator import itemgetter
from heapq import heappop,heappush

H,W,N=map(int,input().split())
WA=[list(map(int,input().split())) for i in range(N)]

WA=[[1,1,1,1]]+WA+[[H,W,H,W]]

DP=[1<<63]*len(WA)
WA.sort(key=itemgetter(0))
WA.sort(key=itemgetter(1))

DP[0]=0

Q=[(0,0)]

while Q:
    time,ind=heappop(Q)

    if DP[ind]!=time:
        continue

    a,b,c,d=WA[ind]
    for j in range(len(WA)):
        e,f,g,h=WA[j]


        dis=abs(e-a)+abs(f-b)

        if DP[j]>DP[ind]+dis:
            DP[j]=DP[ind]+dis
            heappush(Q,(DP[j],j))


        dis=abs(e-c)+abs(f-d)

        if DP[j]>DP[ind]+dis+1:
            DP[j]=DP[ind]+dis+1
            heappush(Q,(DP[j],j))


print(DP[-1])
0