結果
問題 | No.1480 Many Complete Graphs |
ユーザー | tenten |
提出日時 | 2023-04-12 10:20:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 847 ms / 2,000 ms |
コード長 | 3,278 bytes |
コンパイル時間 | 3,236 ms |
コンパイル使用メモリ | 92,340 KB |
実行使用メモリ | 89,716 KB |
最終ジャッジ日時 | 2024-10-08 08:09:22 |
合計ジャッジ時間 | 29,416 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
37,208 KB |
testcase_01 | AC | 51 ms
36,624 KB |
testcase_02 | AC | 53 ms
37,268 KB |
testcase_03 | AC | 51 ms
37,080 KB |
testcase_04 | AC | 51 ms
36,924 KB |
testcase_05 | AC | 53 ms
37,140 KB |
testcase_06 | AC | 53 ms
36,952 KB |
testcase_07 | AC | 52 ms
37,100 KB |
testcase_08 | AC | 55 ms
37,248 KB |
testcase_09 | AC | 96 ms
38,400 KB |
testcase_10 | AC | 84 ms
39,048 KB |
testcase_11 | AC | 59 ms
37,440 KB |
testcase_12 | AC | 69 ms
37,920 KB |
testcase_13 | AC | 180 ms
50,532 KB |
testcase_14 | AC | 160 ms
47,476 KB |
testcase_15 | AC | 328 ms
53,748 KB |
testcase_16 | AC | 237 ms
50,940 KB |
testcase_17 | AC | 232 ms
51,316 KB |
testcase_18 | AC | 152 ms
46,588 KB |
testcase_19 | AC | 265 ms
50,996 KB |
testcase_20 | AC | 309 ms
52,752 KB |
testcase_21 | AC | 190 ms
50,440 KB |
testcase_22 | AC | 149 ms
46,424 KB |
testcase_23 | AC | 312 ms
63,524 KB |
testcase_24 | AC | 454 ms
56,780 KB |
testcase_25 | AC | 507 ms
61,512 KB |
testcase_26 | AC | 513 ms
62,400 KB |
testcase_27 | AC | 449 ms
56,724 KB |
testcase_28 | AC | 494 ms
66,564 KB |
testcase_29 | AC | 507 ms
68,864 KB |
testcase_30 | AC | 519 ms
66,220 KB |
testcase_31 | AC | 511 ms
69,060 KB |
testcase_32 | AC | 516 ms
66,628 KB |
testcase_33 | AC | 518 ms
66,348 KB |
testcase_34 | AC | 502 ms
66,440 KB |
testcase_35 | AC | 524 ms
66,732 KB |
testcase_36 | AC | 541 ms
66,836 KB |
testcase_37 | AC | 499 ms
66,260 KB |
testcase_38 | AC | 498 ms
66,568 KB |
testcase_39 | AC | 536 ms
66,776 KB |
testcase_40 | AC | 500 ms
68,876 KB |
testcase_41 | AC | 495 ms
66,740 KB |
testcase_42 | AC | 495 ms
66,508 KB |
testcase_43 | AC | 479 ms
66,544 KB |
testcase_44 | AC | 509 ms
66,636 KB |
testcase_45 | AC | 518 ms
66,540 KB |
testcase_46 | AC | 536 ms
66,472 KB |
testcase_47 | AC | 674 ms
80,900 KB |
testcase_48 | AC | 847 ms
70,784 KB |
testcase_49 | AC | 652 ms
70,708 KB |
testcase_50 | AC | 515 ms
67,212 KB |
testcase_51 | AC | 816 ms
70,936 KB |
testcase_52 | AC | 627 ms
72,060 KB |
testcase_53 | AC | 617 ms
72,080 KB |
testcase_54 | AC | 577 ms
72,000 KB |
testcase_55 | AC | 627 ms
69,092 KB |
testcase_56 | AC | 638 ms
72,000 KB |
testcase_57 | AC | 593 ms
76,684 KB |
testcase_58 | AC | 770 ms
89,716 KB |
evil_aftercontest.txt | AC | 1,166 ms
118,992 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<>(); for (int i = 0; i < n + m * 2; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int k = sc.nextInt(); int c = sc.nextInt(); for (int j = 0; j < k; j++) { int x = sc.nextInt(); graph.get(x - 1).add(new Path(n + i * 2 + x % 2, x + c)); graph.get(n + i * 2 + x % 2).add(new Path(x - 1, x + c)); } graph.get(n + i * 2).add(new Path(n + i * 2 + 1, 1)); graph.get(n + i * 2 + 1).add(new Path(n + i * 2, 1)); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); long[] costs = new long[n + m * 2]; Arrays.fill(costs, Long.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (Path x : graph.get(p.idx)) { queue.add(new Path(x.idx, p.value + x.value)); } } if (costs[n - 1] == Long.MAX_VALUE) { System.out.println(-1); } else { System.out.println(costs[n - 1] / 2); } } static class Path implements Comparable<Path> { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } } 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(); } }