結果
問題 | No.2712 Play more! |
ユーザー | tenten |
提出日時 | 2024-04-01 18:24:18 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,650 bytes |
コンパイル時間 | 2,539 ms |
コンパイル使用メモリ | 80,400 KB |
実行使用メモリ | 54,864 KB |
最終ジャッジ日時 | 2024-09-30 21:56:47 |
合計ジャッジ時間 | 6,396 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
36,924 KB |
testcase_01 | AC | 45 ms
36,976 KB |
testcase_02 | AC | 44 ms
37,080 KB |
testcase_03 | AC | 43 ms
37,220 KB |
testcase_04 | AC | 44 ms
36,984 KB |
testcase_05 | AC | 44 ms
37,112 KB |
testcase_06 | AC | 43 ms
37,300 KB |
testcase_07 | AC | 117 ms
40,416 KB |
testcase_08 | AC | 108 ms
40,280 KB |
testcase_09 | AC | 110 ms
40,316 KB |
testcase_10 | AC | 46 ms
36,616 KB |
testcase_11 | AC | 119 ms
39,816 KB |
testcase_12 | AC | 116 ms
40,376 KB |
testcase_13 | AC | 115 ms
40,044 KB |
testcase_14 | AC | 98 ms
39,748 KB |
testcase_15 | AC | 132 ms
41,116 KB |
testcase_16 | AC | 121 ms
40,056 KB |
testcase_17 | AC | 119 ms
39,672 KB |
testcase_18 | AC | 103 ms
39,548 KB |
testcase_19 | AC | 94 ms
39,596 KB |
testcase_20 | AC | 119 ms
39,960 KB |
testcase_21 | AC | 126 ms
40,972 KB |
testcase_22 | AC | 121 ms
40,440 KB |
testcase_23 | AC | 146 ms
40,732 KB |
testcase_24 | AC | 123 ms
39,932 KB |
testcase_25 | AC | 125 ms
40,668 KB |
testcase_26 | AC | 118 ms
39,892 KB |
testcase_27 | AC | 113 ms
39,580 KB |
testcase_28 | AC | 95 ms
39,632 KB |
testcase_29 | AC | 117 ms
40,016 KB |
testcase_30 | AC | 119 ms
40,220 KB |
testcase_31 | WA | - |
testcase_32 | AC | 130 ms
41,460 KB |
testcase_33 | AC | 62 ms
38,072 KB |
testcase_34 | AC | 46 ms
36,596 KB |
testcase_35 | AC | 46 ms
37,080 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int[] values = new int[n]; List<List<Path>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { graph.get(sc.nextInt() - 1).add(new Path(sc.nextInt() - 1, sc.nextInt())); } PriorityQueue<Path> queue = new PriorityQueue<>(); long[] points = new long[n]; Arrays.fill(points, Long.MIN_VALUE); queue.add(new Path(0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (p.value < Long.MAX_VALUE) { p.value += values[p.idx]; } if (points[p.idx] >= p.value) { continue; } if (points[p.idx] > Long.MIN_VALUE) { p.value = Long.MAX_VALUE; } points[p.idx] = p.value; for (Path x : graph.get(p.idx)) { queue.add(new Path(x.idx, p.value - (p.value == Long.MAX_VALUE ? 0 : x.value))); } } System.out.println(points[n - 1] == Long.MAX_VALUE ? "inf" : points[n - 1]); } static class Path implements Comparable<Path> { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return Long.compare(another.value, value); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }