結果

問題 No.642 Two Operations No.1
ユーザー taktak
提出日時 2018-03-20 08:38:06
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 4,859 ms
コンパイル使用メモリ 166,036 KB
実行使用メモリ 25,156 KB
最終ジャッジ日時 2023-09-05 10:30:38
合計ジャッジ時間 6,895 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
23,048 KB
testcase_01 AC 87 ms
25,044 KB
testcase_02 AC 87 ms
23,076 KB
testcase_03 AC 89 ms
23,180 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 89 ms
25,044 KB
testcase_14 AC 89 ms
22,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

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