結果

問題 No.3 ビットすごろく
ユーザー ゆめぷろ
提出日時 2021-04-01 18:45:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 1,110 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-12-17 23:19:19
合計ジャッジ時間 3,176 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 33
権限があれば一括ダウンロードができます

ソースコード

diff #


def count_one(d):
    b = 0b1
    count = 0
    for i in range(16):
        if d & b:
            count += 1
        b = b << 1
    
    return count

nest_list =[]

def func(current_index, current_nest, goal_index):
    
    if current_index == goal_index:
        if (nest_list[n-1] == -1) or (nest_list[n-1] > current_nest):
            nest_list[n-1] = current_nest
        return

    if nest_list[current_index] is not goal_index:
        if nest_list[current_index] > current_nest:
            nest_list[current_index] = current_nest
        else :
            return
    else :
        nest_list[current_index] = current_nest

    gap_index = count_one(current_index+1)
    front_index = current_index - gap_index
    back_index = current_index + gap_index
    
    if front_index > 0:
        func(front_index, current_nest + 1, goal_index)
    if back_index <= goal_index:
        func(back_index, current_nest + 1, goal_index)
    


if __name__ == '__main__':
    n = map(int, input().split())
    nest_list = [n] * n
    nest_list[n-1] = -1

    func(0, 1, n-1)
    print(nest_list[n-1])







0