結果
問題 | No.1283 Extra Fee |
ユーザー | tanon710 |
提出日時 | 2020-11-07 01:40:59 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,445 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 87,068 KB |
実行使用メモリ | 150,240 KB |
最終ジャッジ日時 | 2023-09-29 19:58:26 |
合計ジャッジ時間 | 27,118 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
71,140 KB |
testcase_01 | AC | 72 ms
71,096 KB |
testcase_02 | AC | 74 ms
71,476 KB |
testcase_03 | AC | 71 ms
71,248 KB |
testcase_04 | AC | 72 ms
71,520 KB |
testcase_05 | AC | 72 ms
71,436 KB |
testcase_06 | AC | 74 ms
71,344 KB |
testcase_07 | AC | 71 ms
71,480 KB |
testcase_08 | AC | 75 ms
71,468 KB |
testcase_09 | AC | 74 ms
71,152 KB |
testcase_10 | AC | 74 ms
71,520 KB |
testcase_11 | AC | 251 ms
81,032 KB |
testcase_12 | AC | 300 ms
83,144 KB |
testcase_13 | AC | 227 ms
81,308 KB |
testcase_14 | AC | 482 ms
89,136 KB |
testcase_15 | AC | 693 ms
93,668 KB |
testcase_16 | AC | 273 ms
82,652 KB |
testcase_17 | AC | 1,581 ms
124,412 KB |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 1,961 ms
135,676 KB |
testcase_23 | AC | 1,833 ms
136,936 KB |
testcase_24 | AC | 1,850 ms
141,156 KB |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | AC | 1,785 ms
127,160 KB |
ソースコード
import heapq n,m=map(int,input().split()) fees={} for _ in range(m): y,x,cost=map(int,input().split()) fees[(x-1,y-1)]=cost INF=10**18 costs=[[[INF,INF] for _ in range(n)] for _ in range(n)] costs[0][0]=[0,0] q=[] heapq.heappush(q,(0,0,0,0)) while len(q)!=0: curcost,x,y,skipped=heapq.heappop(q) if x==n-1 and y==n-1: print(curcost) exit() for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)]: if 0<=x+dx<=n-1 and 0<=y+dy<=n-1: if (x+dx,y+dy) in fees: if skipped==0: if costs[y+dy][x+dx][skipped+1]>curcost+1: heapq.heappush(q,(curcost+1,x+dx,y+dy,skipped+1)) costs[y+dy][x+dx][skipped+1]=curcost+1 if costs[y+dy][x+dx][skipped]>curcost+1+fees[(x+dx,y+dy)]: heapq.heappush(q,(curcost+1+fees[(x+dx,y+dy)],x+dx,y+dy,skipped)) costs[y+dy][x+dx][skipped]=curcost+1+fees[(x+dx,y+dy)] else: if costs[y+dy][x+dx][skipped]>curcost+1+fees[(x+dx,y+dy)]: heapq.heappush(q,(curcost+1+fees[(x+dx,y+dy)],x+dx,y+dy,skipped)) costs[y+dy][x+dx][skipped]=curcost+1+fees[(x+dx,y+dy)] else: if costs[y+dy][x+dx][skipped]>curcost+1: heapq.heappush(q,(curcost+1,x+dx,y+dy,skipped)) costs[y+dy][x+dx][skipped]=curcost+1