結果
| 問題 |
No.1576 織姫と彦星
|
| ユーザー |
👑 Kazun
|
| 提出日時 | 2021-06-29 17:38:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 536 ms / 2,000 ms |
| コード長 | 479 bytes |
| コンパイル時間 | 201 ms |
| コンパイル使用メモリ | 82,816 KB |
| 実行使用メモリ | 76,720 KB |
| 最終ジャッジ日時 | 2024-06-25 19:48:31 |
| 合計ジャッジ時間 | 10,451 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 54 |
ソースコード
def popcount(x):
return bin(x).count("1")
def Hamming(x,y):
return popcount(x^y)
#==================================================
from collections import deque
N=int(input())
S,G=map(int,input().split())
A=list(map(int,input().split()))
V=[S,G]+A
Q=deque([0])
X=[-1]*(N+2); X[0]=0
while Q:
x=Q.popleft()
for y in range(N+2):
if Hamming(V[x],V[y])==1 and X[y]==-1:
X[y]=X[x]+1
Q.append(y)
print(X[1]-1 if X[1]!=-1 else -1)
Kazun