結果
問題 | No.468 役に立つ競技プログラミング実践編 |
ユーザー | tenten |
提出日時 | 2020-12-24 13:06:06 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,733 bytes |
コンパイル時間 | 4,914 ms |
コンパイル使用メモリ | 88,248 KB |
実行使用メモリ | 164,988 KB |
最終ジャッジ日時 | 2023-10-21 15:39:04 |
合計ジャッジ時間 | 39,725 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 176 ms
58,228 KB |
testcase_01 | AC | 175 ms
58,412 KB |
testcase_02 | AC | 178 ms
58,484 KB |
testcase_03 | AC | 232 ms
59,836 KB |
testcase_04 | AC | 182 ms
58,524 KB |
testcase_05 | AC | 243 ms
60,320 KB |
testcase_06 | AC | 236 ms
58,964 KB |
testcase_07 | AC | 242 ms
59,912 KB |
testcase_08 | AC | 231 ms
58,956 KB |
testcase_09 | AC | 244 ms
59,956 KB |
testcase_10 | AC | 240 ms
58,368 KB |
testcase_11 | AC | 248 ms
58,600 KB |
testcase_12 | AC | 241 ms
58,260 KB |
testcase_13 | AC | 239 ms
58,996 KB |
testcase_14 | AC | 333 ms
62,652 KB |
testcase_15 | AC | 325 ms
62,780 KB |
testcase_16 | AC | 324 ms
62,752 KB |
testcase_17 | AC | 331 ms
62,920 KB |
testcase_18 | AC | 324 ms
62,872 KB |
testcase_19 | AC | 335 ms
62,604 KB |
testcase_20 | AC | 330 ms
61,324 KB |
testcase_21 | AC | 317 ms
62,952 KB |
testcase_22 | AC | 318 ms
62,628 KB |
testcase_23 | AC | 324 ms
62,896 KB |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | AC | 1,376 ms
153,220 KB |
testcase_35 | AC | 277 ms
62,004 KB |
testcase_36 | AC | 196 ms
58,516 KB |
ソースコード
import java.util.*; 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) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); rgraph.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); 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]; } }