結果

問題 No.642 Two Operations No.1
コンテスト
ユーザー Theta
提出日時 2022-10-18 18:53:46
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
MLE  
実行時間 -
コード長 637 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 321 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 926,680 KB
最終ジャッジ日時 2026-03-18 11:16:26
合計ジャッジ時間 34,993 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 MLE * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from math import inf, log10, floor, log2


def main():
    N = int(input())
    two_pow_over_N = 2 ** (floor(log2(N))+1)
    table = [inf for _ in range(two_pow_over_N)]
    for idx in range(floor(log2(N))+2):
        table[2**idx - 1] = idx

    for idx in range(2, floor(log2(N))+2):
        for mid_idx in reversed(range(2**(idx-1)+1, 2**idx)):
            if mid_idx % 2 != 0:
                table[mid_idx-1] = table[mid_idx] + 1
            else:
                table[mid_idx-1] = min(
                    table[mid_idx], table[mid_idx // 2 - 1]
                ) + 1
    print(table[N-1])


if __name__ == "__main__":
    main()
0