結果

問題 No.3 ビットすごろく
ユーザー keisukekeisuke
提出日時 2022-12-07 19:14:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 476 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 73,136 KB
最終ジャッジ日時 2024-04-22 01:25:55
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
54,172 KB
testcase_01 AC 38 ms
54,504 KB
testcase_02 AC 38 ms
54,404 KB
testcase_03 AC 57 ms
68,240 KB
testcase_04 AC 44 ms
63,512 KB
testcase_05 AC 50 ms
70,468 KB
testcase_06 AC 50 ms
68,032 KB
testcase_07 AC 48 ms
65,560 KB
testcase_08 AC 53 ms
68,980 KB
testcase_09 AC 51 ms
69,604 KB
testcase_10 AC 52 ms
71,192 KB
testcase_11 AC 51 ms
70,224 KB
testcase_12 AC 52 ms
69,332 KB
testcase_13 AC 48 ms
65,728 KB
testcase_14 AC 54 ms
71,268 KB
testcase_15 AC 54 ms
72,224 KB
testcase_16 AC 53 ms
71,772 KB
testcase_17 AC 60 ms
72,280 KB
testcase_18 AC 54 ms
65,524 KB
testcase_19 AC 54 ms
72,648 KB
testcase_20 AC 36 ms
54,900 KB
testcase_21 AC 36 ms
54,768 KB
testcase_22 AC 55 ms
70,648 KB
testcase_23 AC 57 ms
73,016 KB
testcase_24 AC 59 ms
73,136 KB
testcase_25 AC 61 ms
72,752 KB
testcase_26 AC 39 ms
53,712 KB
testcase_27 AC 54 ms
66,308 KB
testcase_28 AC 61 ms
72,464 KB
testcase_29 AC 58 ms
69,508 KB
testcase_30 AC 37 ms
54,636 KB
testcase_31 AC 36 ms
55,380 KB
testcase_32 AC 51 ms
70,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque, defaultdict

N = int(input())
bin_N = bin(N)[2:]


dist = defaultdict(lambda:-1)
dist[1] = 1
Q = deque()
Q.append(1)

while len(Q) > 0:
    x = Q.popleft()
    bin_x = bin(x)
    bin_count = bin_x.count('1')
    count_list = [x + bin_count,x - bin_count]
    for i in count_list:
        if (1<=i<=N):
            if dist[i]==-1:
                dist[i] = dist[x]+1
                Q.append(i)
        else:
            continue

print(dist[N])
0