結果

問題 No.1576 織姫と彦星
ユーザー y05h1k1ng
提出日時 2021-07-01 10:53:46
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 543 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 557 ms
コンパイル使用メモリ 20,632 KB
実行使用メモリ 39,900 KB
最終ジャッジ日時 2026-03-16 07:04:33
合計ジャッジ時間 155,930 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 4 TLE * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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