結果
問題 | No.1576 織姫と彦星 |
ユーザー | McGregorsh |
提出日時 | 2022-07-21 19:27:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,100 ms / 2,000 ms |
コード長 | 3,173 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 82,424 KB |
実行使用メモリ | 90,756 KB |
最終ジャッジ日時 | 2024-07-03 02:43:19 |
合計ジャッジ時間 | 29,061 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 153 ms
89,380 KB |
testcase_01 | AC | 172 ms
89,256 KB |
testcase_02 | AC | 150 ms
89,112 KB |
testcase_03 | AC | 151 ms
88,984 KB |
testcase_04 | AC | 145 ms
89,252 KB |
testcase_05 | AC | 154 ms
89,780 KB |
testcase_06 | AC | 161 ms
89,840 KB |
testcase_07 | AC | 351 ms
90,068 KB |
testcase_08 | AC | 303 ms
90,080 KB |
testcase_09 | AC | 165 ms
89,944 KB |
testcase_10 | AC | 714 ms
90,132 KB |
testcase_11 | AC | 164 ms
89,916 KB |
testcase_12 | AC | 508 ms
90,264 KB |
testcase_13 | AC | 847 ms
90,232 KB |
testcase_14 | AC | 616 ms
90,264 KB |
testcase_15 | AC | 610 ms
90,228 KB |
testcase_16 | AC | 765 ms
90,156 KB |
testcase_17 | AC | 598 ms
90,196 KB |
testcase_18 | AC | 238 ms
90,008 KB |
testcase_19 | AC | 297 ms
90,360 KB |
testcase_20 | AC | 601 ms
90,436 KB |
testcase_21 | AC | 652 ms
90,232 KB |
testcase_22 | AC | 678 ms
90,376 KB |
testcase_23 | AC | 227 ms
90,140 KB |
testcase_24 | AC | 223 ms
90,320 KB |
testcase_25 | AC | 876 ms
89,984 KB |
testcase_26 | AC | 336 ms
90,212 KB |
testcase_27 | AC | 169 ms
90,160 KB |
testcase_28 | AC | 690 ms
90,148 KB |
testcase_29 | AC | 335 ms
90,108 KB |
testcase_30 | AC | 157 ms
89,892 KB |
testcase_31 | AC | 351 ms
90,264 KB |
testcase_32 | AC | 574 ms
90,108 KB |
testcase_33 | AC | 1,100 ms
90,316 KB |
testcase_34 | AC | 167 ms
89,996 KB |
testcase_35 | AC | 407 ms
89,944 KB |
testcase_36 | AC | 202 ms
90,364 KB |
testcase_37 | AC | 1,007 ms
90,544 KB |
testcase_38 | AC | 699 ms
90,356 KB |
testcase_39 | AC | 466 ms
90,324 KB |
testcase_40 | AC | 372 ms
90,416 KB |
testcase_41 | AC | 426 ms
90,128 KB |
testcase_42 | AC | 174 ms
89,920 KB |
testcase_43 | AC | 253 ms
90,364 KB |
testcase_44 | AC | 911 ms
90,152 KB |
testcase_45 | AC | 367 ms
90,216 KB |
testcase_46 | AC | 650 ms
90,556 KB |
testcase_47 | AC | 245 ms
90,400 KB |
testcase_48 | AC | 491 ms
90,232 KB |
testcase_49 | AC | 418 ms
90,408 KB |
testcase_50 | AC | 167 ms
89,824 KB |
testcase_51 | AC | 210 ms
90,012 KB |
testcase_52 | AC | 916 ms
90,444 KB |
testcase_53 | AC | 588 ms
90,756 KB |
testcase_54 | AC | 738 ms
90,084 KB |
testcase_55 | AC | 1,065 ms
90,372 KB |
testcase_56 | AC | 989 ms
90,268 KB |
testcase_57 | AC | 159 ms
90,012 KB |
testcase_58 | AC | 316 ms
90,112 KB |
ソースコード
import sys, re from fractions import Fraction from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement, permutations from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def lcm(a, b): return a * b // gcd(a, b) def get_distance(x1, y1, x2, y2): d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) return d def rotate(table): n_fild = [] for x in zip(*table[::-1]): n_fild.append(x) return n_fild sys.setrecursionlimit(10 ** 7) INF = float('inf') MOD = 10 ** 9 + 7 MOD2 = 998244353 ###関数コピーしたか?### def main(): n = int(input()) start, end = i_map() stone = i_list() nums = [set() for i in range(n+2)] for i in range(n): bit_i = format(stone[i], 'b') bit_i_zero = bit_i.zfill(50) for j in range(n): if i == j: continue bit_j = format(stone[j], 'b') bit_j_zero = bit_j.zfill(50) cou = 0 for k in range(50): if bit_i_zero[k] != bit_j_zero[k]: cou += 1 if cou == 2: break if cou == 1: nums[i+1].add(j+1) nums[j+1].add(i+1) start_bit = format(start, 'b') end_bit = format(end, 'b') start_bit_zero = start_bit.zfill(50) end_bit_zero = end_bit.zfill(50) nn = 0 for i in range(50): if start_bit_zero[i] != end_bit_zero[i]: nn += 1 if nn == 1: print(0) exit() for i in range(n): point_i = format(stone[i], 'b') point_i_zero = point_i.zfill(50) cou1 = 0 cou2 = 0 for j in range(50): if point_i_zero[j] != start_bit_zero[j]: cou1 += 1 if point_i_zero[j] != end_bit_zero[j]: cou2 += 1 if cou1 == 1: nums[0].add(i+1) nums[i+1].add(0) if cou2 == 1: nums[n+1].add(i+1) nums[i+1].add(n+1) greets = [] for i in range(n+2): lines = list(nums[i]) greets.append(lines) que = deque() que.append(0) dist = [INF] * (n+2) dist[0] = 0 while que: point = que.popleft() for i in greets[point]: if dist[i] == INF: dist[i] = dist[point] + 1 que.append(i) #print(greets) #print(dist) if dist[-1] == INF: print(-1) else: print(dist[-1]-1) if __name__ == '__main__': main()