結果

問題 No.2695 Warp Zone
ユーザー june19312june19312
提出日時 2024-03-22 23:38:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,652 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 426,712 KB
最終ジャッジ日時 2024-03-22 23:38:22
合計ジャッジ時間 18,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,460 KB
testcase_01 AC 43 ms
53,460 KB
testcase_02 AC 46 ms
58,816 KB
testcase_03 AC 1,652 ms
426,712 KB
testcase_04 AC 1,577 ms
413,148 KB
testcase_05 AC 1,606 ms
413,148 KB
testcase_06 AC 1,626 ms
423,512 KB
testcase_07 AC 1,644 ms
426,708 KB
testcase_08 AC 73 ms
72,620 KB
testcase_09 AC 589 ms
189,084 KB
testcase_10 AC 45 ms
58,816 KB
testcase_11 AC 219 ms
105,968 KB
testcase_12 AC 770 ms
240,396 KB
testcase_13 AC 42 ms
53,460 KB
testcase_14 AC 940 ms
288,384 KB
testcase_15 AC 487 ms
174,880 KB
testcase_16 AC 194 ms
101,488 KB
testcase_17 AC 315 ms
133,372 KB
testcase_18 AC 1,318 ms
342,140 KB
testcase_19 AC 69 ms
70,680 KB
testcase_20 AC 1,079 ms
312,440 KB
testcase_21 AC 968 ms
284,664 KB
testcase_22 AC 418 ms
163,568 KB
testcase_23 AC 729 ms
238,476 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 #

from heapq import heappush,heappop
H,W,N = map(int,input().split())

ten = {}
cnt = 1
warp = {}

ten[(1,1)] = 1
cnt += 1
for i in range(N):
    a,b,c,d = map(int,input().split()) #a=頂点,b=頂点,c=コスト
    if (a,b) not in ten:
        ten[(a,b)] = cnt
        cnt+=1
    if (c,d) not in ten:
        ten[(c,d)] = cnt
        cnt+=1
    
    warp[(a,b,c,d)] = True

ten[(H,W)] = cnt

G = [[] for _ in range(cnt+1)]

for ind1,val1 in ten.items():
    for ind2,val2 in ten.items():
        if val1 == val2:
            continue
        aa,bb,cc,dd = ind1[0],ind1[1],ind2[0],ind2[1]
        if (aa,bb,cc,dd) in warp:
            G[val1].append([val2,1])
        else:
            cost = abs(aa-cc) + abs(bb-dd)
            G[val1].append([val2,cost])

dist = [-1]*(cnt+1)
visited = [False]*(cnt+1)

Q = []
heappush(Q,(0,1)) #◆=出発地点コスト(通常は0),◇=出発地点の頂点
dist[1] = 0

while len(Q)>0:
    a,b = heappop(Q) #a=コスト(◆),b=頂点(◇)

    if visited[b]:
        continue

    visited[b] = True

    for c,d in G[b]: #c=頂点,d=コスト
        if dist[c] == -1 or dist[c] > dist[b]+d:
            dist[c] = dist[b]+d
            heappush(Q,(dist[c],c))

print(dist[-1])
0