結果

問題 No.1576 織姫と彦星
ユーザー y05h1k1ng
提出日時 2021-07-01 10:53:46
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 543 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 281 ms
コンパイル使用メモリ 21,284 KB
実行使用メモリ 16,380 KB
最終ジャッジ日時 2026-07-31 12:36:07
合計ジャッジ時間 5,438 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 2 TLE * 1 -- * 51
権限があれば一括ダウンロードができます

ソースコード

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