結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー shinwisteria
提出日時 2017-03-24 23:42:40
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 2,930 ms
コンパイル使用メモリ 77,672 KB
実行使用メモリ 54,640 KB
最終ジャッジ日時 2024-07-06 01:39:56
合計ジャッジ時間 7,232 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 3 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class WarpCristal {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int Gx = s.nextInt(),Gy = s.nextInt(),N = s.nextInt(),F = s.nextInt();
		int[][] cost = new int[Gx+1][Gy+1];
		int[][] d = new int[Gx+1][Gy+1];
		
		for(int i = 0;i < N;i++){
			d[s.nextInt()][s.nextInt()] = s.nextInt();
		}
		s.close();
		for(int i = 0;i <= Gx;i++){
			for(int j = 0;j <= Gy;j++){
				cost[i][j] = (i+j)*F;
				for(int x = 0;x <= i;x++){
					for(int y = 0;y <= j;y++){
						if(d[x][y] != 0 && cost[i][j] > cost[i-x][j-y] + d[x][y]){
							cost[i][j] = cost[i-x][j-y] + d[x][y];
							d[x][y] = 0;
						}
					}
				}
			}
		}
		System.out.println(cost[Gx][Gy]);
	}

}
0