結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー nebukuro09nebukuro09
提出日時 2017-03-24 22:48:26
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 107,048 KB
実行使用メモリ 6,744 KB
最終ジャッジ日時 2023-09-03 12:37:38
合計ジャッジ時間 2,489 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 6 ms
6,744 KB
testcase_09 AC 6 ms
5,944 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 6 ms
5,496 KB
testcase_23 AC 6 ms
5,416 KB
testcase_24 AC 6 ms
5,484 KB
testcase_25 AC 5 ms
5,888 KB
testcase_26 AC 6 ms
6,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

alias Tuple!(int, "x", int, "y", int, "c") Crystal;

void main() {
    auto s = readln.split.map!(to!int);
    auto Gx = s[0];
    auto Gy = s[1];
    auto N = s[2];
    auto F = s[3];
    auto C = new Crystal[](N);
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        C[i] = Crystal(s[0], s[1], s[2]);
    }

    auto dp = new int[][][](N+1, Gx+1, Gy+1);

    foreach (x; 0..Gx+1) {
        foreach (y; 0..Gy+1) {
            dp[0][x][y] = (x + y) * F;
        }
    }

    foreach (i; 0..N) {
        foreach (x; 0..Gx+1) {
            foreach (y; 0..Gy+1) {
                dp[i+1][x][y] = dp[i][x][y];
                if (x - C[i].x < 0 || y - C[i].y < 0) continue;
                dp[i+1][x][y] = min(dp[i][x][y],
                                    dp[i][x-C[i].x][y-C[i].y] + C[i].c);
            }
        }
    }

    dp[N][Gx][Gy].writeln;
}
0