結果

問題 No.3 ビットすごろく
ユーザー kagami
提出日時 2019-07-14 18:44:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 597 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-11-24 12:56:48
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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] = 1
        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, ans + 1)
        if 0 < now - count  and visited[now - count] == -1:
                return bfs(visited, now - count, ans + 1)
        return -1

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