結果

問題 No.3 ビットすごろく
ユーザー rlangevinrlangevin
提出日時 2023-01-08 01:46:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 450 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 78,060 KB
最終ジャッジ日時 2023-08-21 14:46:16
合計ジャッジ時間 5,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
71,772 KB
testcase_01 AC 87 ms
71,688 KB
testcase_02 AC 92 ms
71,772 KB
testcase_03 AC 108 ms
77,844 KB
testcase_04 AC 98 ms
77,644 KB
testcase_05 AC 104 ms
77,876 KB
testcase_06 AC 105 ms
77,884 KB
testcase_07 AC 104 ms
77,892 KB
testcase_08 AC 105 ms
77,840 KB
testcase_09 AC 102 ms
77,940 KB
testcase_10 AC 101 ms
77,896 KB
testcase_11 AC 101 ms
77,824 KB
testcase_12 AC 101 ms
77,884 KB
testcase_13 AC 103 ms
77,788 KB
testcase_14 AC 100 ms
77,928 KB
testcase_15 AC 99 ms
77,956 KB
testcase_16 AC 100 ms
77,856 KB
testcase_17 AC 101 ms
77,892 KB
testcase_18 AC 102 ms
77,792 KB
testcase_19 AC 101 ms
78,060 KB
testcase_20 AC 92 ms
76,320 KB
testcase_21 AC 87 ms
71,728 KB
testcase_22 AC 101 ms
77,944 KB
testcase_23 AC 103 ms
77,892 KB
testcase_24 AC 102 ms
78,052 KB
testcase_25 AC 103 ms
77,964 KB
testcase_26 AC 86 ms
71,440 KB
testcase_27 AC 102 ms
77,808 KB
testcase_28 AC 102 ms
77,976 KB
testcase_29 AC 104 ms
77,856 KB
testcase_30 AC 89 ms
71,556 KB
testcase_31 AC 88 ms
71,556 KB
testcase_32 AC 103 ms
77,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

def popcount(n):
    cnt = 0
    while n:
        cnt += n & 1
        n //= 2
    return cnt

N = int(input())
dist = [-1] * (N + 1)
dist[1] = 1
Q = deque([1])
while Q:
    n = Q.popleft()
    d = popcount(n)
    for i in range(-1, 2, 2):
        if 1 <= n - i * d <= N:
            if dist[n - i * d] != -1:
                continue
            dist[n - i * d] = dist[n] + 1
            Q.append(n - i * d)
print(dist[N])
0