結果

問題 No.642 Two Operations No.1
ユーザー ThetaTheta
提出日時 2022-10-18 18:53:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 637 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 686,384 KB
最終ジャッジ日時 2023-09-11 11:19:32
合計ジャッジ時間 4,525 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,472 KB
testcase_01 AC 17 ms
7,932 KB
testcase_02 AC 16 ms
8,028 KB
testcase_03 AC 16 ms
7,940 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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