結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー 👑 KazunKazun
提出日時 2021-02-26 18:49:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 965 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 174,816 KB
最終ジャッジ日時 2024-04-10 08:56:16
合計ジャッジ時間 5,357 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,784 KB
testcase_01 AC 38 ms
54,464 KB
testcase_02 AC 37 ms
54,828 KB
testcase_03 AC 36 ms
53,580 KB
testcase_04 AC 38 ms
54,360 KB
testcase_05 AC 39 ms
54,072 KB
testcase_06 AC 130 ms
78,112 KB
testcase_07 AC 36 ms
53,272 KB
testcase_08 AC 965 ms
171,204 KB
testcase_09 AC 843 ms
174,816 KB
testcase_10 AC 86 ms
76,636 KB
testcase_11 AC 94 ms
76,856 KB
testcase_12 AC 68 ms
72,900 KB
testcase_13 AC 72 ms
75,004 KB
testcase_14 AC 162 ms
82,344 KB
testcase_15 AC 103 ms
77,524 KB
testcase_16 AC 51 ms
64,920 KB
testcase_17 AC 104 ms
78,796 KB
testcase_18 AC 122 ms
80,336 KB
testcase_19 AC 89 ms
77,660 KB
testcase_20 AC 83 ms
77,880 KB
testcase_21 AC 57 ms
68,868 KB
testcase_22 AC 160 ms
85,628 KB
testcase_23 AC 148 ms
83,876 KB
testcase_24 AC 107 ms
82,328 KB
testcase_25 AC 72 ms
81,260 KB
testcase_26 AC 127 ms
83,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
#================================================
from heapq import heappop,heappush

Gx,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]=0
Q=[Heap_Point((0,0,0),0)]

while Q:
    p,d=heappop(Q)
    x,y,k=p

    if x==Gx and y==Gy:
        break

    if T[x][y][k]<d:
        continue

    if x<Gx and T[x+1][y][k]>d+F:
        T[x+1][y][k]=d+F
        heappush(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+F
        heappush(Q,Heap_Point((x,y+1,k),d+F))

    for i,q in enumerate(P[k+1:],k+1):
        a,b,c=q
        if 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+c
            heappush(Q,Heap_Point((x+a,y+b,i),d+c))

print(min(T[Gx][Gy]))
0