結果

問題 No.3 ビットすごろく
ユーザー ebicochinealebicochineal
提出日時 2016-06-01 23:21:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 856 ms / 5,000 ms
コード長 402 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 8,368 KB
最終ジャッジ日時 2023-09-13 23:59:35
合計ジャッジ時間 12,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,744 KB
testcase_01 AC 16 ms
7,936 KB
testcase_02 AC 16 ms
7,772 KB
testcase_03 AC 70 ms
7,812 KB
testcase_04 AC 22 ms
7,820 KB
testcase_05 AC 262 ms
8,192 KB
testcase_06 AC 81 ms
7,752 KB
testcase_07 AC 39 ms
7,832 KB
testcase_08 AC 172 ms
8,212 KB
testcase_09 AC 416 ms
8,276 KB
testcase_10 AC 593 ms
8,220 KB
testcase_11 AC 355 ms
8,324 KB
testcase_12 AC 247 ms
8,232 KB
testcase_13 AC 55 ms
7,748 KB
testcase_14 AC 552 ms
8,368 KB
testcase_15 AC 842 ms
8,276 KB
testcase_16 AC 729 ms
8,232 KB
testcase_17 AC 810 ms
8,192 KB
testcase_18 AC 45 ms
7,780 KB
testcase_19 AC 854 ms
8,224 KB
testcase_20 AC 19 ms
7,800 KB
testcase_21 AC 16 ms
7,740 KB
testcase_22 AC 566 ms
8,164 KB
testcase_23 AC 853 ms
8,200 KB
testcase_24 AC 856 ms
8,324 KB
testcase_25 AC 832 ms
8,220 KB
testcase_26 AC 16 ms
7,796 KB
testcase_27 AC 62 ms
7,752 KB
testcase_28 AC 700 ms
8,156 KB
testcase_29 AC 367 ms
8,196 KB
testcase_30 AC 16 ms
7,804 KB
testcase_31 AC 16 ms
7,936 KB
testcase_32 AC 317 ms
8,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
f = lambda x : sum(1 for y in str(bin(x)) if y == '1')
ans = 100001
q = [1]
c = 1
r = []
while c < ans and len(q) > 0:
    a = []
    for i in q:
        if i == N:
            ans = c
        elif (not i in r):
            r += [i]
            n, m = i+f(i), i-f(i)
            if n <= N : a += [n]
            if m > 0 : a += [m]
    q = a
    c += 1
print(ans if ans<100001 else -1)
0