結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー tentententen
提出日時 2020-12-24 13:09:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,496 ms / 2,000 ms
コード長 1,983 bytes
コンパイル時間 2,528 ms
コンパイル使用メモリ 81,112 KB
実行使用メモリ 145,940 KB
最終ジャッジ日時 2023-10-21 15:39:36
合計ジャッジ時間 23,515 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
56,336 KB
testcase_01 AC 90 ms
56,068 KB
testcase_02 AC 91 ms
56,256 KB
testcase_03 AC 106 ms
56,180 KB
testcase_04 AC 90 ms
56,064 KB
testcase_05 AC 105 ms
56,200 KB
testcase_06 AC 107 ms
56,388 KB
testcase_07 AC 106 ms
56,208 KB
testcase_08 AC 105 ms
56,296 KB
testcase_09 AC 105 ms
56,132 KB
testcase_10 AC 105 ms
56,148 KB
testcase_11 AC 108 ms
56,372 KB
testcase_12 AC 106 ms
56,424 KB
testcase_13 AC 106 ms
56,052 KB
testcase_14 AC 190 ms
59,432 KB
testcase_15 AC 191 ms
59,380 KB
testcase_16 AC 190 ms
59,424 KB
testcase_17 AC 189 ms
59,468 KB
testcase_18 AC 197 ms
60,188 KB
testcase_19 AC 182 ms
59,268 KB
testcase_20 AC 185 ms
59,496 KB
testcase_21 AC 192 ms
59,556 KB
testcase_22 AC 179 ms
59,248 KB
testcase_23 AC 189 ms
59,596 KB
testcase_24 AC 1,418 ms
145,668 KB
testcase_25 AC 1,447 ms
145,904 KB
testcase_26 AC 1,455 ms
145,840 KB
testcase_27 AC 1,460 ms
145,740 KB
testcase_28 AC 1,389 ms
145,668 KB
testcase_29 AC 1,438 ms
145,584 KB
testcase_30 AC 1,463 ms
145,544 KB
testcase_31 AC 1,496 ms
143,916 KB
testcase_32 AC 1,455 ms
145,604 KB
testcase_33 AC 1,474 ms
145,940 KB
testcase_34 AC 796 ms
131,960 KB
testcase_35 AC 142 ms
56,588 KB
testcase_36 AC 109 ms
55,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
    static ArrayList<HashMap<Integer, Integer>> rgraph = new ArrayList<>();
    static int[] costs;
    static int[] rcosts;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int n = Integer.parseInt(first[0]);
        int m = Integer.parseInt(first[1]);
        for (int i = 0; i < n; i++) {
            graph.add(new HashMap<>());
            rgraph.add(new HashMap<>());
        }
        for (int i = 0; i < m; i++) {
            String[] line = br.readLine().split(" ", 3);
            int a = Integer.parseInt(line[0]);
            int b = Integer.parseInt(line[1]);
            int c = Integer.parseInt(line[2]);
            graph.get(a).put(b, c);
            rgraph.get(b).put(a, c);
        }
        costs = new int[n];
        Arrays.fill(costs, -1);
        costs[0] = 0;
        dfw(n - 1);
        rcosts = new int[n];
        Arrays.fill(rcosts, Integer.MAX_VALUE);
        rcosts[n - 1] = costs[n - 1];
        rdfw(0);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (costs[i] < rcosts[i]) {
                ans++;
            }
        }
        System.out.println(costs[n - 1] + " " + ans + "/" + n);
    }
    
    static int rdfw(int idx) {
        if (rcosts[idx] == Integer.MAX_VALUE) {
            for (int x : graph.get(idx).keySet()) {
                rcosts[idx] = Math.min(rcosts[idx], rdfw(x) - graph.get(idx).get(x));
            }
        }
        return rcosts[idx];
    }
    
    static int dfw(int idx) {
        if (costs[idx] < 0) {
            for (int x : rgraph.get(idx).keySet()) {
                costs[idx] = Math.max(costs[idx], dfw(x) + rgraph.get(idx).get(x));
            }
        }
        return costs[idx];
    }
}
0