結果

問題 No.1576 織姫と彦星
ユーザー ああいい
提出日時 2021-12-23 19:13:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 622 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-17 17:43:04
合計ジャッジ時間 36,259 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 51 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
s,e = map(int,input().split())
l = list(map(int,input().split()))
l.insert(0,s)
l.append(e)
C = 10 ** 5
memo = [C] * (N + 2)
memo[0] = 0

def hamu(a,b):
    count = 0
    while a != 0 or b != 0:
        if a & 1 != b & 1:
            count += 1
        a >>= 1
        b >>= 1
    return count < 2
    
from collections import deque
q = deque()
q.append(0)
while len(q):
    now = q.popleft()
    for i in range(N+2):
        if memo[i] == C:
            if hamu(l[i],l[now]):
                memo[i] = memo[now] + 1
                q.append(i)
if memo[-1] == C:
    print(-1)
else:
    print(memo[-1]-1)
0