結果
問題 | No.1283 Extra Fee |
ユーザー | tanon710 |
提出日時 | 2020-11-07 01:38:59 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,583 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 87,024 KB |
実行使用メモリ | 151,168 KB |
最終ジャッジ日時 | 2023-09-29 19:57:29 |
合計ジャッジ時間 | 13,815 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
71,392 KB |
testcase_01 | AC | 77 ms
71,344 KB |
testcase_02 | AC | 79 ms
71,000 KB |
testcase_03 | AC | 79 ms
71,324 KB |
testcase_04 | AC | 78 ms
71,316 KB |
testcase_05 | AC | 79 ms
71,224 KB |
testcase_06 | AC | 80 ms
71,212 KB |
testcase_07 | AC | 79 ms
71,300 KB |
testcase_08 | AC | 84 ms
71,500 KB |
testcase_09 | AC | 81 ms
71,512 KB |
testcase_10 | AC | 82 ms
71,208 KB |
testcase_11 | AC | 289 ms
82,288 KB |
testcase_12 | AC | 337 ms
82,276 KB |
testcase_13 | AC | 263 ms
81,480 KB |
testcase_14 | AC | 548 ms
89,448 KB |
testcase_15 | AC | 785 ms
94,396 KB |
testcase_16 | AC | 297 ms
82,168 KB |
testcase_17 | AC | 1,772 ms
125,432 KB |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | AC | 1,903 ms
128,776 KB |
ソースコード
import heapq debug=False def pprint(*s): if debug==True: print(*s) 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) pprint('x:{},y:{},cost:{},skipped:{}'.format(x,y,curcost,skipped)) 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