結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー maesoramaesora
提出日時 2017-04-02 18:58:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 435 ms / 2,000 ms
コード長 1,653 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 9,140 KB
最終ジャッジ日時 2023-09-22 07:42:23
合計ジャッジ時間 5,001 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,396 KB
testcase_01 AC 16 ms
8,312 KB
testcase_02 AC 16 ms
8,284 KB
testcase_03 AC 16 ms
8,248 KB
testcase_04 AC 16 ms
8,368 KB
testcase_05 AC 16 ms
8,308 KB
testcase_06 AC 20 ms
8,556 KB
testcase_07 AC 16 ms
8,148 KB
testcase_08 AC 435 ms
9,112 KB
testcase_09 AC 396 ms
8,048 KB
testcase_10 AC 22 ms
8,388 KB
testcase_11 AC 19 ms
8,292 KB
testcase_12 AC 37 ms
8,376 KB
testcase_13 AC 51 ms
8,504 KB
testcase_14 AC 72 ms
8,128 KB
testcase_15 AC 53 ms
8,448 KB
testcase_16 AC 53 ms
8,416 KB
testcase_17 AC 99 ms
8,500 KB
testcase_18 AC 79 ms
8,132 KB
testcase_19 AC 82 ms
8,648 KB
testcase_20 AC 63 ms
8,660 KB
testcase_21 AC 34 ms
8,372 KB
testcase_22 AC 391 ms
9,132 KB
testcase_23 AC 392 ms
9,140 KB
testcase_24 AC 388 ms
9,016 KB
testcase_25 AC 386 ms
9,020 KB
testcase_26 AC 396 ms
9,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import sys

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

def solve(Gx, Gy, N, F, X, Y, C):
    dp_layer = array2d(Gx + 1, Gy + 1)
    dp_prev_layer = None

    for i in range(-1, N):
        for x in range(Gx + 1):
            for y in range(Gy + 1):
                if x == 0 and y == 0:
                    dp_layer[0][0] = 0
                else:
                    cand = []
                    if x > 0:
                        cand.append(dp_layer[x-1][y] + F)
                    if y > 0:
                        cand.append(dp_layer[x][y-1] + F)
                    if i >= 0:
                        cand.append(dp_prev_layer[x][y])
                        if x > 0:
                            cand.append(dp_prev_layer[x-1][y] + F)
                        if y > 0:
                            cand.append(dp_prev_layer[x][y-1] + F)
                        if x >= X[i] and y >= Y[i]:
                            cand.append(dp_prev_layer[x - X[i]][y - Y[i]] + C[i])
                    dp_layer[x][y] = min(cand)
        dp_prev_layer = dp_layer
        dp_layer = array2d(Gx + 1, Gy + 1)

        # # dbg
        # sys.stderr.write("------\n{} ------\n".format(i))
        # for x in range(Gx + 1):
        #     sys.stderr.write(" ".join(["{:2d}".format(cost) for cost in dp_prev_layer[x]]) + "\n")
    return dp_prev_layer[-1][-1]



def main():
    Gx, Gy, N, F = map(int, input().split())
    x = [None] * N
    y = [None] * N
    c = [None] * N
    for i in range(N):
        x[i], y[i], c[i] = map(int, input().split())
    print(solve(Gx, Gy, N, F, x, y, c))

main()
0