結果

問題 No.1576 織姫と彦星
ユーザー persimmon-persimmon
提出日時 2021-07-02 08:25:53
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 521 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 392 ms
コンパイル使用メモリ 85,232 KB
実行使用メモリ 81,304 KB
最終ジャッジ日時 2026-03-17 20:02:07
合計ジャッジ時間 7,011 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n=int(input())
s,e=map(int,input().split())
a=list(map(int,input().split()))
a.append(s)
a.append(e)
g=[[] for _ in range(n+2)]
for i in range(n+1):
  for j in range(i+1,n+2):
    x=a[i]^a[j]
    cnt=bin(x).count('1')
    if cnt<=1:
      g[i].append(j)
      g[j].append(i)
from collections import deque
todo=deque([n])
seen=[-1]*(n+2)
seen[n]=0
while todo:
  v=todo.popleft()
  for nv in g[v]:
    if seen[nv]==-1:
      seen[nv]=seen[v]+1
      todo.append(nv)
if seen[n+1]==-1:
  print(-1)
else:
  print(seen[n+1]-1)
0