結果

問題 No.2695 Warp Zone
ユーザー nikoro256nikoro256
提出日時 2024-03-22 22:44:53
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,094 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 470,100 KB
最終ジャッジ日時 2024-03-22 22:45:14
合計ジャッジ時間 19,789 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 41 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 TLE -
testcase_04 AC 1,908 ms
455,636 KB
testcase_05 AC 1,855 ms
447,828 KB
testcase_06 AC 1,951 ms
459,988 KB
testcase_07 AC 1,994 ms
465,492 KB
testcase_08 AC 70 ms
70,448 KB
testcase_09 AC 478 ms
203,388 KB
testcase_10 AC 41 ms
53,460 KB
testcase_11 AC 198 ms
106,744 KB
testcase_12 AC 827 ms
274,804 KB
testcase_13 AC 41 ms
53,460 KB
testcase_14 AC 1,036 ms
327,016 KB
testcase_15 AC 429 ms
186,768 KB
testcase_16 AC 189 ms
102,128 KB
testcase_17 AC 317 ms
137,072 KB
testcase_18 AC 1,441 ms
379,492 KB
testcase_19 AC 69 ms
70,584 KB
testcase_20 AC 1,113 ms
341,348 KB
testcase_21 AC 1,016 ms
325,096 KB
testcase_22 AC 421 ms
173,168 KB
testcase_23 AC 801 ms
273,268 KB
testcase_24 AC 41 ms
53,460 KB
testcase_25 AC 41 ms
53,460 KB
testcase_26 AC 41 ms
53,460 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

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)
for a,b,c,d in dat:
    edge[poses.index((a,b))].append([poses.index((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