結果
| 問題 |
No.1576 織姫と彦星
|
| ユーザー |
|
| 提出日時 | 2021-07-02 08:25:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 337 ms / 2,000 ms |
| コード長 | 521 bytes |
| コンパイル時間 | 587 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 76,288 KB |
| 最終ジャッジ日時 | 2024-06-28 18:54:33 |
| 合計ジャッジ時間 | 10,594 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 54 |
ソースコード
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)