結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー htkb
提出日時 2019-03-26 23:20:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 387 ms / 2,000 ms
コード長 588 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-10-11 01:37:02
合計ジャッジ時間 3,045 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import product
Gx, Gy, N, F = map(int, input().split())
crystal = [(x, y, c) for l in sys.stdin for x, y, c in (map(int, l.split()),) if (x+y)*F > c]
crystal_count = len(crystal)
inf = 10**9

dp = [[inf]*(Gx+2) for _ in [0]*(Gy+2)]
dp[0][0] = 0

for cx, cy, ccost in crystal:
    for x, y in product(range(Gx-cx, -1, -1), range(Gy-cy, -1, -1)):
        dp[y+cy][x+cx] = min(dp[y+cy][x+cx], dp[y][x]+ccost)

for x, y in product(range(Gx+1), range(Gy+1)):
    dp[y+1][x] = min(dp[y+1][x], dp[y][x]+F)
    dp[y][x+1] = min(dp[y][x+1], dp[y][x]+F)

print(dp[Gy][Gx])
0