結果
問題 | No.2695 Warp Zone |
ユーザー | mkawa2 |
提出日時 | 2024-03-22 22:03:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 294 ms / 2,000 ms |
コード長 | 1,790 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 78,228 KB |
最終ジャッジ日時 | 2024-03-22 22:03:19 |
合計ジャッジ時間 | 5,458 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
55,600 KB |
testcase_01 | AC | 42 ms
55,600 KB |
testcase_02 | AC | 47 ms
55,600 KB |
testcase_03 | AC | 286 ms
78,204 KB |
testcase_04 | AC | 259 ms
77,948 KB |
testcase_05 | AC | 258 ms
77,940 KB |
testcase_06 | AC | 294 ms
78,068 KB |
testcase_07 | AC | 271 ms
78,068 KB |
testcase_08 | AC | 63 ms
67,952 KB |
testcase_09 | AC | 197 ms
77,852 KB |
testcase_10 | AC | 43 ms
55,600 KB |
testcase_11 | AC | 122 ms
76,948 KB |
testcase_12 | AC | 228 ms
78,228 KB |
testcase_13 | AC | 43 ms
55,600 KB |
testcase_14 | AC | 229 ms
77,964 KB |
testcase_15 | AC | 163 ms
77,964 KB |
testcase_16 | AC | 120 ms
76,844 KB |
testcase_17 | AC | 146 ms
77,848 KB |
testcase_18 | AC | 264 ms
77,960 KB |
testcase_19 | AC | 60 ms
65,868 KB |
testcase_20 | AC | 256 ms
78,220 KB |
testcase_21 | AC | 215 ms
77,964 KB |
testcase_22 | AC | 158 ms
77,848 KB |
testcase_23 | AC | 190 ms
77,972 KB |
testcase_24 | AC | 43 ms
55,600 KB |
testcase_25 | AC | 43 ms
55,600 KB |
testcase_26 | AC | 43 ms
55,600 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = -1-(-1 << 31) # inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 from collections import defaultdict from heapq import * def dijkstra(n, to, root=0): dist = [inf]*n dist[root] = 0 hp = [(0, root)] while hp: d, u = heappop(hp) x, y = ij[u] if d > dist[u]: continue for v in to[u]: nd = d+1 if dist[v] <= nd: continue dist[v] = nd heappush(hp, (nd, v)) for v in range(n): i, j = ij[v] c = abs(i-x)+abs(j-y) nd = d+c if dist[v] <= nd: continue dist[v] = nd heappush(hp, (nd, v)) return dist h, w, m = LI() ij2u = {(0, 0): 0, (h-1, w-1): 1} ij = [(0, 0), (h-1, w-1)] to = defaultdict(list) for _ in range(m): i, j, x, y = LI1() if (i, j) not in ij2u: ij2u[i, j] = len(ij) ij.append((i, j)) if (x, y) not in ij2u: ij2u[x, y] = len(ij) ij.append((x, y)) u = ij2u[i, j] v = ij2u[x, y] to[u].append(v) n = len(ij) dist = dijkstra(n, to, 0) print(dist[1])