結果

問題 No.1576 織姫と彦星
ユーザー sugar_sentan
提出日時 2021-06-20 16:24:04
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 557 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 235 ms
コンパイル使用メモリ 85,164 KB
実行使用メモリ 137,552 KB
最終ジャッジ日時 2026-03-07 06:09:16
合計ジャッジ時間 153,076 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 4 TLE * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def checkhamming(n, m):
    return bin(n ^ m).count('1')


N = int(input())
start, end = map(int, input().split())
stones = list(map(int, input().split()))
stones.append(end)

q = [[start, 0]]

while len(q):
    # print(q)
    now, count = q.pop(0)
    if count > len(stones)+1:
        break
    # print(now, count)
    for stone in stones:
        if checkhamming(now, stone) <= 1 and now != stone:
            if stone == end:
                print(count)
                exit()
            else:
                q.append([stone, count+1])
    
print(-1)
0