結果

問題 No.642 Two Operations No.1
コンテスト
ユーザー tak
提出日時 2018-03-20 08:38:06
言語 F#
(F# 10.0)
コンパイル:
fsharp_c _filename_
実行:
/usr/bin/dotnet_wrap
結果
WA  
実行時間 -
コード長 829 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 12,343 ms
コンパイル使用メモリ 210,856 KB
実行使用メモリ 37,844 KB
最終ジャッジ日時 2026-03-07 21:27:23
合計ジャッジ時間 16,417 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (182 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

open System

let rec binarySearch ng ok func =
        if abs (ok-ng) > 1 then 
            let mid = (ok+ng)/2
            if func mid then 
                binarySearch ng mid func 
            else 
                binarySearch mid ok func
        else 
            if func ok then Some(ok)
            else            None

let lowerBound (arr:'a[]) x =
    binarySearch -1 arr.Length (fun mid -> compare arr.[mid] x >= 0)
            
let arr =
    let rec f a =
        [|
            yield a
            if a < (int 1e9 + 5) then 
                yield! f (a*2)
        |]
    f 1       

let N = Console.ReadLine() |> int

let ans = 
    match lowerBound arr N with
    | Some(x) -> 
        let n1 = x
        let n2 = arr.[n1] - N
        n1 + n2                
    | None ->
        -1
    
ans
|> printfn "%i"

    
0