結果
問題 | No.1576 織姫と彦星 |
ユーザー | tenten |
提出日時 | 2024-04-23 18:40:15 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 206 ms / 2,000 ms |
コード長 | 2,556 bytes |
コンパイル時間 | 2,642 ms |
コンパイル使用メモリ | 79,428 KB |
実行使用メモリ | 57,520 KB |
最終ジャッジ日時 | 2024-10-15 19:26:42 |
合計ジャッジ時間 | 12,720 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
50,200 KB |
testcase_01 | AC | 57 ms
50,432 KB |
testcase_02 | AC | 60 ms
50,436 KB |
testcase_03 | AC | 59 ms
50,288 KB |
testcase_04 | AC | 57 ms
50,248 KB |
testcase_05 | AC | 62 ms
50,232 KB |
testcase_06 | AC | 61 ms
50,040 KB |
testcase_07 | AC | 139 ms
55,660 KB |
testcase_08 | AC | 132 ms
55,468 KB |
testcase_09 | AC | 62 ms
49,936 KB |
testcase_10 | AC | 181 ms
56,440 KB |
testcase_11 | AC | 66 ms
50,640 KB |
testcase_12 | AC | 166 ms
56,452 KB |
testcase_13 | AC | 193 ms
56,536 KB |
testcase_14 | AC | 171 ms
56,568 KB |
testcase_15 | AC | 167 ms
56,380 KB |
testcase_16 | AC | 180 ms
56,560 KB |
testcase_17 | AC | 169 ms
56,320 KB |
testcase_18 | AC | 114 ms
51,792 KB |
testcase_19 | AC | 130 ms
55,540 KB |
testcase_20 | AC | 171 ms
56,728 KB |
testcase_21 | AC | 171 ms
56,400 KB |
testcase_22 | AC | 179 ms
56,452 KB |
testcase_23 | AC | 107 ms
51,860 KB |
testcase_24 | AC | 98 ms
51,916 KB |
testcase_25 | AC | 179 ms
56,180 KB |
testcase_26 | AC | 139 ms
55,940 KB |
testcase_27 | AC | 70 ms
51,068 KB |
testcase_28 | AC | 172 ms
56,612 KB |
testcase_29 | AC | 139 ms
55,656 KB |
testcase_30 | AC | 60 ms
50,492 KB |
testcase_31 | AC | 146 ms
56,196 KB |
testcase_32 | AC | 170 ms
56,564 KB |
testcase_33 | AC | 193 ms
56,544 KB |
testcase_34 | AC | 77 ms
50,496 KB |
testcase_35 | AC | 155 ms
56,428 KB |
testcase_36 | AC | 108 ms
51,548 KB |
testcase_37 | AC | 205 ms
56,288 KB |
testcase_38 | AC | 173 ms
56,496 KB |
testcase_39 | AC | 155 ms
56,328 KB |
testcase_40 | AC | 142 ms
55,692 KB |
testcase_41 | AC | 155 ms
56,608 KB |
testcase_42 | AC | 89 ms
51,424 KB |
testcase_43 | AC | 111 ms
52,052 KB |
testcase_44 | AC | 197 ms
57,124 KB |
testcase_45 | AC | 137 ms
55,676 KB |
testcase_46 | AC | 176 ms
56,484 KB |
testcase_47 | AC | 119 ms
52,168 KB |
testcase_48 | AC | 155 ms
56,432 KB |
testcase_49 | AC | 159 ms
56,736 KB |
testcase_50 | AC | 81 ms
50,888 KB |
testcase_51 | AC | 103 ms
51,416 KB |
testcase_52 | AC | 198 ms
56,512 KB |
testcase_53 | AC | 167 ms
56,140 KB |
testcase_54 | AC | 180 ms
56,592 KB |
testcase_55 | AC | 197 ms
56,288 KB |
testcase_56 | AC | 206 ms
57,520 KB |
testcase_57 | AC | 61 ms
50,472 KB |
testcase_58 | AC | 143 ms
55,672 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; 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]; List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n + 2; i++) { graph.add(new ArrayList<>()); } List<Set<Integer>> nextTo = new ArrayList<>(); for (int i = 0; i < n + 2; i++) { values[i] = sc.nextInt(); nextTo.add(new HashSet<>()); for (int j = 0; j <= 30; j++) { nextTo.get(i).add(values[i] ^ (1 << j)); } for (int j = 0; j < i; j++) { if (nextTo.get(j).contains(values[i])) { graph.get(i).add(j); graph.get(j).add(i); } } } Deque<Path> deq = new ArrayDeque<>(); int[] costs = new int[n + 2]; Arrays.fill(costs, Integer.MAX_VALUE); deq.add(new Path(0, 0)); while (deq.size() > 0) { Path p = deq.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx)) { deq.add(new Path(x, p.value + 1)); } } System.out.println(costs[1] == Integer.MAX_VALUE ? -1 : costs[1] - 1); } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }