結果
問題 | No.1480 Many Complete Graphs |
ユーザー | tenten |
提出日時 | 2023-02-02 13:03:07 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 750 ms / 2,000 ms |
コード長 | 3,303 bytes |
コンパイル時間 | 4,633 ms |
コンパイル使用メモリ | 85,632 KB |
実行使用メモリ | 79,440 KB |
最終ジャッジ日時 | 2024-07-02 02:36:32 |
合計ジャッジ時間 | 32,358 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
37,152 KB |
testcase_01 | AC | 53 ms
37,160 KB |
testcase_02 | AC | 53 ms
37,300 KB |
testcase_03 | AC | 56 ms
37,412 KB |
testcase_04 | AC | 56 ms
37,428 KB |
testcase_05 | AC | 54 ms
37,288 KB |
testcase_06 | AC | 53 ms
37,288 KB |
testcase_07 | AC | 54 ms
37,080 KB |
testcase_08 | AC | 56 ms
37,156 KB |
testcase_09 | AC | 92 ms
38,760 KB |
testcase_10 | AC | 93 ms
38,640 KB |
testcase_11 | AC | 66 ms
37,112 KB |
testcase_12 | AC | 71 ms
37,924 KB |
testcase_13 | AC | 205 ms
49,868 KB |
testcase_14 | AC | 176 ms
47,252 KB |
testcase_15 | AC | 367 ms
53,496 KB |
testcase_16 | AC | 276 ms
51,120 KB |
testcase_17 | AC | 298 ms
51,024 KB |
testcase_18 | AC | 169 ms
47,340 KB |
testcase_19 | AC | 295 ms
50,760 KB |
testcase_20 | AC | 350 ms
52,528 KB |
testcase_21 | AC | 203 ms
50,216 KB |
testcase_22 | AC | 170 ms
46,272 KB |
testcase_23 | AC | 440 ms
63,548 KB |
testcase_24 | AC | 498 ms
56,428 KB |
testcase_25 | AC | 555 ms
61,112 KB |
testcase_26 | AC | 534 ms
62,504 KB |
testcase_27 | AC | 475 ms
56,312 KB |
testcase_28 | AC | 546 ms
68,944 KB |
testcase_29 | AC | 584 ms
66,752 KB |
testcase_30 | AC | 526 ms
69,128 KB |
testcase_31 | AC | 550 ms
69,660 KB |
testcase_32 | AC | 575 ms
67,108 KB |
testcase_33 | AC | 544 ms
66,480 KB |
testcase_34 | AC | 534 ms
66,336 KB |
testcase_35 | AC | 546 ms
66,628 KB |
testcase_36 | AC | 547 ms
66,324 KB |
testcase_37 | AC | 528 ms
66,512 KB |
testcase_38 | AC | 547 ms
66,284 KB |
testcase_39 | AC | 568 ms
67,420 KB |
testcase_40 | AC | 580 ms
67,624 KB |
testcase_41 | AC | 531 ms
66,364 KB |
testcase_42 | AC | 548 ms
66,232 KB |
testcase_43 | AC | 551 ms
66,676 KB |
testcase_44 | AC | 546 ms
67,024 KB |
testcase_45 | AC | 576 ms
69,316 KB |
testcase_46 | AC | 543 ms
67,056 KB |
testcase_47 | AC | 750 ms
71,072 KB |
testcase_48 | AC | 705 ms
70,736 KB |
testcase_49 | AC | 673 ms
70,724 KB |
testcase_50 | AC | 425 ms
67,780 KB |
testcase_51 | AC | 745 ms
70,928 KB |
testcase_52 | AC | 697 ms
68,672 KB |
testcase_53 | AC | 673 ms
72,032 KB |
testcase_54 | AC | 691 ms
71,236 KB |
testcase_55 | AC | 685 ms
69,128 KB |
testcase_56 | AC | 675 ms
68,932 KB |
testcase_57 | AC | 513 ms
79,440 KB |
testcase_58 | AC | 570 ms
68,144 KB |
evil_aftercontest.txt | AC | 941 ms
107,628 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(); int idx = n + i * 2 + x % 2; graph.get(x - 1).add(new Path(idx, x / 2 + c)); graph.get(idx).add(new Path(x - 1, x / 2 + x % 2)); } graph.get(n + i * 2).add(new Path(n + i * 2 + 1, 0)); graph.get(n + i * 2 + 1).add(new Path(n + i * 2, 1)); } long[] costs = new long[n + m * 2]; Arrays.fill(costs, Long.MAX_VALUE); PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); 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, x.value + p.value)); } } if (costs[n - 1] == Long.MAX_VALUE) { System.out.println(-1); } else { System.out.println(costs[n - 1]); } } 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(); } }