結果

問題 No.2695 Warp Zone
ユーザー nikoro256nikoro256
提出日時 2024-03-22 22:47:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,923 ms / 2,000 ms
コード長 1,225 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 471,432 KB
最終ジャッジ日時 2024-03-22 22:48:06
合計ジャッジ時間 19,554 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,604 KB
testcase_01 AC 42 ms
55,604 KB
testcase_02 AC 43 ms
55,604 KB
testcase_03 AC 1,920 ms
468,616 KB
testcase_04 AC 1,908 ms
455,176 KB
testcase_05 AC 1,858 ms
454,284 KB
testcase_06 AC 1,923 ms
458,628 KB
testcase_07 AC 1,917 ms
471,432 KB
testcase_08 AC 76 ms
72,516 KB
testcase_09 AC 487 ms
203,936 KB
testcase_10 AC 44 ms
55,604 KB
testcase_11 AC 188 ms
107,256 KB
testcase_12 AC 788 ms
275,624 KB
testcase_13 AC 43 ms
55,604 KB
testcase_14 AC 982 ms
328,352 KB
testcase_15 AC 440 ms
187,184 KB
testcase_16 AC 183 ms
102,392 KB
testcase_17 AC 275 ms
137,336 KB
testcase_18 AC 1,409 ms
382,740 KB
testcase_19 AC 68 ms
70,560 KB
testcase_20 AC 1,098 ms
340,892 KB
testcase_21 AC 959 ms
321,032 KB
testcase_22 AC 400 ms
173,304 KB
testcase_23 AC 746 ms
273,960 KB
testcase_24 AC 48 ms
55,604 KB
testcase_25 AC 43 ms
55,604 KB
testcase_26 AC 49 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
def dijkstra(s):
    hq=[]
    heapq.heappush(hq,[0,s])
    dist=[-1 for _ in range(N)]
    karidist=[10**9+1 for _ in range(N)]
    while len(hq)!=0:
        d,p=heapq.heappop(hq)
        if dist[p]==-1:
            dist[p]=d
            for e,c in edge[p]:
                if karidist[e]>d+c:
                    karidist[e]=d+c
                    heapq.heappush(hq,[d+c,e])
    return dist

def csv(i,j):
    return i*W+j

import sys
input=sys.stdin.readline
H,W,N=map(int,input().split())
dat=[]
poses=[(0,0),(H-1,W-1)]
poses=set(poses)
for i in range(N):
    a,b,c,d=map(int,input().split())
    a-=1
    b-=1
    c-=1
    d-=1
    dat.append([a,b,c,d])
    poses.add((a,b))
    poses.add((c,d))
edge=[[] for _ in range(len(poses))]
poses=list(poses)
from collections import defaultdict
dic=defaultdict(lambda:-1)
for i in range(len(poses)):
    dic[poses[i]]=i
for a,b,c,d in dat:
    edge[dic[(a,b)]].append([dic[(c,d)],1])
for i in range(len(poses)):
    for j in range(i+1,len(poses)):
        a,b=poses[i]
        c,d=poses[j]
        edge[i].append([j,abs(a-c)+abs(b-d)])
        edge[j].append([i,abs(a-c)+abs(b-d)])
N=len(poses)
dist=dijkstra(poses.index((0,0)))
print(dist[poses.index((H-1,W-1))])
0