結果

問題 No.1576 織姫と彦星
ユーザー d1k0b3o
提出日時 2021-07-18 18:47:18
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 545 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 358 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 64,896 KB
最終ジャッジ日時 2026-05-26 14:58:27
合計ジャッジ時間 5,273 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 = [g]+ list(map(int,input().split()))
q=deque()

q.append([s,0])
S=set()
S.add(s)
while q:
    a = q.popleft()
    S.add(a[0]) 
    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