結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー shinwisteria
提出日時 2017-03-26 13:03:29
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,250 bytes
コンパイル時間 3,669 ms
コンパイル使用メモリ 80,288 KB
実行使用メモリ 54,492 KB
最終ジャッジ日時 2024-07-06 06:26:09
合計ジャッジ時間 8,265 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class WarpCrystal {

	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 sx = 0,sy = 0;
		ArrayList<Integer>[] crystal = new ArrayList[N];
		for(int i = 0;i < N;i++){
			crystal[i] = new ArrayList<Integer>();
			crystal[i].add(s.nextInt());
			crystal[i].add(s.nextInt());
			crystal[i].add(s.nextInt());
		}
		int cost = (Gx + Gy) * F, cost0 = cost;
		while(sx != Gx || sy != Gy){
			//System.out.println(sx + " " + sy);
			int kn = -1;
			for(int i = 0;i < N;i++){
				int x = crystal[i].get(0);
				int y = crystal[i].get(1);
				int c = crystal[i].get(2);
				if(c != 0){
					if(sx + x <= Gx && sy + y <= Gy && cost > cost0 + c - (x+y)*F){
						//System.out.print("更新" + x + " " + y + " " + cost);
						cost += c-(x+y)*F;
						kn = i;
						//System.out.println(" " + cost);
					}else if(c >= (x+y)*F){
						crystal[i].set(2, 0);
					}
				}
			}
			if(kn != -1){
				crystal[kn].set(2, 0);
				sx += crystal[kn].get(0);
				sy += crystal[kn].get(1);
				cost0 = cost;
			}else{
				sx = Gx;
				sy = Gy;
			}
		}
		s.close();
		System.out.println(cost);
	}
}
0