結果
問題 | No.1577 織姫と彦星2 |
ユーザー | tenten |
提出日時 | 2023-04-25 18:20:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 521 ms / 2,000 ms |
コード長 | 3,135 bytes |
コンパイル時間 | 2,864 ms |
コンパイル使用メモリ | 85,164 KB |
実行使用メモリ | 64,392 KB |
最終ジャッジ日時 | 2024-11-14 14:26:48 |
合計ジャッジ時間 | 20,820 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
50,468 KB |
testcase_01 | AC | 55 ms
50,284 KB |
testcase_02 | AC | 55 ms
50,520 KB |
testcase_03 | AC | 55 ms
50,516 KB |
testcase_04 | AC | 55 ms
50,480 KB |
testcase_05 | AC | 202 ms
55,792 KB |
testcase_06 | AC | 132 ms
54,772 KB |
testcase_07 | AC | 427 ms
63,572 KB |
testcase_08 | AC | 274 ms
59,096 KB |
testcase_09 | AC | 521 ms
64,392 KB |
testcase_10 | AC | 240 ms
59,120 KB |
testcase_11 | AC | 115 ms
54,628 KB |
testcase_12 | AC | 329 ms
59,224 KB |
testcase_13 | AC | 204 ms
58,028 KB |
testcase_14 | AC | 348 ms
61,300 KB |
testcase_15 | AC | 212 ms
56,284 KB |
testcase_16 | AC | 403 ms
63,660 KB |
testcase_17 | AC | 317 ms
59,540 KB |
testcase_18 | AC | 64 ms
50,612 KB |
testcase_19 | AC | 384 ms
61,308 KB |
testcase_20 | AC | 360 ms
61,512 KB |
testcase_21 | AC | 395 ms
61,588 KB |
testcase_22 | AC | 412 ms
61,652 KB |
testcase_23 | AC | 260 ms
58,808 KB |
testcase_24 | AC | 424 ms
63,376 KB |
testcase_25 | AC | 202 ms
56,880 KB |
testcase_26 | AC | 256 ms
58,808 KB |
testcase_27 | AC | 364 ms
61,180 KB |
testcase_28 | AC | 343 ms
61,352 KB |
testcase_29 | AC | 282 ms
59,648 KB |
testcase_30 | AC | 300 ms
59,324 KB |
testcase_31 | AC | 361 ms
61,612 KB |
testcase_32 | AC | 96 ms
51,816 KB |
testcase_33 | AC | 90 ms
51,468 KB |
testcase_34 | AC | 260 ms
58,528 KB |
testcase_35 | AC | 377 ms
61,612 KB |
testcase_36 | AC | 398 ms
61,500 KB |
testcase_37 | AC | 466 ms
64,308 KB |
testcase_38 | AC | 482 ms
63,644 KB |
testcase_39 | AC | 263 ms
59,000 KB |
testcase_40 | AC | 258 ms
58,852 KB |
testcase_41 | AC | 425 ms
61,408 KB |
testcase_42 | AC | 310 ms
58,824 KB |
testcase_43 | AC | 315 ms
59,472 KB |
testcase_44 | AC | 106 ms
51,724 KB |
testcase_45 | AC | 178 ms
56,216 KB |
testcase_46 | AC | 193 ms
56,044 KB |
testcase_47 | AC | 381 ms
61,296 KB |
testcase_48 | AC | 227 ms
58,680 KB |
testcase_49 | AC | 274 ms
58,904 KB |
testcase_50 | AC | 222 ms
58,476 KB |
testcase_51 | AC | 134 ms
55,040 KB |
testcase_52 | AC | 433 ms
63,356 KB |
testcase_53 | AC | 447 ms
63,460 KB |
testcase_54 | AC | 275 ms
59,028 KB |
testcase_55 | AC | 419 ms
63,404 KB |
testcase_56 | AC | 218 ms
56,996 KB |
testcase_57 | AC | 166 ms
55,904 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[] values = new int[n + 2]; ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); HashMap<Integer, Integer> idxes = new HashMap<>(); HashMap<Integer, ArrayList<Integer>> hamings = new HashMap<>(); for (int i = 0; i < n + 2; i++) { values[i] = sc.nextInt(); idxes.put(values[i], i); graph.add(new ArrayList<>()); } for (int i = 0; i < n + 2; i++) { for (int j = 0; j < 30; j++) { values[i] ^= (1 << j); if (idxes.containsKey(values[i])) { graph.get(i).add(idxes.get(values[i])); } values[i] ^= (1 << j); } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); int[] costs = new int[n + 2]; Arrays.fill(costs, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } if (costs[1] == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(costs[1] - 1); } } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } 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(); } }