結果

問題 No.3 ビットすごろく
ユーザー kagami
提出日時 2019-07-14 18:59:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 617 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-11-24 13:08:13
合計ジャッジ時間 2,053 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(100000)

N = int(input())

visited = [-1] * N
def bfs(visited, now, ans):
        if now == (N - 1):
                return ans
        visited[now] = ans
        tmp = bin(now + 1)
        count = 0
        for i in tmp:
                if i == '1':
                        count += 1
        if now + count < N and visited[now + count] == -1:
                return bfs(visited, now + count, visited[now] + 1)
        if 0 < now - count  and visited[now - count] == -1:
                return bfs(visited, now - count, visited[now] + 1)
        return -1

print(bfs(visited, 0, 1))
0