結果
| 問題 | No.2695 Warp Zone | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-03-22 21:42:28 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 200 ms / 2,000 ms | 
| コード長 | 935 bytes | 
| コンパイル時間 | 215 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 76,672 KB | 
| 最終ジャッジ日時 | 2024-09-30 11:10:51 | 
| 合計ジャッジ時間 | 3,997 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
ソースコード
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])
            
            
            
        