結果
問題 | No.1283 Extra Fee |
ユーザー | H3PO4 |
提出日時 | 2022-02-19 10:13:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,085 ms / 2,000 ms |
コード長 | 1,303 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 219,564 KB |
最終ジャッジ日時 | 2024-11-16 08:38:15 |
合計ジャッジ時間 | 16,317 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,480 KB |
testcase_01 | AC | 39 ms
52,480 KB |
testcase_02 | AC | 44 ms
52,992 KB |
testcase_03 | AC | 43 ms
52,608 KB |
testcase_04 | AC | 43 ms
52,608 KB |
testcase_05 | AC | 42 ms
52,608 KB |
testcase_06 | AC | 46 ms
58,624 KB |
testcase_07 | AC | 40 ms
52,864 KB |
testcase_08 | AC | 46 ms
59,776 KB |
testcase_09 | AC | 43 ms
53,376 KB |
testcase_10 | AC | 44 ms
53,632 KB |
testcase_11 | AC | 189 ms
83,416 KB |
testcase_12 | AC | 219 ms
85,248 KB |
testcase_13 | AC | 177 ms
82,432 KB |
testcase_14 | AC | 295 ms
102,144 KB |
testcase_15 | AC | 379 ms
116,736 KB |
testcase_16 | AC | 203 ms
85,376 KB |
testcase_17 | AC | 931 ms
191,144 KB |
testcase_18 | AC | 965 ms
207,268 KB |
testcase_19 | AC | 967 ms
214,484 KB |
testcase_20 | AC | 930 ms
205,952 KB |
testcase_21 | AC | 977 ms
208,508 KB |
testcase_22 | AC | 913 ms
194,496 KB |
testcase_23 | AC | 806 ms
217,088 KB |
testcase_24 | AC | 806 ms
217,128 KB |
testcase_25 | AC | 1,043 ms
219,196 KB |
testcase_26 | AC | 990 ms
219,392 KB |
testcase_27 | AC | 1,085 ms
219,564 KB |
testcase_28 | AC | 1,040 ms
219,448 KB |
testcase_29 | AC | 1,024 ms
201,296 KB |
ソースコード
import sys from heapq import heappush, heappop input = sys.stdin.buffer.readline INF = 10 ** 18 def dijkstra(N, G, s): dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappop(que) if dist[v] < c: continue for t, cost in G[v]: if dist[v] + cost < dist[t]: dist[t] = dist[v] + cost heappush(que, (dist[t], t)) return dist N, M = map(int, input().split()) grid2int = lambda h, w, i: h * N + w + i * N * N toll_table = [[1] * N for _ in range(N)] for _ in range(M): h, w, c = map(int, input().split()) h -= 1 w -= 1 toll_table[h][w] += c size = 2 * N * N G = [[] for _ in range(size)] for h in range(N): for w in range(N): toll = toll_table[h][w] for dh, dw in ((1, 0), (0, 1), (-1, 0), (0, -1)): hdh = h + dh wdw = w + dw if not (0 <= hdh < N and 0 <= wdw < N): continue G[grid2int(h, w, 0)].append((grid2int(hdh, wdw, 0), toll)) G[grid2int(h, w, 1)].append((grid2int(hdh, wdw, 1), toll)) if toll > 1: G[grid2int(h, w, 0)].append((grid2int(hdh, wdw, 1), 1)) dist = dijkstra(size, G, grid2int(0, 0, 0)) print(dist[grid2int(N - 1, N - 1, 1)])