結果

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

ソースコード

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
G = [[] for _ in range(N + 2)]
for i in range(N+1):
    for j in range(i + 1,N + 2):
        if hamu(l[i],l[j]):
            G[i].append(j)
            G[j].append(i)
    
from collections import deque
q = deque()
q.append(0)
while len(q):
    now = q.popleft()
    for v in G[now]:
        if memo[v] == C:
            memo[v] = memo[now] + 1
            q.append(v)
if memo[-1] == C:
    print(-1)
else:
    print(memo[-1]-1)
0