結果
問題 | No.468 役に立つ競技プログラミング実践編 |
ユーザー | tenten |
提出日時 | 2023-12-14 17:44:27 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,037 ms / 2,000 ms |
コード長 | 3,473 bytes |
コンパイル時間 | 2,756 ms |
コンパイル使用メモリ | 91,456 KB |
実行使用メモリ | 103,672 KB |
最終ジャッジ日時 | 2023-12-14 17:44:47 |
合計ジャッジ時間 | 20,314 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
54,764 KB |
testcase_01 | AC | 82 ms
54,904 KB |
testcase_02 | AC | 82 ms
54,760 KB |
testcase_03 | AC | 101 ms
56,792 KB |
testcase_04 | AC | 82 ms
54,768 KB |
testcase_05 | AC | 103 ms
56,688 KB |
testcase_06 | AC | 102 ms
56,804 KB |
testcase_07 | AC | 109 ms
56,444 KB |
testcase_08 | AC | 101 ms
56,796 KB |
testcase_09 | AC | 102 ms
56,796 KB |
testcase_10 | AC | 100 ms
56,700 KB |
testcase_11 | AC | 101 ms
56,680 KB |
testcase_12 | AC | 100 ms
56,816 KB |
testcase_13 | AC | 100 ms
56,704 KB |
testcase_14 | AC | 166 ms
57,588 KB |
testcase_15 | AC | 181 ms
58,088 KB |
testcase_16 | AC | 166 ms
57,584 KB |
testcase_17 | AC | 185 ms
58,720 KB |
testcase_18 | AC | 181 ms
58,732 KB |
testcase_19 | AC | 181 ms
58,112 KB |
testcase_20 | AC | 179 ms
57,976 KB |
testcase_21 | AC | 181 ms
58,728 KB |
testcase_22 | AC | 181 ms
60,284 KB |
testcase_23 | AC | 170 ms
57,584 KB |
testcase_24 | AC | 1,028 ms
103,096 KB |
testcase_25 | AC | 988 ms
103,300 KB |
testcase_26 | AC | 1,037 ms
103,300 KB |
testcase_27 | AC | 1,001 ms
103,000 KB |
testcase_28 | AC | 1,025 ms
103,304 KB |
testcase_29 | AC | 1,014 ms
103,352 KB |
testcase_30 | AC | 979 ms
103,108 KB |
testcase_31 | AC | 987 ms
103,392 KB |
testcase_32 | AC | 1,015 ms
103,304 KB |
testcase_33 | AC | 1,025 ms
102,992 KB |
testcase_34 | AC | 763 ms
103,672 KB |
testcase_35 | AC | 127 ms
56,948 KB |
testcase_36 | AC | 88 ms
54,892 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(); } }