結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー mosmos_21mosmos_21
提出日時 2017-06-20 10:56:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 1,478 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 78,040 KB
実行使用メモリ 57,304 KB
最終ジャッジ日時 2024-04-10 02:12:55
合計ジャッジ時間 7,575 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
54,192 KB
testcase_01 AC 136 ms
54,036 KB
testcase_02 AC 143 ms
54,144 KB
testcase_03 AC 136 ms
54,108 KB
testcase_04 AC 136 ms
54,108 KB
testcase_05 AC 138 ms
54,160 KB
testcase_06 AC 134 ms
54,264 KB
testcase_07 AC 137 ms
54,368 KB
testcase_08 AC 207 ms
57,252 KB
testcase_09 AC 208 ms
57,304 KB
testcase_10 AC 150 ms
54,112 KB
testcase_11 AC 149 ms
54,656 KB
testcase_12 AC 153 ms
54,080 KB
testcase_13 AC 151 ms
54,360 KB
testcase_14 AC 165 ms
54,180 KB
testcase_15 AC 149 ms
54,356 KB
testcase_16 AC 151 ms
54,092 KB
testcase_17 AC 173 ms
54,676 KB
testcase_18 AC 157 ms
54,232 KB
testcase_19 AC 159 ms
53,964 KB
testcase_20 AC 149 ms
54,280 KB
testcase_21 AC 147 ms
54,104 KB
testcase_22 AC 184 ms
57,000 KB
testcase_23 AC 192 ms
56,888 KB
testcase_24 AC 177 ms
56,772 KB
testcase_25 AC 181 ms
56,884 KB
testcase_26 AC 185 ms
56,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[N + 1][Gx + 1][Gy + 1];
        for(int i = 0; i < Gx + 1; i++){
            for(int j = 0; j < Gy + 1; j++){
                dp[0][i][j] = (i + j) * F;
            }
        }
        for(int i = 1; i < N + 1; i++){
            for(int j = 0; j < Gx + 1; j++){
                for(int k = 0; k < Gy + 1; k++){
                    if(j == 0 && k == 0){
                        dp[i][j][k] = dp[i - 1][j][k];
                    }
                    if(j != 0){
                        dp[i][j][k] = Math.min(dp[i - 1][j][k], dp[i - 1][j - 1][k] + F);
                    }
                    if(k != 0){
                        dp[i][j][k] = Math.min(dp[i - 1][j][k], dp[i - 1][j][k - 1] + F);
                    }
                    if(j - x[i - 1] >= 0 && k - y[i - 1] >= 0){
                        dp[i][j][k] = Math.min(dp[i - 1][j][k], dp[i - 1][j - x[i - 1]][k - y[i - 1]] + c[i - 1]);
                    }
                }
            }
        }
        System.out.println(dp[N][Gx][Gy]);
    }
}
0