結果

問題 No.1576 織姫と彦星
ユーザー y05h1k1ng
提出日時 2021-07-01 10:53:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 543 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 18,464 KB
最終ジャッジ日時 2024-06-28 00:01:18
合計ジャッジ時間 4,336 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 2 TLE * 1 -- * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
start, end = map(int, input().split(" "))
stones = list(map(int, input().split(" ")))

def hamming_distance(a: int, b: int) -> int:
    x = a ^ b
    return bin(x)[2:].count("1")

que = deque([])

que.append((0, start))

while len(que):
    cnt, now = que.popleft()

    if hamming_distance(now, end) == 1:
        print(cnt)
        break

    for i in range(n):
        stone = stones[i]
        if hamming_distance(now, stone) == 1:
            que.append((cnt+1, stone))
else:
    print(-1)
0