結果
問題 | No.1283 Extra Fee |
ユーザー | brthyyjp |
提出日時 | 2020-11-06 22:33:07 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,441 bytes |
コンパイル時間 | 219 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 221,396 KB |
最終ジャッジ日時 | 2024-07-22 13:18:09 |
合計ジャッジ時間 | 14,631 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,608 KB |
testcase_01 | AC | 43 ms
52,608 KB |
testcase_02 | AC | 43 ms
52,736 KB |
testcase_03 | AC | 43 ms
52,736 KB |
testcase_04 | AC | 43 ms
52,608 KB |
testcase_05 | AC | 43 ms
52,608 KB |
testcase_06 | WA | - |
testcase_07 | AC | 43 ms
53,120 KB |
testcase_08 | AC | 45 ms
53,888 KB |
testcase_09 | WA | - |
testcase_10 | AC | 44 ms
53,500 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 308 ms
117,032 KB |
testcase_16 | AC | 146 ms
85,248 KB |
testcase_17 | AC | 975 ms
196,316 KB |
testcase_18 | AC | 777 ms
207,060 KB |
testcase_19 | AC | 817 ms
216,736 KB |
testcase_20 | AC | 785 ms
206,012 KB |
testcase_21 | AC | 764 ms
208,092 KB |
testcase_22 | AC | 763 ms
195,056 KB |
testcase_23 | AC | 800 ms
213,080 KB |
testcase_24 | AC | 814 ms
216,712 KB |
testcase_25 | AC | 832 ms
221,268 KB |
testcase_26 | AC | 845 ms
221,268 KB |
testcase_27 | AC | 846 ms
221,008 KB |
testcase_28 | AC | 858 ms
221,396 KB |
testcase_29 | AC | 1,060 ms
206,312 KB |
ソースコード
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m = map(int, input().split()) HWC = [] A = [[0]*n for _ in range(n)] for i in range(m): h, w, c = map(int, input().split()) h, w =h-1, w-1 HWC.append((h, w, c)) A[h][w] = c import heapq INF = 10**18 def dijkstra_heap(s, edge): n = len(edge) d = [INF] * n used = [True] * n #True: not used d[s] = 0 used[s] = False edgelist = [] for e in edge[s]: heapq.heappush(edgelist,e) while len(edgelist): minedge = heapq.heappop(edgelist) if not used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist,(e[0]+d[v],e[1])) return d ans = INF g = [[] for _ in range(n**2)] rg = [[] for _ in range(n**2)] for i in range(n): for j in range(n): v = i*n+j for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1): ni, nj = i+di, j+dj if 0 <= ni < n and 0 <= nj < n: c = A[ni][nj]+1 u = ni*n+nj g[v].append((c, u)) rg[u].append((c, v)) d = dijkstra_heap(0, g) #print(d) cur = n**2-1 X = [] while cur != 0: for c, u in rg[cur]: if d[u]+c == d[cur]: cur = u X.append(c-1) #print(X) ans = d[-1]-max(X) print(ans)