結果

問題 No.2317 Expression Menu
ユーザー InTheBloomInTheBloom
提出日時 2023-05-27 19:41:29
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,372 bytes
コンパイル時間 3,302 ms
コンパイル使用メモリ 160,092 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 20:27:33
合計ジャッジ時間 7,481 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 81 ms
4,376 KB
testcase_24 AC 77 ms
4,376 KB
testcase_25 AC 76 ms
4,376 KB
testcase_26 AC 74 ms
4,376 KB
testcase_27 AC 75 ms
4,380 KB
testcase_28 AC 77 ms
4,380 KB
testcase_29 AC 79 ms
4,376 KB
testcase_30 AC 82 ms
4,376 KB
testcase_31 AC 76 ms
4,376 KB
testcase_32 AC 75 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 WA -
testcase_39 AC 45 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    // input
    int N, X, Y;
    {
        auto buf = readln.split.to!(int[]);
        N = buf[0], X = buf[1], Y = buf[2];
    }

    int[] A, B, C;
    foreach (_; 0..N) {
        auto buf = readln.split.to!(int[]);
        A ~= buf[0], B ~= buf[1], C ~= buf[2];
    }

    solve(N, X, Y, A, B, C);
}

void solve (int N, int X, int Y, int[] A, int[] B, int[] C) {
    int[][] dp = new int[][](X+1, Y+1);
    // dp[i][j] := 「メニュー枠i, 容量jを消費して達成できる最大かわいさ」
    // dp[i+A_k][j+B_k] = max(dp[i][j] + C_k, dp[i+A_k][j+B_k]) if dp[i][j] != -1 && i+A_k <= X && j+B_k <= Y

    // initialize
    foreach (ref x; dp) {
        x[] = -1;
    }
    dp[0][0] = 0;

    // DP
    // 基本的なアイデアは一次元DPの「組み合わせ全列挙の圧縮」にほかならない
    foreach (k; 0..N) {
        foreach_reverse (i; 0..X+1) {
            foreach_reverse (j; 0..Y+1) {
                if (dp[i][j] != -1 && i + A[k] <= X && j + B[k] <= Y) {
                    dp[i+A[k]][j+B[k]] = max(dp[i][j] + C[k], dp[i+A[k]][j+B[k]]);
                }
            }
        }
    }

    // output
    int ans = 0;
    foreach (i; 0..X+1) {
        foreach (j; 0..Y+1) {
            if (dp[i][j] != -1) {
                ans = max(ans, dp[i][j]);
            }
        }
    }

    writeln(ans);
}
0