結果

問題 No.2695 Warp Zone
ユーザー miztommiztom
提出日時 2024-03-22 22:05:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 858 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 453,968 KB
最終ジャッジ日時 2024-03-22 22:05:44
合計ジャッジ時間 3,981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
60,264 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import*
h,w,n=map(int,input().split())
dh={1,h}
dw={1,w}
ab=[[*map(int,input().split())]for i in range(n)]
for a,b,c,d in ab:dh|={a,c};dw|={b,d}
dh=sorted(dh)
dhd={j:i for i,j in enumerate(dh)}
dw=sorted(dw)
dwd={j:i for i,j in enumerate(dw)}
D=[[[-1,None]for j in range(len(dw))]+[[1,None]]for i in range(len(dh))]+[[[1,None]]*(len(dw)+1)]
for a,b,c,d in ab:D[dhd[a]][dwd[b]][1]=(dhd[c],dwd[d])
h=[(0,0,0)]
while h:
    e,a,b=heappop(h)
    if D[a][b][0]<0:
        D[a][b][0]=e
        if D[a][b][1]:
            c,d=D[a][b][1]
            if D[c][d][0]<0:heappush(h,(e+1,c,d))
        if D[a-1][b][0]<0:heappush(h,(e+dh[a]-dh[a-1],a-1,b))
        if D[a+1][b][0]<0:heappush(h,(e+dh[a+1]-dh[a],a+1,b))
        if D[a][b-1][0]<0:heappush(h,(e+dw[b]-dw[b-1],a,b-1))
        if D[a][b+1][0]<0:heappush(h,(e+dw[b+1]-dw[b],a,b+1))
print(D[-2][-2][0])
0