結果

問題 No.3 ビットすごろく
ユーザー kagamikagami
提出日時 2019-07-14 18:35:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 8,776 KB
最終ジャッジ日時 2023-08-16 03:16:09
合計ジャッジ時間 3,596 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,924 KB
testcase_01 AC 16 ms
7,868 KB
testcase_02 AC 16 ms
7,972 KB
testcase_03 AC 23 ms
8,372 KB
testcase_04 AC 16 ms
8,244 KB
testcase_05 AC 49 ms
8,344 KB
testcase_06 AC 24 ms
8,236 KB
testcase_07 AC 18 ms
8,136 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 48 ms
8,552 KB
testcase_13 AC 21 ms
8,332 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 19 ms
8,272 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 15 ms
7,920 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 15 ms
7,820 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 15 ms
7,820 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

visited = [0] * N
def bfs(visited, now, ans):
        if now == (N - 1):
                return ans
        if sum(visited) == N:
                return -1
        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] == 0:
                return bfs(visited, now + count, ans + 1)
        if 0 < now - count  and visited[now - count] == 0:
                return bfs(visited, now - count, ans + 1)
        return -1

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