結果
問題 | No.1577 織姫と彦星2 |
ユーザー | tenten |
提出日時 | 2023-04-25 18:15:50 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,023 bytes |
コンパイル時間 | 2,919 ms |
コンパイル使用メモリ | 93,712 KB |
実行使用メモリ | 423,440 KB |
最終ジャッジ日時 | 2024-11-14 14:19:35 |
合計ジャッジ時間 | 82,472 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
57,392 KB |
testcase_01 | AC | 54 ms
387,044 KB |
testcase_02 | AC | 55 ms
57,324 KB |
testcase_03 | AC | 56 ms
381,720 KB |
testcase_04 | AC | 56 ms
56,956 KB |
testcase_05 | AC | 909 ms
126,728 KB |
testcase_06 | AC | 327 ms
78,888 KB |
testcase_07 | TLE | - |
testcase_08 | AC | 990 ms
138,036 KB |
testcase_09 | TLE | - |
testcase_10 | AC | 1,131 ms
169,148 KB |
testcase_11 | AC | 233 ms
62,964 KB |
testcase_12 | AC | 1,863 ms
201,024 KB |
testcase_13 | AC | 879 ms
126,688 KB |
testcase_14 | AC | 1,816 ms
209,092 KB |
testcase_15 | AC | 642 ms
115,212 KB |
testcase_16 | TLE | - |
testcase_17 | AC | 1,321 ms
171,900 KB |
testcase_18 | AC | 88 ms
51,632 KB |
testcase_19 | AC | 1,891 ms
211,160 KB |
testcase_20 | AC | 1,871 ms
197,132 KB |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | AC | 1,012 ms
126,380 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 654 ms
115,352 KB |
testcase_26 | AC | 962 ms
130,772 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 1,817 ms
199,100 KB |
testcase_29 | AC | 1,103 ms
171,332 KB |
testcase_30 | AC | 1,702 ms
201,368 KB |
testcase_31 | TLE | - |
testcase_32 | AC | 156 ms
57,164 KB |
testcase_33 | AC | 124 ms
54,760 KB |
testcase_34 | AC | 1,134 ms
170,620 KB |
testcase_35 | AC | 1,816 ms
221,492 KB |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | AC | 1,045 ms
135,884 KB |
testcase_40 | AC | 1,137 ms
171,580 KB |
testcase_41 | TLE | - |
testcase_42 | AC | 1,707 ms
203,332 KB |
testcase_43 | AC | 1,706 ms
205,580 KB |
testcase_44 | AC | 162 ms
59,504 KB |
testcase_45 | AC | 548 ms
95,424 KB |
testcase_46 | AC | 597 ms
115,604 KB |
testcase_47 | TLE | - |
testcase_48 | AC | 1,091 ms
171,324 KB |
testcase_49 | AC | 1,178 ms
171,528 KB |
testcase_50 | AC | 959 ms
126,256 KB |
testcase_51 | AC | 340 ms
79,040 KB |
testcase_52 | TLE | - |
testcase_53 | TLE | - |
testcase_54 | AC | 1,679 ms
201,396 KB |
testcase_55 | TLE | - |
testcase_56 | AC | 694 ms
115,188 KB |
testcase_57 | AC | 515 ms
423,440 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]; HashMap<Integer, ArrayList<Integer>> hamings = new HashMap<>(); for (int i = 0; i < n + 2; i++) { values[i] = sc.nextInt(); for (int j = 0; j < 30; j++) { values[i] ^= (1 << j); if (!hamings.containsKey(values[i])) { hamings.put(values[i], new ArrayList<>()); } hamings.get(values[i]).add(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; if (hamings.containsKey(values[p.idx])) { for (int x : hamings.get(values[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(); } }