結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー tanson
提出日時 2025-07-17 17:01:17
言語 Standard ML
(MLton 20210117)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 3,566 ms
コンパイル使用メモリ 687,356 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-17 17:01:22
合計ジャッジ時間 4,645 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

fun readInt () =
    valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn)

fun int_pow (x, y) =
    let
        fun loop n =
            if n = 0 then 1
            else x * loop (n - 1)
    in
        loop y
    end

val () =
    let
        val n = readInt ()

        val numOfHitsForMoreThanHalf =
            let
                fun loop need current =
                    if need < current then 0
                    else 1 + loop need (current * 2)
            in
                loop n 1 - 1
            end
                
        val rest = n - int_pow (2, numOfHitsForMoreThanHalf)

        val ans = if rest = 0 then numOfHitsForMoreThanHalf
                  else numOfHitsForMoreThanHalf + 1
    in
        print (Int.toString ans)
    end
0