結果

問題 No.3 ビットすごろく
ユーザー Akijin_007Akijin_007
提出日時 2022-11-04 14:03:01
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 533 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 81,012 KB
最終ジャッジ日時 2023-09-25 17:19:04
合計ジャッジ時間 5,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,796 KB
testcase_01 AC 95 ms
71,552 KB
testcase_02 AC 91 ms
71,540 KB
testcase_03 AC 107 ms
77,972 KB
testcase_04 AC 97 ms
76,644 KB
testcase_05 AC 108 ms
78,456 KB
testcase_06 AC 108 ms
77,936 KB
testcase_07 AC 108 ms
77,932 KB
testcase_08 AC 109 ms
78,380 KB
testcase_09 AC 113 ms
78,716 KB
testcase_10 AC 114 ms
78,984 KB
testcase_11 AC 111 ms
78,452 KB
testcase_12 AC 109 ms
78,472 KB
testcase_13 AC 108 ms
77,672 KB
testcase_14 AC 116 ms
78,984 KB
testcase_15 AC 117 ms
80,772 KB
testcase_16 AC 116 ms
79,044 KB
testcase_17 AC 118 ms
80,832 KB
testcase_18 AC 108 ms
77,568 KB
testcase_19 AC 119 ms
80,672 KB
testcase_20 AC 94 ms
71,564 KB
testcase_21 AC 92 ms
71,340 KB
testcase_22 AC 119 ms
79,136 KB
testcase_23 AC 118 ms
80,908 KB
testcase_24 AC 119 ms
81,012 KB
testcase_25 AC 120 ms
80,752 KB
testcase_26 RE -
testcase_27 AC 110 ms
77,828 KB
testcase_28 AC 117 ms
78,868 KB
testcase_29 AC 114 ms
78,252 KB
testcase_30 AC 94 ms
71,904 KB
testcase_31 AC 94 ms
71,772 KB
testcase_32 AC 114 ms
78,156 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)]
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