結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー uafr_csuafr_cs
提出日時 2017-03-24 22:47:34
言語 Java19
(openjdk 21)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 74,572 KB
実行使用メモリ 56,372 KB
最終ジャッジ日時 2023-09-20 01:53:24
合計ジャッジ時間 6,446 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,864 KB
testcase_01 AC 125 ms
55,764 KB
testcase_02 AC 115 ms
56,144 KB
testcase_03 AC 124 ms
55,808 KB
testcase_04 AC 121 ms
55,824 KB
testcase_05 AC 113 ms
55,968 KB
testcase_06 AC 113 ms
55,964 KB
testcase_07 AC 114 ms
56,156 KB
testcase_08 AC 150 ms
56,068 KB
testcase_09 AC 152 ms
55,740 KB
testcase_10 AC 127 ms
55,860 KB
testcase_11 AC 126 ms
55,832 KB
testcase_12 AC 127 ms
55,684 KB
testcase_13 AC 125 ms
55,828 KB
testcase_14 AC 123 ms
55,960 KB
testcase_15 AC 123 ms
55,732 KB
testcase_16 AC 128 ms
56,372 KB
testcase_17 AC 131 ms
55,516 KB
testcase_18 AC 122 ms
55,860 KB
testcase_19 AC 123 ms
55,856 KB
testcase_20 AC 117 ms
55,504 KB
testcase_21 AC 120 ms
56,228 KB
testcase_22 AC 150 ms
56,064 KB
testcase_23 AC 143 ms
56,148 KB
testcase_24 AC 143 ms
54,132 KB
testcase_25 AC 143 ms
56,268 KB
testcase_26 AC 141 ms
55,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int gx = sc.nextInt();
		final int gy = sc.nextInt();
		final int N = sc.nextInt();
		final int F = sc.nextInt();
		
		int[] xs = new int[N];
		int[] ys = new int[N];
		int[] cs = new int[N];
		for(int i = 0; i < N; i++){
			final int x = sc.nextInt();
			final int y = sc.nextInt();
			final int c = sc.nextInt();
			
			xs[i] = x;
			ys[i] = y;
			cs[i] = c;
		}
		
		long[][] DP = new long[gy + 1][gx + 1];
		for(int y = 0; y <= gy; y++){
			for(int x = 0; x <= gx; x++){
				DP[y][x] = (y + x) * F;
			}
		}
		
		for(int index = 0; index < N; index++){
			for(int y = gy; y >= 0; y--){
				final int ny = y - ys[index];
				if(ny < 0){ continue; }
				
				for(int x = gx; x >= 0; x--){
					final int nx = x - xs[index];
					if(nx < 0){ continue; }
					
					DP[y][x] = Math.min(DP[y][x], DP[ny][nx] + cs[index]);
				}
			}
		}
		
		
		/*
		for(int y = 0; y <= gy; y++){
			for(int x = 0; x <= gx; x++){
				System.out.print(DP[y][x] + " ");
			}
			System.out.println();
		}
		//*/
		
		System.out.println(DP[gy][gx]);
	}
}
0