結果

問題 No.3 ビットすごろく
ユーザー kagamikagami
提出日時 2019-07-14 18:35:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-05-03 12:50:38
合計ジャッジ時間 2,879 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,752 KB
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 25 ms
10,752 KB
testcase_03 AC 34 ms
10,880 KB
testcase_04 AC 26 ms
10,752 KB
testcase_05 AC 67 ms
11,008 KB
testcase_06 AC 38 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 64 ms
11,008 KB
testcase_13 AC 33 ms
10,624 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 32 ms
10,752 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 25 ms
10,752 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 26 ms
10,624 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 25 ms
10,752 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