結果

問題 No.1576 織姫と彦星
ユーザー d1k0b3o
提出日時 2021-07-18 18:25:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 548 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-07-08 11:44:26
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 2 TLE * 1 -- * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import deque
def is_ham1(a,b):
    if math.log2(a^b).is_integer():
        return True
    else:
        return False

n = int(input())
s,g = map(int,input().split())
ishi = deque(map(int,input().split()))
ishi.appendleft(g)
q=deque()

q.append([s,0])
S=set()
S.add(s)
while q:
    a = q.popleft()
    
    for b in ishi:
        if a[0]==b: continue
        if not is_ham1(a[0],b): continue
        if b in S: continue
        if b==g:
            print(a[1])
            exit()
        q.append([b,a[1]+1])

print(-1)
0