結果
問題 | No.1283 Extra Fee |
ユーザー | tenten |
提出日時 | 2021-03-19 13:17:43 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,655 bytes |
コンパイル時間 | 3,095 ms |
コンパイル使用メモリ | 79,644 KB |
実行使用メモリ | 98,252 KB |
最終ジャッジ日時 | 2024-04-29 06:38:10 |
合計ジャッジ時間 | 46,359 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
41,072 KB |
testcase_01 | AC | 132 ms
40,932 KB |
testcase_02 | AC | 143 ms
41,328 KB |
testcase_03 | AC | 134 ms
41,556 KB |
testcase_04 | AC | 134 ms
41,432 KB |
testcase_05 | AC | 119 ms
40,356 KB |
testcase_06 | AC | 151 ms
41,048 KB |
testcase_07 | AC | 136 ms
41,440 KB |
testcase_08 | AC | 171 ms
41,688 KB |
testcase_09 | AC | 149 ms
41,440 KB |
testcase_10 | AC | 149 ms
41,324 KB |
testcase_11 | AC | 418 ms
48,672 KB |
testcase_12 | AC | 516 ms
49,228 KB |
testcase_13 | AC | 495 ms
48,888 KB |
testcase_14 | AC | 1,189 ms
62,356 KB |
testcase_15 | AC | 1,423 ms
64,444 KB |
testcase_16 | AC | 589 ms
49,712 KB |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); HashMap<Integer, Integer> places = new HashMap<>(); for (int i = 0; i < m; i++) { places.put((sc.nextInt() - 1) * n + sc.nextInt() - 1, sc.nextInt()); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); long[][] costs = new long[2][n * n]; Arrays.fill(costs[0], Long.MAX_VALUE); Arrays.fill(costs[1], Long.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); int add = places.getOrDefault(p.idx, 0); if (costs[p.level][p.idx] <= p.value + add) { continue; } costs[p.level][p.idx] = p.value + add; if (p.idx % n > 0) { queue.add(new Path(p.idx - 1, p.level, p.value + 1 + add)); } if (p.idx % n < n - 1) { queue.add(new Path(p.idx + 1, p.level, p.value + 1 + add)); } if (p.idx / n > 0) { queue.add(new Path(p.idx - n, p.level, p.value + 1 + add)); } if (p.idx / n < n - 1) { queue.add(new Path(p.idx + n, p.level, p.value + 1 + add)); } if (p.level > 0) { continue; } if (costs[1][p.idx] <= p.value) { continue; } costs[1][p.idx] = p.value; if (p.idx % n > 0) { queue.add(new Path(p.idx - 1, 1, p.value + 1)); } if (p.idx % n < n - 1) { queue.add(new Path(p.idx + 1, 1, p.value + 1)); } if (p.idx / n > 0) { queue.add(new Path(p.idx - n, 1, p.value + 1)); } if (p.idx / n < n - 1) { queue.add(new Path(p.idx + n, 1, p.value + 1)); } } System.out.println(costs[1][n * n - 1]); } static class Path implements Comparable<Path> { int idx; int level; long value; public Path(int idx, int level, long value) { this.idx = idx; this.level = level; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } }