結果
問題 | No.1283 Extra Fee |
ユーザー | tanon710 |
提出日時 | 2020-11-07 02:47:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,288 ms / 2,000 ms |
コード長 | 1,497 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 81,924 KB |
実行使用メモリ | 121,172 KB |
最終ジャッジ日時 | 2024-04-27 23:32:28 |
合計ジャッジ時間 | 16,924 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,828 KB |
testcase_01 | AC | 32 ms
53,172 KB |
testcase_02 | AC | 33 ms
53,752 KB |
testcase_03 | AC | 38 ms
53,292 KB |
testcase_04 | AC | 35 ms
54,312 KB |
testcase_05 | AC | 34 ms
53,900 KB |
testcase_06 | AC | 36 ms
53,788 KB |
testcase_07 | AC | 35 ms
52,624 KB |
testcase_08 | AC | 38 ms
53,948 KB |
testcase_09 | AC | 36 ms
53,352 KB |
testcase_10 | AC | 35 ms
54,100 KB |
testcase_11 | AC | 170 ms
80,268 KB |
testcase_12 | AC | 199 ms
79,776 KB |
testcase_13 | AC | 140 ms
78,428 KB |
testcase_14 | AC | 256 ms
81,740 KB |
testcase_15 | AC | 347 ms
85,028 KB |
testcase_16 | AC | 152 ms
78,892 KB |
testcase_17 | AC | 1,146 ms
118,504 KB |
testcase_18 | AC | 1,093 ms
107,120 KB |
testcase_19 | AC | 1,104 ms
107,508 KB |
testcase_20 | AC | 977 ms
105,508 KB |
testcase_21 | AC | 1,059 ms
105,728 KB |
testcase_22 | AC | 917 ms
102,232 KB |
testcase_23 | AC | 889 ms
103,196 KB |
testcase_24 | AC | 888 ms
103,388 KB |
testcase_25 | AC | 1,114 ms
108,236 KB |
testcase_26 | AC | 1,120 ms
108,416 KB |
testcase_27 | AC | 1,128 ms
108,336 KB |
testcase_28 | AC | 1,131 ms
107,716 KB |
testcase_29 | AC | 1,288 ms
121,172 KB |
ソースコード
import heapq import sys input=sys.stdin.readline n,m=map(int,input().split()) fees=[[0]*n for _ in range(n)] for _ in range(m): y,x,cost=map(int,input().split()) fees[y-1][x-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 fees[y+dy][x+dx]!=0: 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[y+dy][x+dx]: heapq.heappush(q,(curcost+1+fees[y+dy][x+dx],x+dx,y+dy,skipped)) costs[y+dy][x+dx][skipped]=curcost+1+fees[y+dy][x+dx] else: if costs[y+dy][x+dx][skipped]>curcost+1+fees[y+dy][x+dx]: heapq.heappush(q,(curcost+1+fees[y+dy][x+dx],x+dx,y+dy,skipped)) costs[y+dy][x+dx][skipped]=curcost+1+fees[y+dy][x+dx] 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