結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー GrenacheGrenache
提出日時 2017-03-24 23:57:00
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,646 bytes
コンパイル時間 5,763 ms
コンパイル使用メモリ 76,124 KB
実行使用メモリ 58,020 KB
最終ジャッジ日時 2023-09-20 05:53:19
合計ジャッジ時間 11,310 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,580 KB
testcase_01 AC 130 ms
55,676 KB
testcase_02 AC 131 ms
55,640 KB
testcase_03 AC 130 ms
55,340 KB
testcase_04 AC 130 ms
56,044 KB
testcase_05 AC 133 ms
55,676 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 171 ms
55,844 KB
testcase_09 AC 167 ms
55,996 KB
testcase_10 AC 152 ms
55,784 KB
testcase_11 AC 152 ms
55,700 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 134 ms
55,656 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.Map.*;


public class Main_yukicoder496 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int gx = sc.nextInt();
		int gy = sc.nextInt();
		int n = sc.nextInt();
		int f = sc.nextInt();

		int[] x = new int[n];
		int[] y = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}

		Map<Integer, Integer> hm = new HashMap<>();
		hm.put(enc(x[0], y[0]), c[0]);
		for (int i = 1; i < n; i++) {
			List<Integer> tmp = new ArrayList<>(hm.keySet());
			for (int e : tmp) {
				int xx = e / 1000;
				int yy = e % 1000;
				int cc = hm.get(e);

				int nx = xx + x[i];
				int ny = yy + y[i];
				int nc = cc + c[i];

				if (nx > gx || ny > gy) {
					continue;
				}

				int key = enc(nx, ny);
				if (!hm.containsKey(key)) {
					hm.put(key, nc);
				} else {
					if (hm.get(key) > nc) {
						hm.put(key, nc);
					}
				}
			}
		}

		int min = (gx + gy) * f;
		for (Entry<Integer, Integer> e : hm.entrySet()) {
			int xx = e.getKey() / 1000;
			int yy = e.getKey() % 1000;
			int cc = e.getValue();

			min = Math.min(min, cc + (gx - xx + gy - yy) * f);
		}

		pr.println(min);
	}

	private static int enc(int x, int y) {
		return x * 1000 + y;
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0