結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー uafr_csuafr_cs
提出日時 2017-03-24 22:44:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,472 bytes
コンパイル時間 2,075 ms
コンパイル使用メモリ 74,384 KB
実行使用メモリ 57,824 KB
最終ジャッジ日時 2023-09-20 01:49:42
合計ジャッジ時間 7,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,072 KB
testcase_01 AC 122 ms
55,852 KB
testcase_02 AC 120 ms
55,708 KB
testcase_03 AC 125 ms
55,816 KB
testcase_04 WA -
testcase_05 AC 128 ms
55,732 KB
testcase_06 AC 129 ms
55,700 KB
testcase_07 AC 126 ms
55,820 KB
testcase_08 AC 193 ms
54,724 KB
testcase_09 AC 189 ms
56,728 KB
testcase_10 AC 143 ms
55,824 KB
testcase_11 AC 139 ms
55,536 KB
testcase_12 AC 137 ms
55,992 KB
testcase_13 AC 142 ms
55,536 KB
testcase_14 AC 137 ms
56,496 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 138 ms
55,668 KB
testcase_19 WA -
testcase_20 AC 135 ms
55,804 KB
testcase_21 AC 135 ms
55,960 KB
testcase_22 WA -
testcase_23 AC 165 ms
56,472 KB
testcase_24 AC 161 ms
56,112 KB
testcase_25 AC 166 ms
56,124 KB
testcase_26 AC 164 ms
55,948 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] = Integer.MAX_VALUE;
			}
		}
		DP[0][0] = 0;
		
		for(int index = 0; index < N; index++){
			for(int y = 0; y <= gy; y++){
				final int ny = y + ys[index];
				if(ny > gy){ break; }
				
				for(int x = 0; x <= gx; x++){
					final int nx = x + xs[index];
					if(nx > gx){ break; }
					
					DP[ny][nx] = Math.min(DP[ny][nx], DP[y][x] + cs[index]);
				}
			}
		}
		
		for(int y = 0; y <= gy; y++){
			for(int x = 0; x <= gx; x++){
				if(x != gx){ DP[y][x + 1] = Math.min(DP[y][x + 1], DP[y][x] + F); }
				if(y != gy){ DP[y + 1][x] = Math.min(DP[y + 1][x], DP[y][x] + F); }
			}
		}
		
		/*
		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