結果
問題 | No.1283 Extra Fee |
ユーザー | tanon710 |
提出日時 | 2020-11-07 02:17:38 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,151 bytes |
コンパイル時間 | 173 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 400,316 KB |
最終ジャッジ日時 | 2024-04-27 23:30:27 |
合計ジャッジ時間 | 27,142 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
53,076 KB |
testcase_01 | AC | 45 ms
54,524 KB |
testcase_02 | AC | 42 ms
54,732 KB |
testcase_03 | AC | 40 ms
52,884 KB |
testcase_04 | AC | 40 ms
53,072 KB |
testcase_05 | AC | 40 ms
53,040 KB |
testcase_06 | AC | 44 ms
53,996 KB |
testcase_07 | AC | 42 ms
54,512 KB |
testcase_08 | AC | 47 ms
60,728 KB |
testcase_09 | AC | 43 ms
54,256 KB |
testcase_10 | AC | 42 ms
54,520 KB |
testcase_11 | AC | 223 ms
90,368 KB |
testcase_12 | AC | 204 ms
94,148 KB |
testcase_13 | AC | 160 ms
88,800 KB |
testcase_14 | AC | 343 ms
131,620 KB |
testcase_15 | AC | 465 ms
163,720 KB |
testcase_16 | AC | 182 ms
94,956 KB |
testcase_17 | AC | 1,486 ms
308,012 KB |
testcase_18 | AC | 1,790 ms
363,216 KB |
testcase_19 | AC | 1,884 ms
390,024 KB |
testcase_20 | AC | 1,788 ms
361,784 KB |
testcase_21 | AC | 1,894 ms
367,616 KB |
testcase_22 | AC | 1,484 ms
336,236 KB |
testcase_23 | AC | 1,755 ms
387,032 KB |
testcase_24 | AC | 1,841 ms
398,620 KB |
testcase_25 | AC | 1,931 ms
400,316 KB |
testcase_26 | AC | 1,940 ms
399,800 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 1,952 ms
400,272 KB |
testcase_29 | AC | 1,615 ms
324,700 KB |
ソースコード
import heapq import sys input=sys.stdin.readline def dijkstra(s,e): hq = [(0, s)] heapq.heapify(hq) cost = [float('inf')] * len(e) cost[s] = 0 while hq: c, v = heapq.heappop(hq) if c > cost[v]: continue for u, d in e[v]: tmp = d + cost[v] if tmp < cost[u]: cost[u] = tmp heapq.heappush(hq, (tmp, u)) return cost n,m=map(int,input().split()) fees=[1]*(n*n) for _ in range(m): y,x,cost=map(int,input().split()) fees[n*(y-1)+x-1]+=cost g=[[] for _ in range(2*n**2)] for y in range(n): for x in range(n): for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]: if 0<=x+dx<=n-1 and 0<=y+dy<=n-1: u=n*y+x v=n*(y+dy)+x+dx fee=fees[n*(y+dy)+x+dx] if fee!=1: g[u].append([v,fee]) g[u].append([v+n**2,1]) g[u+n**2].append([v+n**2,fee]) else: g[u].append([v,1]) g[u+n**2].append([v+n**2,1]) ans=dijkstra(0,g) print(min(ans[n**2-1],ans[2*n**2-1]))