結果

問題 No.3 ビットすごろく
ユーザー satorysatory
提出日時 2017-04-16 11:32:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,903 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 10,840 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-09-26 08:58:45
合計ジャッジ時間 7,085 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# coding: utf-8

def count_1(n):
    count = 0

    flg = True
    while (flg):
        mod = n % 2

        if mod==0: pass
        if mod==1: count += 1

        if (mod==n):
            flg = False

        n = int(n / 2)

    return count

# Run the main function if called from the command line
if __name__ == "__main__":
    # 標準入力から一行分を読み出し、文字列として格納する。
    first = input()
    # 読み込んだ文字列をスペースで分割する
    #split_first = first.split()

    # それぞれをint型に変換する
    N = int(first)

    # 慣れてくると この一行でよい
    # A, B = map(int, input().split())

    # 参考: リストを読む際はlist()で覆ってやらないといけない
    # L = list(map(int, input().split()))

    #2行目を読み込む
    #S = input()

    # 標準出力に書き出す。
    # カンマで区切るとスペースで分割してくれるので楽です。
    #print(A + B, S)

    target_list = [N]
    cand_list = []
    count = 1

    flg = True
    while(flg):
        count += 1
        for target in target_list:
            for i in range(1, 14):

                t_pi = target + i
                if target+i <= N:
                    if (t_pi - count_1(t_pi) == target):
                        cand_list.append(t_pi)

                t_mi = target - i
                if t_mi >= 1:
                    if (t_mi + count_1(t_mi) == target):
                        cand_list.append(t_mi)

        # 終了判定
        if N==1:
            count = 1
            flg = False
        elif len(cand_list)==0:
            count = -1
            flg = False
        else:
            for i in cand_list:
                if i==1:
                    flg = False
                else:
                    pass

        target_list = cand_list
        cand_list = []

    print (count)
0