結果

問題 No.3 ビットすごろく
ユーザー Akijin_007Akijin_007
提出日時 2022-11-04 14:04:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 547 bytes
コンパイル時間 1,246 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 80,880 KB
最終ジャッジ日時 2023-09-25 17:21:46
合計ジャッジ時間 6,125 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,652 KB
testcase_01 AC 93 ms
71,644 KB
testcase_02 AC 95 ms
71,756 KB
testcase_03 AC 114 ms
77,568 KB
testcase_04 AC 103 ms
76,552 KB
testcase_05 AC 114 ms
78,160 KB
testcase_06 AC 113 ms
78,280 KB
testcase_07 AC 111 ms
77,808 KB
testcase_08 AC 114 ms
78,232 KB
testcase_09 AC 117 ms
78,928 KB
testcase_10 AC 118 ms
79,032 KB
testcase_11 AC 114 ms
78,304 KB
testcase_12 AC 114 ms
78,316 KB
testcase_13 AC 112 ms
77,572 KB
testcase_14 AC 117 ms
78,896 KB
testcase_15 AC 123 ms
80,856 KB
testcase_16 AC 119 ms
79,036 KB
testcase_17 AC 120 ms
80,712 KB
testcase_18 AC 113 ms
77,748 KB
testcase_19 AC 122 ms
80,844 KB
testcase_20 AC 96 ms
71,912 KB
testcase_21 AC 95 ms
71,564 KB
testcase_22 AC 119 ms
78,920 KB
testcase_23 AC 122 ms
80,796 KB
testcase_24 AC 120 ms
80,764 KB
testcase_25 AC 122 ms
80,880 KB
testcase_26 AC 96 ms
71,588 KB
testcase_27 AC 115 ms
77,868 KB
testcase_28 AC 120 ms
78,816 KB
testcase_29 AC 116 ms
78,240 KB
testcase_30 AC 94 ms
71,532 KB
testcase_31 AC 95 ms
71,600 KB
testcase_32 AC 116 ms
78,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

N = int(input())

def popcnt(n):
    return bin(n).count("1")

to = [[] for i in range(N+1)]
if N > 1:
    to[1] = [2]
for i in range(2, N+1):
    p = popcnt(i)
    if i + p <= N:
        to[i] = [i+p, i-p]
    else:
        to[i] = [i-p]

q = [1]

v = [-1] * (N+1)
v[1] = 1

from collections import deque
q = deque(q)

while q:
    t = q.popleft()
    for x in to[t]:
        if v[x] != -1:
            continue
        v[x] = v[t] + 1
        q.append(x)

print(v[N])


0