結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー htensaihtensai
提出日時 2020-05-08 16:28:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 74,032 KB
実行使用メモリ 60,512 KB
最終ジャッジ日時 2023-09-16 08:29:51
合計ジャッジ時間 7,254 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,336 KB
testcase_01 AC 122 ms
55,700 KB
testcase_02 AC 124 ms
55,440 KB
testcase_03 AC 124 ms
55,596 KB
testcase_04 AC 125 ms
55,616 KB
testcase_05 AC 127 ms
55,336 KB
testcase_06 AC 123 ms
55,840 KB
testcase_07 AC 123 ms
55,396 KB
testcase_08 AC 156 ms
58,572 KB
testcase_09 AC 153 ms
58,744 KB
testcase_10 AC 153 ms
57,104 KB
testcase_11 AC 141 ms
55,888 KB
testcase_12 AC 135 ms
57,596 KB
testcase_13 AC 133 ms
55,964 KB
testcase_14 AC 131 ms
56,200 KB
testcase_15 AC 129 ms
53,860 KB
testcase_16 AC 131 ms
55,900 KB
testcase_17 AC 134 ms
55,760 KB
testcase_18 AC 134 ms
55,856 KB
testcase_19 AC 136 ms
55,600 KB
testcase_20 AC 129 ms
55,640 KB
testcase_21 AC 134 ms
55,632 KB
testcase_22 AC 151 ms
60,512 KB
testcase_23 AC 152 ms
58,372 KB
testcase_24 AC 149 ms
58,160 KB
testcase_25 AC 150 ms
58,072 KB
testcase_26 AC 150 ms
58,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] xArr;
    static int[] yArr;
    static int[] cArr;
    static int[][][] dp;
    static int fee;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int goalX = sc.nextInt();
		int goalY = sc.nextInt();
		int n = sc.nextInt();
		fee = sc.nextInt();
		xArr = new int[n];
		yArr = new int[n];
		cArr = new int[n];
		for (int i = 0; i < n; i++) {
		    xArr[i] = sc.nextInt();
		    yArr[i] = sc.nextInt();
		    cArr[i] = sc.nextInt();
		}
		dp = new int[n][goalX + 1][goalY + 1];
		System.out.println(dfw(n - 1, goalX, goalY));
	}
	
	static int dfw(int idx, int x, int y) {
	    if (idx < 0) {
	        return (x + y) * fee;
	    }
	    if (dp[idx][x][y] != 0) {
	        return dp[idx][x][y];
	    }
	    dp[idx][x][y] = dfw(idx - 1, x, y);
	    if (xArr[idx] <= x && yArr[idx] <= y)  {
	        dp[idx][x][y] = Math.min(dp[idx][x][y], dfw(idx - 1, x - xArr[idx], y - yArr[idx]) + cArr[idx]);
	    }
	    return dp[idx][x][y];
	}
}
0