結果

問題 No.3 ビットすごろく
ユーザー syuki791syuki791
提出日時 2019-02-02 16:56:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 442 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 10,744 KB
実行使用メモリ 75,048 KB
最終ジャッジ日時 2023-08-18 15:47:39
合計ジャッジ時間 8,087 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,824 KB
testcase_01 AC 14 ms
7,836 KB
testcase_02 AC 15 ms
7,972 KB
testcase_03 AC 15 ms
7,840 KB
testcase_04 AC 15 ms
7,816 KB
testcase_05 AC 16 ms
7,920 KB
testcase_06 AC 16 ms
7,856 KB
testcase_07 AC 15 ms
7,752 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 16 ms
7,976 KB
testcase_13 AC 17 ms
7,836 KB
testcase_14 AC 16 ms
7,868 KB
testcase_15 AC 17 ms
8,004 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 15 ms
7,972 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 15 ms
7,828 KB
testcase_22 AC 16 ms
7,776 KB
testcase_23 AC 17 ms
7,824 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #



def countbinary(x):
    x2 = bin(x)
    return str(x2).count('1')


n = int(input())
list = []
a = 1
while True:
    num = int(countbinary(a))
    if a + num > n:
        if (a-num in list) and (a-num>0):
            print('-1')
            break
        else:
            list.append(a-num)
            a = a-num
    else:
        list.append(a+num)
        a = a + num
        if a == n:
            print(len(list)+1)
            break
0