結果

問題 No.3 ビットすごろく
ユーザー GrayCoderGrayCoder
提出日時 2018-06-28 20:16:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 735 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 8,808 KB
最終ジャッジ日時 2023-09-14 01:04:07
合計ジャッジ時間 2,000 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,456 KB
testcase_01 AC 18 ms
8,528 KB
testcase_02 AC 17 ms
8,460 KB
testcase_03 AC 20 ms
8,612 KB
testcase_04 AC 19 ms
8,472 KB
testcase_05 AC 24 ms
8,628 KB
testcase_06 AC 20 ms
8,604 KB
testcase_07 AC 18 ms
8,476 KB
testcase_08 AC 20 ms
8,620 KB
testcase_09 AC 23 ms
8,680 KB
testcase_10 AC 24 ms
8,720 KB
testcase_11 AC 22 ms
8,512 KB
testcase_12 AC 21 ms
8,592 KB
testcase_13 AC 19 ms
8,612 KB
testcase_14 AC 24 ms
8,664 KB
testcase_15 AC 28 ms
8,696 KB
testcase_16 AC 25 ms
8,756 KB
testcase_17 AC 25 ms
8,688 KB
testcase_18 AC 19 ms
8,564 KB
testcase_19 AC 25 ms
8,744 KB
testcase_20 AC 18 ms
8,524 KB
testcase_21 AC 17 ms
8,480 KB
testcase_22 AC 23 ms
8,716 KB
testcase_23 AC 25 ms
8,676 KB
testcase_24 AC 27 ms
8,680 KB
testcase_25 AC 27 ms
8,808 KB
testcase_26 AC 18 ms
8,464 KB
testcase_27 AC 20 ms
8,476 KB
testcase_28 AC 24 ms
8,780 KB
testcase_29 AC 22 ms
8,728 KB
testcase_30 AC 18 ms
8,564 KB
testcase_31 AC 18 ms
8,456 KB
testcase_32 AC 23 ms
8,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def bitCount(i):
    ret = 0
    while i:
        i &= i - 1
        ret += 1
    return ret

def main():
    N = int(input())

    flag = [None] * (N + 1)
    flag[1] = 1
    que = deque([(1, 1)])
    while que:
        cnt, n = que.popleft()
        bit = bitCount(n)
        a, b = n + bit, n - bit
        if a <= N or b >= 0:
            cnt += 1
        if a <= N and flag[a] is None:
            que.append((cnt, a))
            flag[a] = cnt
        if b > 0 and flag[b] is None:
            que.append((cnt, b))
            flag[b] = cnt

    print(-1) if flag[-1] is None else print(flag[-1])

main()
0