結果

問題 No.1576 織姫と彦星
ユーザー boeboeMartinboeboeMartin
提出日時 2021-07-20 19:21:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,267 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 79,760 KB
最終ジャッジ日時 2023-09-24 12:53:49
合計ジャッジ時間 24,827 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
71,400 KB
testcase_01 AC 86 ms
71,560 KB
testcase_02 AC 88 ms
71,704 KB
testcase_03 AC 87 ms
71,664 KB
testcase_04 AC 83 ms
71,700 KB
testcase_05 AC 82 ms
71,768 KB
testcase_06 AC 90 ms
76,808 KB
testcase_07 AC 253 ms
78,400 KB
testcase_08 AC 163 ms
78,412 KB
testcase_09 AC 118 ms
77,884 KB
testcase_10 AC 750 ms
78,780 KB
testcase_11 AC 117 ms
77,888 KB
testcase_12 AC 487 ms
78,860 KB
testcase_13 AC 504 ms
78,580 KB
testcase_14 AC 688 ms
78,756 KB
testcase_15 AC 635 ms
79,560 KB
testcase_16 AC 403 ms
78,484 KB
testcase_17 AC 602 ms
78,872 KB
testcase_18 AC 195 ms
78,396 KB
testcase_19 AC 318 ms
78,748 KB
testcase_20 AC 122 ms
78,116 KB
testcase_21 AC 626 ms
79,480 KB
testcase_22 AC 231 ms
78,532 KB
testcase_23 AC 136 ms
78,488 KB
testcase_24 AC 170 ms
78,044 KB
testcase_25 AC 541 ms
78,728 KB
testcase_26 AC 381 ms
78,532 KB
testcase_27 AC 121 ms
77,816 KB
testcase_28 AC 522 ms
79,564 KB
testcase_29 AC 361 ms
78,540 KB
testcase_30 AC 97 ms
76,676 KB
testcase_31 AC 344 ms
78,628 KB
testcase_32 AC 545 ms
78,836 KB
testcase_33 AC 1,187 ms
79,612 KB
testcase_34 AC 120 ms
77,488 KB
testcase_35 AC 445 ms
78,556 KB
testcase_36 AC 169 ms
78,472 KB
testcase_37 AC 1,267 ms
78,824 KB
testcase_38 AC 631 ms
78,740 KB
testcase_39 AC 488 ms
78,784 KB
testcase_40 AC 371 ms
79,760 KB
testcase_41 AC 429 ms
79,008 KB
testcase_42 AC 128 ms
78,176 KB
testcase_43 AC 193 ms
78,556 KB
testcase_44 AC 1,180 ms
78,752 KB
testcase_45 AC 296 ms
78,368 KB
testcase_46 AC 821 ms
78,972 KB
testcase_47 AC 132 ms
78,164 KB
testcase_48 AC 529 ms
78,756 KB
testcase_49 AC 478 ms
78,508 KB
testcase_50 AC 125 ms
77,816 KB
testcase_51 AC 133 ms
77,748 KB
testcase_52 AC 188 ms
78,328 KB
testcase_53 AC 778 ms
78,700 KB
testcase_54 AC 649 ms
78,708 KB
testcase_55 AC 640 ms
78,852 KB
testcase_56 AC 700 ms
78,776 KB
testcase_57 AC 116 ms
77,776 KB
testcase_58 AC 274 ms
78,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from collections import deque
# import time
# start_time = time.time()

def hmg_d(a, b):
    count = Counter(list(bin(a ^ b)))
    if count["1"] == 1:
        return True
    else:
        return False

n = int(input())
start, end = map(int,input().split())
stone = list(map(int,input().split()))

if hmg_d(start, end):
    print(0)
    exit()

stone_dict = {}
stone_dict[start] = 0
for i in stone:
    stone_dict[i] = 0

queue = deque()
queue.append(start)

while queue:
    v = queue.popleft()
    l = []
    for i in stone:
        if hmg_d(v, i):
            if stone_dict[i] == 0:
                stone_dict[i] = stone_dict[v] + 1
                queue.append(i)
            if hmg_d(i, end):
                print(stone_dict[i])
                # print(time.time() - start_time)
                exit()
            
            l.append(i)
    
    for i in l:
        stone.remove(i)


print(-1)
0