結果

問題 No.1577 織姫と彦星2
ユーザー boeboeMartinboeboeMartin
提出日時 2021-07-20 19:23:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 933 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 91,984 KB
最終ジャッジ日時 2024-07-17 13:47:06
合計ジャッジ時間 5,343 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 2 TLE * 1 -- * 50
権限があれば一括ダウンロードができます

ソースコード

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