結果
問題 | No.1283 Extra Fee |
ユーザー | neterukun |
提出日時 | 2020-11-06 22:05:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,678 ms / 2,000 ms |
コード長 | 1,501 bytes |
コンパイル時間 | 1,035 ms |
コンパイル使用メモリ | 82,056 KB |
実行使用メモリ | 116,152 KB |
最終ジャッジ日時 | 2024-11-16 06:41:17 |
合計ジャッジ時間 | 19,154 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,440 KB |
testcase_01 | AC | 38 ms
54,220 KB |
testcase_02 | AC | 39 ms
54,600 KB |
testcase_03 | AC | 38 ms
53,172 KB |
testcase_04 | AC | 38 ms
52,868 KB |
testcase_05 | AC | 39 ms
52,820 KB |
testcase_06 | AC | 42 ms
54,236 KB |
testcase_07 | AC | 39 ms
54,236 KB |
testcase_08 | AC | 42 ms
54,196 KB |
testcase_09 | AC | 40 ms
54,808 KB |
testcase_10 | AC | 39 ms
54,384 KB |
testcase_11 | AC | 207 ms
79,700 KB |
testcase_12 | AC | 203 ms
79,208 KB |
testcase_13 | AC | 161 ms
78,848 KB |
testcase_14 | AC | 289 ms
83,392 KB |
testcase_15 | AC | 401 ms
88,016 KB |
testcase_16 | AC | 184 ms
79,448 KB |
testcase_17 | AC | 1,566 ms
106,876 KB |
testcase_18 | AC | 1,173 ms
113,172 KB |
testcase_19 | AC | 1,135 ms
114,796 KB |
testcase_20 | AC | 1,110 ms
112,720 KB |
testcase_21 | AC | 1,131 ms
113,280 KB |
testcase_22 | AC | 1,063 ms
108,772 KB |
testcase_23 | AC | 989 ms
111,868 KB |
testcase_24 | AC | 983 ms
111,072 KB |
testcase_25 | AC | 1,232 ms
115,700 KB |
testcase_26 | AC | 1,213 ms
116,152 KB |
testcase_27 | AC | 1,173 ms
115,688 KB |
testcase_28 | AC | 1,175 ms
115,712 KB |
testcase_29 | AC | 1,678 ms
107,820 KB |
ソースコード
import heapq dd = ((1, 0), (-1, 0), (0, 1), (0, -1)) def dijkstra() -> list: INF = 10 ** 18 dist = [[[INF] * n for i in range(n)] for i in range(2)] dist[0][0][0] = 0 q = [(0, 0, 0, 0)] # q = [(startからの距離, i, j, cnt)] while q: d, i, j, cnt = heapq.heappop(q) if dist[cnt][i][j] < d: continue for di, dj in dd: nxt_i, nxt_j = i + di, j + dj if not(0 <= nxt_i < h and 0 <= nxt_j < w): continue if cnt == 1: if dist[1][i][j] + 1 + cost[nxt_i][nxt_j] < dist[1][nxt_i][nxt_j]: dist[1][nxt_i][nxt_j] = dist[1][i][j] + 1 + cost[nxt_i][nxt_j] heapq.heappush(q, (dist[1][nxt_i][nxt_j], nxt_i, nxt_j, 1)) else: if dist[0][i][j] + 1 + cost[nxt_i][nxt_j] < dist[0][nxt_i][nxt_j]: dist[0][nxt_i][nxt_j] = dist[0][i][j] + 1 + cost[nxt_i][nxt_j] heapq.heappush(q, (dist[0][nxt_i][nxt_j], nxt_i, nxt_j, 0)) if dist[0][i][j] + 1 < dist[1][nxt_i][nxt_j]: dist[1][nxt_i][nxt_j] = dist[0][i][j] + 1 heapq.heappush(q, (dist[1][nxt_i][nxt_j], nxt_i, nxt_j, 1)) return dist n, m = map(int, input().split()) h, w = n, n info = [list(map(int, input().split())) for i in range(m)] cost = [[0] * n for i in range(n)] for i, j, c in info: i -= 1 j -= 1 cost[i][j] = c dist = dijkstra() print(dist[1][-1][-1])