結果

問題 No.2695 Warp Zone
ユーザー 👑 rin204rin204
提出日時 2024-03-22 21:42:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,208 KB
最終ジャッジ日時 2024-03-22 21:42:34
合計ジャッジ時間 4,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 206 ms
76,164 KB
testcase_04 AC 197 ms
76,172 KB
testcase_05 AC 197 ms
76,168 KB
testcase_06 AC 204 ms
76,168 KB
testcase_07 AC 205 ms
76,164 KB
testcase_08 AC 54 ms
66,020 KB
testcase_09 AC 117 ms
76,208 KB
testcase_10 AC 38 ms
53,460 KB
testcase_11 AC 82 ms
73,276 KB
testcase_12 AC 138 ms
76,068 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 153 ms
76,184 KB
testcase_15 AC 114 ms
76,208 KB
testcase_16 AC 79 ms
72,620 KB
testcase_17 AC 91 ms
72,736 KB
testcase_18 AC 183 ms
76,180 KB
testcase_19 AC 55 ms
66,020 KB
testcase_20 AC 163 ms
76,056 KB
testcase_21 AC 158 ms
76,060 KB
testcase_22 AC 103 ms
74,264 KB
testcase_23 AC 135 ms
76,068 KB
testcase_24 AC 36 ms
53,460 KB
testcase_25 AC 36 ms
53,460 KB
testcase_26 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w, n = map(int, input().split())
V = [0, h * w - 1]
edges = {}
for _ in range(n):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    x = a * w + b
    y = c * w + d
    V.append(x)
    V.append(y)
    edges.setdefault(x, []).append(y)

V = sorted(set(V))
idx = {v: i for i, v in enumerate(V)}
n = len(V)
dist = [1 << 60] * n
dist[0] = 0
used = [False] * n
for _ in range(n):
    pos = -1
    mi = 1 << 60
    for i in range(n):
        if not used[i] and dist[i] < mi:
            mi = dist[i]
            pos = i
    used[pos] = True

    i1 = V[pos] // w
    j1 = V[pos] - w * i1
    for npos in range(n):
        i2 = V[npos] // w
        j2 = V[npos] - w * i2
        nd = dist[pos] + abs(i1 - i2) + abs(j1 - j2)
        dist[npos] = min(dist[npos], nd)
    for npos in edges.get(V[pos], []):
        nd = dist[pos] + 1
        dist[idx[npos]] = min(dist[idx[npos]], nd)

print(dist[-1])
0