結果
問題 | No.1283 Extra Fee |
ユーザー | Coki628 |
提出日時 | 2020-12-08 18:33:58 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,972 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 82,960 KB |
実行使用メモリ | 110,532 KB |
最終ジャッジ日時 | 2024-11-16 07:15:58 |
合計ジャッジ時間 | 21,014 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,076 KB |
testcase_01 | AC | 41 ms
54,000 KB |
testcase_02 | AC | 41 ms
53,724 KB |
testcase_03 | AC | 41 ms
54,188 KB |
testcase_04 | AC | 42 ms
54,636 KB |
testcase_05 | AC | 40 ms
53,640 KB |
testcase_06 | AC | 43 ms
54,204 KB |
testcase_07 | AC | 41 ms
53,676 KB |
testcase_08 | AC | 43 ms
54,876 KB |
testcase_09 | AC | 42 ms
54,444 KB |
testcase_10 | AC | 42 ms
54,784 KB |
testcase_11 | AC | 211 ms
79,208 KB |
testcase_12 | AC | 227 ms
79,308 KB |
testcase_13 | AC | 158 ms
78,264 KB |
testcase_14 | AC | 316 ms
80,520 KB |
testcase_15 | AC | 407 ms
82,816 KB |
testcase_16 | AC | 176 ms
78,148 KB |
testcase_17 | AC | 1,870 ms
108,404 KB |
testcase_18 | AC | 1,296 ms
98,072 KB |
testcase_19 | AC | 1,261 ms
97,668 KB |
testcase_20 | AC | 1,211 ms
96,124 KB |
testcase_21 | AC | 1,197 ms
96,800 KB |
testcase_22 | AC | 1,095 ms
93,944 KB |
testcase_23 | AC | 1,074 ms
93,532 KB |
testcase_24 | AC | 1,085 ms
93,684 KB |
testcase_25 | AC | 1,334 ms
97,900 KB |
testcase_26 | AC | 1,320 ms
98,528 KB |
testcase_27 | AC | 1,292 ms
98,500 KB |
testcase_28 | AC | 1,327 ms
98,644 KB |
testcase_29 | TLE | - |
ソースコード
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF = 10**19 MOD = 10**9 + 7 EPS = 10**-10 def dijkstra(grid: list, src: tuple) -> list: """ グリッドダイクストラ(縦, 横, H*Wグリッド, 始点(h, w)) """ from heapq import heappush, heappop H, W = len(grid), len(grid[0]) res = list3d(2, H, W, INF) srch, srcw = src que = [(0, 0, srch, srcw)] res[0][srch][srcw] = 0 directions = ((1, 0), (-1, 0), (0, 1), (0, -1)) while que: dist, used, h, w = heappop(que) if res[used][h][w] < dist: continue for dh, dw in directions: nh, nw = h + dh, w + dw if grid[nh][nw] == -1: continue cost = grid[nh][nw] if dist + cost < res[used][nh][nw]: res[used][nh][nw] = dist + cost heappush(que, (dist+cost, used, nh, nw)) if cost > 1 and not used: cost = 1 if dist + cost < res[1][nh][nw]: res[1][nh][nw] = dist + cost heappush(que, (dist+cost, 1, nh, nw)) return res N, M = MAP() grid = list2d(N+2, N+2, 1) for i in range(N+2): grid[i][0] = -1 grid[i][N+1] = -1 grid[0][i] = -1 grid[N+1][i] = -1 for i in range(M): h, w, c = MAP() grid[h][w] += c res = dijkstra(grid, (1, 1)) ans = min(res[0][N][N], res[1][N][N]) print(ans)