結果
問題 | No.1283 Extra Fee |
ユーザー | 👑 Kazun |
提出日時 | 2021-02-10 18:48:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,434 ms / 2,000 ms |
コード長 | 2,214 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 224,172 KB |
最終ジャッジ日時 | 2024-04-27 23:47:50 |
合計ジャッジ時間 | 20,060 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,324 KB |
testcase_01 | AC | 46 ms
54,256 KB |
testcase_02 | AC | 42 ms
53,776 KB |
testcase_03 | AC | 41 ms
54,824 KB |
testcase_04 | AC | 40 ms
53,984 KB |
testcase_05 | AC | 40 ms
54,320 KB |
testcase_06 | AC | 42 ms
54,036 KB |
testcase_07 | AC | 41 ms
55,300 KB |
testcase_08 | AC | 46 ms
59,648 KB |
testcase_09 | AC | 42 ms
55,068 KB |
testcase_10 | AC | 41 ms
53,840 KB |
testcase_11 | AC | 197 ms
83,832 KB |
testcase_12 | AC | 245 ms
84,760 KB |
testcase_13 | AC | 191 ms
80,848 KB |
testcase_14 | AC | 337 ms
97,296 KB |
testcase_15 | AC | 458 ms
110,960 KB |
testcase_16 | AC | 220 ms
83,216 KB |
testcase_17 | AC | 1,050 ms
208,832 KB |
testcase_18 | AC | 1,299 ms
210,800 KB |
testcase_19 | AC | 1,341 ms
221,616 KB |
testcase_20 | AC | 1,259 ms
209,492 KB |
testcase_21 | AC | 1,243 ms
209,836 KB |
testcase_22 | AC | 1,157 ms
196,344 KB |
testcase_23 | AC | 975 ms
210,372 KB |
testcase_24 | AC | 1,175 ms
217,188 KB |
testcase_25 | AC | 1,407 ms
223,008 KB |
testcase_26 | AC | 1,434 ms
224,172 KB |
testcase_27 | AC | 1,381 ms
223,504 KB |
testcase_28 | AC | 1,403 ms
223,636 KB |
testcase_29 | AC | 1,135 ms
222,184 KB |
ソースコード
from heapq import heappop,heappush class Heap_Point: def __init__(self,x,d): self.d=d self.x=x def __str__(self): return "(point:{}, dist:{})".format(self.x,self.d) def __repr__(self): return str(self) def __lt__(self,other): return self.d<other.d def __iter__(self): yield from (self.x,self.d) class Dijkstra_Heap: def __init__(self): self.heap=[] self.used=set() def __str__(self): return str(self.heap) def __repr__(self): return repr(self.heap) def __bool__(self): return bool(self.heap) def push(self,point,dist): heappush(self.heap,Heap_Point(point,dist)) def pop(self): assert self.heap while True: x,d=heappop(self.heap) if x not in self.used: self.used.add(x) return x,d return None def refresh(self): self.used=set() def main(): import sys from heapq import heappop,heappush input=sys.stdin.readline N,M=map(int,input().split()) inf=float("inf") F=[[1]*(N+1) for _ in range(N+1)] for _ in range(M): h,w,c=map(int,input().split()) F[h][w]+=c V=[(1,0),(-1,0),(0,1),(0,-1)] Dist0=[[inf]*(N+1) for __ in range(N+1)] Dist1=[[inf]*(N+1) for __ in range(N+1)] Dist0[1][1]=0 H=Dijkstra_Heap() H.push((1,1,0),0) while H: v,d=H.pop() i,j,m=v if (m==0 and d<Dist0[i][j]) or (m==1 and d<Dist1[i][j]): continue if i==j==N: break for (a,b) in V: if 1<=i+a<=N and 1<=j+b<=N: c=d+F[i+a][j+b] if m==0 and c<Dist0[i+a][j+b]: Dist0[i+a][j+b]=c H.push((i+a,j+b,0),c) if m==1 and c<Dist1[i+a][j+b]: Dist1[i+a][j+b]=c H.push((i+a,j+b,1),c) if m==0 and d+1<Dist1[i+a][j+b]: Dist1[i+a][j+b]=d+1 H.push((i+a,j+b,1),d+1) print(min(Dist0[N][N],Dist1[N][N])) if __name__=="__main__": main()