結果

問題 No.642 Two Operations No.1
ユーザー tak
提出日時 2018-03-20 08:38:06
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 14,267 ms
コンパイル使用メモリ 186,872 KB
実行使用メモリ 36,044 KB
最終ジャッジ日時 2024-06-23 06:16:08
合計ジャッジ時間 20,043 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (327 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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