結果

問題 No.2695 Warp Zone
ユーザー navel_tosnavel_tos
提出日時 2024-03-23 15:42:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 108,632 KB
最終ジャッジ日時 2024-03-23 15:42:59
合計ジャッジ時間 5,237 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,460 KB
testcase_01 AC 33 ms
53,460 KB
testcase_02 AC 33 ms
53,460 KB
testcase_03 AC 292 ms
108,632 KB
testcase_04 AC 289 ms
107,352 KB
testcase_05 AC 300 ms
107,352 KB
testcase_06 AC 288 ms
108,376 KB
testcase_07 AC 288 ms
108,628 KB
testcase_08 AC 56 ms
70,696 KB
testcase_09 AC 153 ms
86,660 KB
testcase_10 AC 33 ms
53,460 KB
testcase_11 AC 89 ms
78,972 KB
testcase_12 AC 181 ms
91,516 KB
testcase_13 AC 32 ms
53,460 KB
testcase_14 AC 231 ms
96,116 KB
testcase_15 AC 149 ms
85,500 KB
testcase_16 AC 85 ms
78,360 KB
testcase_17 AC 111 ms
81,640 KB
testcase_18 AC 243 ms
100,712 KB
testcase_19 AC 55 ms
70,700 KB
testcase_20 AC 224 ms
98,032 KB
testcase_21 AC 234 ms
95,472 KB
testcase_22 AC 128 ms
84,200 KB
testcase_23 AC 187 ms
91,260 KB
testcase_24 AC 34 ms
53,460 KB
testcase_25 AC 33 ms
53,460 KB
testcase_26 AC 34 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yukicoder423E Warp Zone

#入力受取  点は座標圧縮する
H, W, N = map(int, input().split())
P = set([(1, 1), (H, W)])
X = [tuple(map(int, input().split())) for _ in range(N)]
for a, b, c, d in X:
    P.add((a, b))
    P.add((c, d))
P = sorted(P)
R = {(x, y): i for i, (x, y) in enumerate(P)}
M = len(P)

#二点間距離をdistに格納  これ以降、座標を陽に持つ必要がなくなる
dist = lambda P1, P2: abs(P1[0] - P2[0]) + abs(P1[1] - P2[1])
D = [[dist(P1, P2) for P2 in P] for P1 in P]
del P

#ワープを反映
G = [[] for _ in range(M)]
for a, b, c, d in X:
    G[ R[(a, b)] ].append( R[(c, d)] )
S, E = R[(1, 1)], R[(H, W)]
del R

#オリジナルダイクストラ法
DP = [10 ** 18] * M
checked = [False] * M
DP[S] = 0

for _ in range(M):
    d, i = min([(DP[i], i) for i in range(M) if checked[i] == False])
    checked[i] = True
    for j in range(M):
        if checked[j]:
            assert DP[j] <= DP[i] + D[i][j]
        DP[j] = min(DP[j], DP[i] + D[i][j])
    for j in G[i]:
        if checked[j]:
            assert DP[j] <= DP[i] + 1
        DP[j] = min(DP[j], DP[i] + 1)

#答えを出力
print(DP[E])
0