結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー brthyyjp
提出日時 2021-03-11 03:17:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2024-10-12 18:15:22
合計ジャッジ時間 2,734 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

gx, gy, n, f = map(int, input().split())
XYC = []
for i in range(n):
    x, y, c = map(int, input().split())
    XYC.append((x, y, c))

INF = 10**18
dp = [[INF]*(gx+1) for i in range(gy+1)]
dp[0][0] = 0
for i in range(gy+1):
    for j in range(gx+1):
        for di, dj in (1, 0), (0, 1):
            ni, nj = i+di, j+dj
            if 0 <= ni <= gy and 0 <= nj <= gx:
                dp[ni][nj] = min(dp[ni][nj], dp[i][j]+f)
for x, y, c in XYC:
    for i in reversed(range(gy+1)):
        for j in reversed(range(gx+1)):
                if 0 <= i+y <= gy and 0 <= j+x <= gx:
                    dp[i+y][j+x] = min(dp[i+y][j+x], dp[i][j]+c)
print(dp[gy][gx])
0