結果

問題 No.3 ビットすごろく
ユーザー zombietanzombietan
提出日時 2016-04-28 02:21:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 673 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 8,968 KB
最終ジャッジ日時 2023-08-14 14:45:25
合計ジャッジ時間 2,111 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,820 KB
testcase_01 AC 15 ms
7,956 KB
testcase_02 AC 15 ms
7,832 KB
testcase_03 AC 18 ms
8,288 KB
testcase_04 AC 16 ms
7,928 KB
testcase_05 AC 21 ms
8,300 KB
testcase_06 AC 18 ms
8,260 KB
testcase_07 AC 17 ms
7,888 KB
testcase_08 AC 19 ms
8,228 KB
testcase_09 AC 21 ms
8,784 KB
testcase_10 AC 23 ms
8,888 KB
testcase_11 AC 21 ms
8,356 KB
testcase_12 AC 20 ms
8,292 KB
testcase_13 AC 22 ms
8,224 KB
testcase_14 AC 23 ms
8,920 KB
testcase_15 AC 26 ms
8,800 KB
testcase_16 AC 25 ms
8,728 KB
testcase_17 AC 25 ms
8,840 KB
testcase_18 AC 17 ms
8,268 KB
testcase_19 AC 25 ms
8,888 KB
testcase_20 AC 16 ms
7,752 KB
testcase_21 AC 15 ms
7,824 KB
testcase_22 AC 23 ms
8,856 KB
testcase_23 AC 25 ms
8,836 KB
testcase_24 AC 24 ms
8,776 KB
testcase_25 AC 24 ms
8,772 KB
testcase_26 AC 15 ms
7,860 KB
testcase_27 AC 18 ms
8,220 KB
testcase_28 AC 24 ms
8,840 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 15 ms
7,836 KB
testcase_32 AC 21 ms
8,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

if N == 1:
    print(1)
else:
    count = 1
    num = 1
    trace = [1]
    result = {1}
    f = False
    while trace:
        n = []
        count += 1
        for num in trace:
            b1 = bin(num).count('1')
            if num + b1 == N:
                print(count)
                f = True
                break
            n1 = num + b1
            n2 = num - b1
            if n1 < N and n1 not in result:
                result.add(n1)
                n.append(n1)
            if n2 > 1 and n2 not in result:
                result.add(n2)
                n.append(n2)
        trace = n
    else:
        if f == False:
            print(-1)
0