結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-20 12:05:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 548 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-30 22:41:35
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 34 ms
10,752 KB
testcase_02 AC 33 ms
10,752 KB
testcase_03 AC 32 ms
10,624 KB
testcase_04 AC 31 ms
10,624 KB
testcase_05 AC 34 ms
10,752 KB
testcase_06 AC 38 ms
10,752 KB
testcase_07 AC 32 ms
10,624 KB
testcase_08 AC 548 ms
11,008 KB
testcase_09 AC 548 ms
10,880 KB
testcase_10 AC 36 ms
10,624 KB
testcase_11 AC 33 ms
10,624 KB
testcase_12 AC 42 ms
10,752 KB
testcase_13 AC 54 ms
10,752 KB
testcase_14 AC 76 ms
10,880 KB
testcase_15 AC 55 ms
10,752 KB
testcase_16 AC 52 ms
10,624 KB
testcase_17 AC 83 ms
10,624 KB
testcase_18 AC 78 ms
10,752 KB
testcase_19 AC 78 ms
10,624 KB
testcase_20 AC 62 ms
10,624 KB
testcase_21 AC 42 ms
10,624 KB
testcase_22 AC 272 ms
10,752 KB
testcase_23 AC 285 ms
10,752 KB
testcase_24 AC 274 ms
10,752 KB
testcase_25 AC 259 ms
10,880 KB
testcase_26 AC 271 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**9

gx, gy, n, f = map(int, input().split())
H = gx + 1
W = gy + 1

dp = [inf] * (H * W)
dp[0] = 0
for _ in range(n):
    x, y, c = map(int, input().split())
    for i in range(H)[::-1]:
        for j in range(W)[::-1]:
            nx = x + i
            ny = y + j
            if nx < H and ny < W:
                to = nx * W + ny
                dp[to] = min(dp[to], dp[i*W+j] + c)

ans = inf
for i in range(H):
    for j in range(W):
        cost = f * (gx+gy-i-j)
        ans = min(ans, dp[i*W+j]+cost)
print(ans)
0