結果

問題 No.2695 Warp Zone
ユーザー tkykwtnbtkykwtnb
提出日時 2024-03-23 16:56:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 981 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 306,348 KB
最終ジャッジ日時 2024-03-23 16:56:33
合計ジャッジ時間 4,052 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
62,280 KB
testcase_01 AC 36 ms
55,476 KB
testcase_02 AC 37 ms
55,476 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 #

H,W,N=map(int,input().split())
from collections import defaultdict,deque
G=defaultdict(defaultdict)
C=defaultdict(int)
I=[]
O=[]
G[(1,1)][(H,W)]=H-1+W-1
for _ in range(N):
    a,b,c,d=map(int,input().split())
    G[(1,1)][(a,b)]=a-1+b-1
    G[(1,1)][(c,d)]=c-1+d-1
    G[(a,b)][(H,W)]=H-a+H-b
    G[(c,d)][(H,W)]=H-c+W-d
    G[(a,b)][(c,d)]=1
    C[(a,b)]=1<<60
    C[(c,d)]=1<<60
    I.append((a,b))
    O.append((c,d))
for c,d in O:
    for a,b in I:
        if not (a,b) in G[(c,d)].keys():G[(c,d)][(a,b)]=abs(c-a)+abs(d-b)
        else:G[(c,d)][(a,b)]=min(G[(c,d)][(a,b)],abs(c-a)+abs(d-b))
        if not (c,d) in G[(a,b)].keys():G[(a,b)][(c,d)]=abs(c-a)+abs(d-b)
        else:G[(a,b)][(c,d)]=min(G[(a,b)][(c,d)],abs(c-a)+abs(d-b))
C[(H,W)]=1<<60
C[(1,1)]=0
Q=deque()
Q.append((1,1))
while Q:
    a,b=Q.popleft()
    for c,d in G[(a,b)].keys():
        tmp=C[(a,b)]+G[(a,b)][(c,d)]
        if tmp<C[(c,d)]:
            C[(c,d)]=tmp
            Q.append((c,d))
print(C[(H,W)])
0