結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー | Grenache |
提出日時 | 2017-03-25 00:02:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 1,637 bytes |
コンパイル時間 | 3,758 ms |
コンパイル使用メモリ | 76,288 KB |
実行使用メモリ | 55,900 KB |
最終ジャッジ日時 | 2023-09-20 06:25:32 |
合計ジャッジ時間 | 9,007 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 128 ms
55,684 KB |
testcase_01 | AC | 129 ms
55,468 KB |
testcase_02 | AC | 126 ms
55,632 KB |
testcase_03 | AC | 127 ms
55,780 KB |
testcase_04 | AC | 128 ms
55,540 KB |
testcase_05 | AC | 130 ms
55,584 KB |
testcase_06 | AC | 126 ms
55,484 KB |
testcase_07 | AC | 127 ms
55,384 KB |
testcase_08 | AC | 167 ms
55,596 KB |
testcase_09 | AC | 165 ms
55,792 KB |
testcase_10 | AC | 153 ms
55,856 KB |
testcase_11 | AC | 143 ms
55,900 KB |
testcase_12 | AC | 142 ms
55,708 KB |
testcase_13 | AC | 141 ms
55,748 KB |
testcase_14 | AC | 139 ms
55,820 KB |
testcase_15 | AC | 135 ms
55,764 KB |
testcase_16 | AC | 139 ms
55,536 KB |
testcase_17 | AC | 139 ms
55,512 KB |
testcase_18 | AC | 144 ms
55,676 KB |
testcase_19 | AC | 137 ms
55,664 KB |
testcase_20 | AC | 131 ms
55,656 KB |
testcase_21 | AC | 135 ms
55,372 KB |
testcase_22 | AC | 162 ms
55,800 KB |
testcase_23 | AC | 166 ms
55,544 KB |
testcase_24 | AC | 161 ms
55,540 KB |
testcase_25 | AC | 158 ms
55,796 KB |
testcase_26 | AC | 162 ms
55,832 KB |
ソースコード
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); } } }