結果
問題 | No.468 役に立つ競技プログラミング実践編 |
ユーザー | tenten |
提出日時 | 2023-12-14 17:44:27 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 948 ms / 2,000 ms |
コード長 | 3,473 bytes |
コンパイル時間 | 3,051 ms |
コンパイル使用メモリ | 91,680 KB |
実行使用メモリ | 90,088 KB |
最終ジャッジ日時 | 2024-09-27 05:44:40 |
合計ジャッジ時間 | 18,309 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
38,204 KB |
testcase_01 | AC | 86 ms
39,576 KB |
testcase_02 | AC | 75 ms
38,424 KB |
testcase_03 | AC | 101 ms
40,076 KB |
testcase_04 | AC | 78 ms
39,668 KB |
testcase_05 | AC | 101 ms
39,788 KB |
testcase_06 | AC | 95 ms
39,836 KB |
testcase_07 | AC | 105 ms
39,516 KB |
testcase_08 | AC | 105 ms
40,212 KB |
testcase_09 | AC | 101 ms
40,216 KB |
testcase_10 | AC | 95 ms
40,064 KB |
testcase_11 | AC | 87 ms
39,820 KB |
testcase_12 | AC | 103 ms
39,648 KB |
testcase_13 | AC | 93 ms
39,636 KB |
testcase_14 | AC | 167 ms
41,824 KB |
testcase_15 | AC | 169 ms
41,856 KB |
testcase_16 | AC | 173 ms
41,676 KB |
testcase_17 | AC | 173 ms
41,992 KB |
testcase_18 | AC | 169 ms
42,244 KB |
testcase_19 | AC | 169 ms
42,056 KB |
testcase_20 | AC | 158 ms
42,456 KB |
testcase_21 | AC | 156 ms
42,384 KB |
testcase_22 | AC | 157 ms
41,644 KB |
testcase_23 | AC | 168 ms
43,780 KB |
testcase_24 | AC | 937 ms
89,308 KB |
testcase_25 | AC | 945 ms
90,088 KB |
testcase_26 | AC | 930 ms
89,932 KB |
testcase_27 | AC | 934 ms
89,648 KB |
testcase_28 | AC | 948 ms
89,872 KB |
testcase_29 | AC | 930 ms
89,804 KB |
testcase_30 | AC | 924 ms
89,488 KB |
testcase_31 | AC | 892 ms
89,436 KB |
testcase_32 | AC | 896 ms
90,044 KB |
testcase_33 | AC | 908 ms
88,632 KB |
testcase_34 | AC | 685 ms
89,208 KB |
testcase_35 | AC | 115 ms
40,376 KB |
testcase_36 | AC | 81 ms
37,744 KB |
ソースコード
import java.io.*; import java.util.*; 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(); ArrayList<ArrayList<Path>> graph = new ArrayList<>(); ArrayList<ArrayList<Path>> reverse = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); reverse.add(new ArrayList<>()); } int[] counts = new int[n]; int[] rCounts = new int[n]; for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); counts[b]++; rCounts[a]++; graph.get(a).add(new Path(b, c)); reverse.get(b).add(new Path(a, c)); } ArrayDeque<Integer> idxes = new ArrayDeque<>(); idxes.add(0); int[] value = new int[n]; while (idxes.size() > 0) { int x = idxes.poll(); for (Path y : graph.get(x)) { value[y.idx] = Math.max(value[y.idx], value[x] + y.value); counts[y.idx]--; if(counts[y.idx] == 0) { idxes.add(y.idx); } } } idxes.add(n - 1); int[] rValue = new int[n]; Arrays.fill(rValue, Integer.MAX_VALUE); rValue[n - 1] = value[n - 1]; while (idxes.size() > 0) { int x = idxes.poll(); for (Path y : reverse.get(x)) { rValue[y.idx] = Math.min(rValue[y.idx], rValue[x] - y.value); rCounts[y.idx]--; if(rCounts[y.idx] == 0) { idxes.add(y.idx); } } } int ans = 0; for (int i = 0; i < n; i++) { if (rValue[i] > value[i]) { ans++; } } System.out.print(value[n - 1]); System.out.println(" " + ans + "/" + n); } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }