結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-26 18:49:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,078 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 82,504 KB |
実行使用メモリ | 174,848 KB |
最終ジャッジ日時 | 2024-10-02 10:40:36 |
合計ジャッジ時間 | 5,645 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
class Heap_Point:def __init__(self,x,d):self.d=dself.x=xdef __str__(self):return "(point:{}, dist:{})".format(self.x,self.d)def __repr__(self):return str(self)def __lt__(self,other):return self.d<other.ddef __iter__(self):yield from (self.x,self.d)#================================================from heapq import heappop,heappushGx,Gy,N,F=map(int,input().split())P=["*"]for _ in range(N):x,y,c=map(int,input().split())P.append((x,y,c))inf=float("inf")T=[[[inf]*(N+1) for _ in range(Gy+1)] for __ in range(Gx+1)]T[0][0][0]=0Q=[Heap_Point((0,0,0),0)]while Q:p,d=heappop(Q)x,y,k=pif x==Gx and y==Gy:breakif T[x][y][k]<d:continueif x<Gx and T[x+1][y][k]>d+F:T[x+1][y][k]=d+Fheappush(Q,Heap_Point((x+1,y,k),d+F))if y<Gy and T[x][y+1][k]>d+F:T[x][y+1][k]=d+Fheappush(Q,Heap_Point((x,y+1,k),d+F))for i,q in enumerate(P[k+1:],k+1):a,b,c=qif 0<=x+a<=Gx and 0<=y+b<=Gy and T[x+a][y+b][i]>d+c:T[x+a][y+b][i]=d+cheappush(Q,Heap_Point((x+a,y+b,i),d+c))print(min(T[Gx][Gy]))