結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー mosmos_21mosmos_21
提出日時 2017-06-20 10:25:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,283 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 77,644 KB
実行使用メモリ 54,644 KB
最終ジャッジ日時 2024-04-10 02:10:20
合計ジャッジ時間 6,640 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,064 KB
testcase_01 AC 116 ms
52,932 KB
testcase_02 AC 123 ms
54,092 KB
testcase_03 AC 102 ms
52,772 KB
testcase_04 WA -
testcase_05 AC 127 ms
54,076 KB
testcase_06 WA -
testcase_07 AC 120 ms
54,092 KB
testcase_08 AC 163 ms
54,280 KB
testcase_09 AC 163 ms
54,124 KB
testcase_10 AC 131 ms
54,344 KB
testcase_11 AC 135 ms
54,040 KB
testcase_12 AC 132 ms
54,312 KB
testcase_13 AC 133 ms
54,208 KB
testcase_14 AC 138 ms
54,192 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 121 ms
53,080 KB
testcase_19 WA -
testcase_20 AC 127 ms
54,120 KB
testcase_21 AC 121 ms
53,116 KB
testcase_22 WA -
testcase_23 AC 160 ms
54,276 KB
testcase_24 AC 157 ms
54,136 KB
testcase_25 AC 158 ms
54,244 KB
testcase_26 AC 155 ms
54,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int Gx = in.nextInt(), Gy = in.nextInt(), N = in.nextInt(), F = in.nextInt();
        int[] x = new int[N], y = new int[N], c = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = in.nextInt();
            y[i] = in.nextInt();
            c[i] = in.nextInt();
        }
        int[][] dp = new int[Gx + 1][Gy + 1];
        for (int i = 0; i < Gx + 1; i++) {
            Arrays.fill(dp[i], Integer.MAX_VALUE);
        }
        dp[0][0] = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < Gx + 1; j++) {
                for (int k = 0; k < Gy + 1; k++) {
                    if (j != 0) {
                        dp[j][k] = Math.min(dp[j][k], dp[j - 1][k] + F);
                    }
                    if (k != 0) {
                        dp[j][k] = Math.min(dp[j][k], dp[j][k - 1] + F);
                    }
                    if (j - x[i] >= 0 && k - y[i] >= 0) {
                        dp[j][k] = Math.min(dp[j][k], dp[j - x[i]][k - y[i]] + c[i]);
                    }
                }
            }
        }
        System.out.println(dp[Gx][Gy]);
    }
}
0