結果
| 問題 |
No.496 ワープクリスタル (給料日前編)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-25 00:02:58 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 177 ms / 2,000 ms |
| コード長 | 1,637 bytes |
| コンパイル時間 | 3,901 ms |
| コンパイル使用メモリ | 81,580 KB |
| 実行使用メモリ | 54,604 KB |
| 最終ジャッジ日時 | 2024-07-06 02:24:41 |
| 合計ジャッジ時間 | 8,959 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
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(0, 0), 0);
for (int i = 0; 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);
}
}
}