結果
問題 | No.30 たこやき工場 |
ユーザー | tenten |
提出日時 | 2021-03-05 18:29:46 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,421 bytes |
コンパイル時間 | 2,667 ms |
コンパイル使用メモリ | 80,576 KB |
実行使用メモリ | 648,796 KB |
最終ジャッジ日時 | 2024-04-16 06:36:55 |
合計ジャッジ時間 | 10,962 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
41,484 KB |
testcase_01 | AC | 138 ms
40,984 KB |
testcase_02 | AC | 148 ms
41,088 KB |
testcase_03 | AC | 145 ms
40,968 KB |
testcase_04 | AC | 140 ms
41,336 KB |
testcase_05 | AC | 138 ms
41,328 KB |
testcase_06 | AC | 143 ms
41,184 KB |
testcase_07 | AC | 141 ms
41,524 KB |
testcase_08 | AC | 343 ms
53,108 KB |
testcase_09 | AC | 190 ms
42,140 KB |
testcase_10 | MLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int parts = sc.nextInt() - 1; int count = sc.nextInt(); int product = sc.nextInt() - 1; graph.get(product).put(parts, count); } ArrayDeque<Path> deq = new ArrayDeque<>(); deq.add(new Path(n - 1, 1)); long[] ans = new long[n]; while (deq.size() > 0) { Path p = deq.poll(); if (graph.get(p.idx).size() == 0) { ans[p.idx] += p.value; } else { for (int x : graph.get(p.idx).keySet()) { deq.add(new Path(x, p.value * graph.get(p.idx).get(x))); } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n - 1; i++) { sb.append(ans[i]).append("\n"); } System.out.print(sb); } static class Path { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } } }