結果

問題 No.3 ビットすごろく
ユーザー convexineqconvexineq
提出日時 2020-11-22 06:24:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 359 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 86,796 KB
実行使用メモリ 77,764 KB
最終ジャッジ日時 2023-09-14 01:54:39
合計ジャッジ時間 5,505 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,308 KB
testcase_01 AC 94 ms
71,328 KB
testcase_02 AC 94 ms
71,632 KB
testcase_03 AC 125 ms
77,636 KB
testcase_04 AC 104 ms
77,132 KB
testcase_05 AC 106 ms
77,460 KB
testcase_06 AC 108 ms
77,392 KB
testcase_07 AC 109 ms
77,248 KB
testcase_08 AC 106 ms
77,368 KB
testcase_09 AC 107 ms
77,400 KB
testcase_10 AC 105 ms
77,316 KB
testcase_11 AC 106 ms
77,372 KB
testcase_12 AC 105 ms
77,688 KB
testcase_13 AC 105 ms
77,764 KB
testcase_14 AC 106 ms
77,692 KB
testcase_15 AC 105 ms
77,416 KB
testcase_16 AC 107 ms
77,636 KB
testcase_17 AC 107 ms
77,528 KB
testcase_18 AC 106 ms
77,384 KB
testcase_19 AC 108 ms
77,388 KB
testcase_20 AC 101 ms
76,232 KB
testcase_21 AC 95 ms
71,500 KB
testcase_22 AC 109 ms
77,308 KB
testcase_23 AC 109 ms
77,432 KB
testcase_24 AC 106 ms
77,592 KB
testcase_25 AC 108 ms
77,696 KB
testcase_26 AC 93 ms
71,332 KB
testcase_27 AC 107 ms
77,360 KB
testcase_28 AC 107 ms
77,396 KB
testcase_29 AC 106 ms
77,580 KB
testcase_30 AC 94 ms
71,544 KB
testcase_31 AC 96 ms
71,660 KB
testcase_32 AC 110 ms
77,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(x):
    r = 0
    while x:
        r += x%2
        x //= 2
    return r

n = int(input())
dp = [-1]*(n+1)
dp[1] = 1
from collections import deque
q = deque()
q.append(1)
while q:
    v = q.popleft()
    c = popcount(v)
    for i in [v-c,v+c]:
        if 0 < i <= n and dp[i]==-1:
            dp[i] = dp[v]+1
            q.append(i)

print(dp[n])
0