結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー shinwisteria
提出日時 2017-03-24 23:58:01
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 983 bytes
コンパイル時間 3,833 ms
コンパイル使用メモリ 77,944 KB
実行使用メモリ 56,416 KB
最終ジャッジ日時 2024-07-06 02:00:10
合計ジャッジ時間 10,113 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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];
		int[][] anti = new int[Gx+1][Gy+1];
		
		for(int i = 0;i < N;i++){
			d[s.nextInt()][s.nextInt()] = s.nextInt();
		}
		int sx = 0,sy = 0;
		s.close();
		for(int i = sx;i <= Gx;i++){
			for(int j = sy;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];
							anti[x][y] = d[x][y];
							d[x][y] = 0;
						}
						if(anti[x][y] != 0&& cost[i][j] > cost[i-x][j-y]){
							cost[i][j] = cost[i-x][j-y] + anti[x][y];
							d[x][y] = anti[x][y];
							anti[x][y] = 0;
						}
					}
				}
			}
		}
		System.out.println(cost[Gx][Gy]);
	}

}
0