結果
| 問題 | 
                            No.642 Two Operations No.1
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-18 18:53:46 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 637 bytes | 
| コンパイル時間 | 88 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 615,128 KB | 
| 最終ジャッジ日時 | 2024-06-29 01:58:32 | 
| 合計ジャッジ時間 | 3,821 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 MLE * 1 -- * 10 | 
ソースコード
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()