結果

問題 No.3 ビットすごろく
ユーザー ktny
提出日時 2016-07-19 00:22:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 742 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-15 17:08:10
合計ジャッジ時間 2,569 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 21 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
array = []
for i in range(1, N):
    array.append(str(bin(i))[2:].count("1"))

count = 0
queue = [0]

while(True):
    count += 1
    n = array[queue[0]] # 現在の位置のビット数をnに代入
    array[queue[0]] = 0 # 訪問履歴を0で表現する。すでに訪問した位置のビット数は0
    a = queue[0] + n # 現在の位置+現在の位置のビット数をaに代入
    b = queue[0] - n # 現在の位置-現在の位置のビット数をbに代入
    queue.pop(0)
    if(a == N - 1):
        break
    if(0 < a < N - 1 and array[a] != 0):
        queue.append(a)
    if(0 < b < N - 1 and array[b] != 0):
        queue.append(b)
    if(len(queue) == 0):
        count = -1
        break

print(count)
0