結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
54,152 KB
testcase_01 AC 126 ms
54,120 KB
testcase_02 AC 128 ms
54,340 KB
testcase_03 AC 127 ms
54,124 KB
testcase_04 WA -
testcase_05 AC 123 ms
54,028 KB
testcase_06 AC 124 ms
54,280 KB
testcase_07 AC 123 ms
54,044 KB
testcase_08 AC 168 ms
54,244 KB
testcase_09 AC 168 ms
54,548 KB
testcase_10 AC 132 ms
54,392 KB
testcase_11 AC 130 ms
54,096 KB
testcase_12 AC 136 ms
54,360 KB
testcase_13 AC 133 ms
54,144 KB
testcase_14 AC 134 ms
54,232 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 121 ms
52,884 KB
testcase_19 WA -
testcase_20 AC 129 ms
54,296 KB
testcase_21 AC 124 ms
54,180 KB
testcase_22 WA -
testcase_23 AC 159 ms
54,216 KB
testcase_24 AC 156 ms
54,248 KB
testcase_25 AC 156 ms
54,336 KB
testcase_26 AC 151 ms
54,300 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();
        
        if(N== 0){
            System.out.println((Gx + Gy) * F);
            return;
        }
        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