結果

問題 No.3 ビットすごろく
ユーザー けむけむけむけむ
提出日時 2021-06-16 23:48:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 820 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 12,728 KB
最終ジャッジ日時 2023-08-30 05:13:27
合計ジャッジ時間 7,785 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,972 KB
testcase_01 AC 16 ms
7,928 KB
testcase_02 AC 16 ms
7,936 KB
testcase_03 TLE -
testcase_04 -- -
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 #

def sugoroku(N):
    if N == 1:
        return 0
    bit_1_list = []
    for i in range(1, N + 1):
        s = bin(i)
        bit_1 = s.count('1')
        bit_1_list.append(bit_1)
    loc_list = []
    loc = 0
    while len(loc_list) <= N:
        if (loc < 0) or (loc == N - 1):
            loc_list.append(loc)
            break
        if loc > N - 1:
            loc = loc_list[-1]
            loc = loc - bit_1_list[loc]
        if loc in loc_list:
            loc_list.pop(-1)
            loc = loc_list[-1]
            loc = loc - bit_1_list[loc]
        elif loc not in loc_list:
            loc_list.append(loc)
            loc = loc + bit_1_list[loc]
    if loc < 0:
        return -1
    elif loc == N - 1:
        return len(loc_list)

if __name__ == '__main__':
    N = int(input())
    print(sugoroku(N))

0