結果

問題 No.2695 Warp Zone
ユーザー nikoro256nikoro256
提出日時 2024-03-22 22:43:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,162 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 27,412 KB
最終ジャッジ日時 2024-03-22 22:43:30
合計ジャッジ時間 4,097 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
17,044 KB
testcase_01 AC 32 ms
10,240 KB
testcase_02 AC 33 ms
10,240 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 #

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[poses.index((a,b))].append([poses.index((c,d)),abs(a-c)+abs(b-d)])
        edge[poses.index((c,d))].append([poses.index((a,b)),abs(a-c)+abs(b-d)])
N=len(poses)
dist=dijkstra(poses.index((0,0)))
print(dist[poses.index((H-1,W-1))])
0