結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-11 03:17:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 82,192 KB
実行使用メモリ 76,348 KB
最終ジャッジ日時 2024-04-20 20:13:35
合計ジャッジ時間 2,643 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,220 KB
testcase_01 AC 35 ms
52,808 KB
testcase_02 AC 36 ms
53,132 KB
testcase_03 AC 36 ms
52,136 KB
testcase_04 AC 36 ms
53,428 KB
testcase_05 AC 35 ms
52,760 KB
testcase_06 AC 44 ms
61,136 KB
testcase_07 AC 35 ms
53,364 KB
testcase_08 AC 68 ms
75,688 KB
testcase_09 AC 60 ms
73,608 KB
testcase_10 AC 43 ms
61,280 KB
testcase_11 AC 46 ms
62,912 KB
testcase_12 AC 53 ms
65,848 KB
testcase_13 AC 53 ms
66,332 KB
testcase_14 AC 52 ms
66,784 KB
testcase_15 AC 52 ms
67,164 KB
testcase_16 AC 54 ms
67,560 KB
testcase_17 AC 56 ms
69,408 KB
testcase_18 AC 55 ms
67,900 KB
testcase_19 AC 55 ms
68,696 KB
testcase_20 AC 54 ms
67,632 KB
testcase_21 AC 53 ms
66,340 KB
testcase_22 AC 65 ms
75,852 KB
testcase_23 AC 70 ms
76,028 KB
testcase_24 AC 65 ms
75,996 KB
testcase_25 AC 71 ms
75,752 KB
testcase_26 AC 66 ms
76,348 KB
権限があれば一括ダウンロードができます

ソースコード

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