結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー 37zigen37zigen
提出日時 2016-07-16 13:49:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 77,204 KB
実行使用メモリ 54,224 KB
最終ジャッジ日時 2024-04-23 13:43:17
合計ジャッジ時間 6,262 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
52,860 KB
testcase_01 AC 105 ms
52,888 KB
testcase_02 AC 113 ms
53,208 KB
testcase_03 AC 115 ms
54,212 KB
testcase_04 AC 111 ms
53,392 KB
testcase_05 AC 121 ms
54,224 KB
testcase_06 AC 107 ms
52,868 KB
testcase_07 AC 113 ms
53,708 KB
testcase_08 AC 164 ms
42,420 KB
testcase_09 AC 134 ms
41,568 KB
testcase_10 AC 151 ms
42,656 KB
testcase_11 AC 130 ms
42,008 KB
testcase_12 AC 128 ms
41,576 KB
testcase_13 AC 151 ms
42,788 KB
testcase_14 AC 129 ms
42,040 KB
testcase_15 AC 128 ms
41,696 KB
testcase_16 AC 127 ms
42,220 KB
testcase_17 AC 143 ms
42,404 KB
testcase_18 AC 148 ms
41,864 KB
testcase_19 AC 126 ms
42,108 KB
testcase_20 AC 140 ms
42,012 KB
testcase_21 AC 123 ms
41,604 KB
testcase_22 AC 154 ms
42,540 KB
testcase_23 AC 152 ms
41,568 KB
testcase_24 AC 144 ms
41,860 KB
testcase_25 AC 151 ms
41,948 KB
testcase_26 AC 138 ms
41,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static void solver() {
		int INF = Integer.MAX_VALUE / 4;
		Scanner sc = new Scanner(System.in);
		int gx = sc.nextInt();
		int gy = sc.nextInt();
		int n = sc.nextInt();
		int f = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		int[][] map = new int[101][101];
		for (int i = 0; i <= 100; i++) {
			for (int j = 0; j <= 100; j++) {
				map[i][j] = INF;
			}
		}
		map[0][0] = 0;
		long ans = f * (gx + gy);
		for (int i = 0; i < n; i++) {
			if (c[i] < (x[i] + y[i]) * f) {
				for (int sum = gx + gy; sum >= 0; sum--) {
					for (int xx = gx; xx >= 0; xx--) {
						int yy = sum - gx;
						if (yy < 0 || yy > gy)
							continue;
						if (map[xx][yy] != INF) {
							if (xx + x[i] <= gx && yy + y[i] <= gy) {
								map[xx + x[i]][yy + y[i]] = Math.min(map[xx][yy] + c[i], map[xx + x[i]][yy + y[i]]);
								ans = Math.min(ans, f * (gx + gy - xx - yy - x[i] - y[i]) + map[xx + x[i]][yy + y[i]]);
							}
						}
					}
				}
			} else {
				continue;
			}
		}
		System.out.println(ans);
	}
}
0