結果

問題 No.2695 Warp Zone
ユーザー hato336hato336
提出日時 2024-03-22 21:47:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 91,064 KB
最終ジャッジ日時 2024-03-22 21:47:38
合計ジャッジ時間 7,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
85,048 KB
testcase_01 AC 141 ms
85,048 KB
testcase_02 AC 131 ms
84,920 KB
testcase_03 AC 389 ms
90,680 KB
testcase_04 AC 347 ms
91,064 KB
testcase_05 AC 356 ms
90,680 KB
testcase_06 AC 373 ms
90,808 KB
testcase_07 AC 347 ms
90,680 KB
testcase_08 AC 156 ms
88,888 KB
testcase_09 AC 303 ms
90,808 KB
testcase_10 AC 130 ms
85,048 KB
testcase_11 AC 246 ms
89,912 KB
testcase_12 AC 301 ms
90,552 KB
testcase_13 AC 126 ms
85,048 KB
testcase_14 AC 310 ms
90,552 KB
testcase_15 AC 251 ms
90,168 KB
testcase_16 AC 231 ms
89,784 KB
testcase_17 AC 234 ms
90,168 KB
testcase_18 AC 341 ms
90,808 KB
testcase_19 AC 153 ms
89,016 KB
testcase_20 AC 328 ms
90,808 KB
testcase_21 AC 291 ms
90,936 KB
testcase_22 AC 248 ms
90,040 KB
testcase_23 AC 276 ms
90,552 KB
testcase_24 AC 129 ms
85,048 KB
testcase_25 AC 128 ms
85,048 KB
testcase_26 AC 142 ms
85,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
#n = int(input())
#alist = list(map(int,input().split()))
#alist = []
#s = input()
h,w,n = map(int,input().split())
v = 2*n+2
e = [[] for i in range(2*n+2)]
warp = []
warp.append((1,1))
for i in range(n):
    a,b,c,d = map(int,input().split())
    dist = abs(a-c) + abs(b-d)
    #e[2*i+2].append(2*i+1)
    e[2*i+1].append(2*i+2)
    warp.append((a,b))
    warp.append((c,d))
warp.append((h,w))

start = 0
d = []
dist = [10**18 for i in range(v)]
heapq.heappush(d,(0,start))
dist[start] = 0
while d:
    _,now = heapq.heappop(d)
    if _ > dist[now]:
        continue
    x,y = warp[now]
    for to in e[now]:
        if dist[to] > dist[now] + 1:
            dist[to] = dist[now] + 1
            heapq.heappush(d,(dist[to],to))
    for i in range(v):
        if i == now:
            continue
        tx,ty = warp[i]
        cost = abs(x-tx) + abs(y-ty)
        if dist[i] > dist[now] + cost:
            dist[i] = dist[now] + cost
            heapq.heappush(d,(dist[i],i))

print(dist[-1])
0