結果

問題 No.2695 Warp Zone
ユーザー 👑 hitonanodehitonanode
提出日時 2024-04-05 00:36:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,228 KB
最終ジャッジ日時 2024-04-05 00:36:52
合計ジャッジ時間 5,199 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 264 ms
76,080 KB
testcase_04 AC 219 ms
76,160 KB
testcase_05 AC 219 ms
76,076 KB
testcase_06 AC 227 ms
76,076 KB
testcase_07 AC 228 ms
76,076 KB
testcase_08 AC 60 ms
68,128 KB
testcase_09 AC 141 ms
76,112 KB
testcase_10 AC 41 ms
53,460 KB
testcase_11 AC 96 ms
74,704 KB
testcase_12 AC 162 ms
76,112 KB
testcase_13 AC 38 ms
53,460 KB
testcase_14 AC 175 ms
76,224 KB
testcase_15 AC 138 ms
76,116 KB
testcase_16 AC 88 ms
73,292 KB
testcase_17 AC 106 ms
76,228 KB
testcase_18 AC 212 ms
76,084 KB
testcase_19 AC 63 ms
66,288 KB
testcase_20 AC 186 ms
76,088 KB
testcase_21 AC 182 ms
76,092 KB
testcase_22 AC 118 ms
76,096 KB
testcase_23 AC 154 ms
76,104 KB
testcase_24 AC 43 ms
53,460 KB
testcase_25 AC 44 ms
53,460 KB
testcase_26 AC 42 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W, N = map(int, input().split())

abcds = [tuple(map(int, input().split())) for _ in range(N)]

vs = [(1, 1)] + [(a, b) for a, b, c, d in abcds] + [(c, d) for a, b, c, d in abcds] + [(H, W)]

dist = [(1 << 60)] * len(vs)

dist[0] = 0
done = [False] * len(vs)

while True:
    # Dijkstra
    v = -1
    for i in range(len(vs)):
        if not done[i] and (v == -1 or dist[i] < dist[v]):
            v = i

    if v == -1:
        break

    done[v] = True

    x0, y0 = vs[v]
    d0 = dist[v]

    for i, (x1, y1) in enumerate(vs):
        if done[i]:
            continue

        d = abs(x1 - x0) + abs(y1 - y0)

        if d0 + d < dist[i]:
            dist[i] = d0 + d

    for i in range(N):
        dist[N + i + 1] = min(dist[N + i + 1], dist[i + 1] + 1)

print(dist[-1])
0