結果

問題 No.3 ビットすごろく
ユーザー pocaristpocarist
提出日時 2015-09-01 13:00:24
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 718 bytes
コンパイル時間 5,673 ms
コンパイル使用メモリ 164,708 KB
実行使用メモリ 26,900 KB
最終ジャッジ日時 2023-09-25 21:44:36
合計ジャッジ時間 9,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
22,816 KB
testcase_01 AC 80 ms
20,648 KB
testcase_02 AC 81 ms
22,748 KB
testcase_03 AC 82 ms
22,872 KB
testcase_04 AC 82 ms
24,780 KB
testcase_05 AC 82 ms
24,868 KB
testcase_06 AC 81 ms
24,776 KB
testcase_07 AC 81 ms
24,900 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 84 ms
22,920 KB
testcase_13 AC 81 ms
22,636 KB
testcase_14 AC 82 ms
20,828 KB
testcase_15 AC 82 ms
23,016 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 80 ms
20,744 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 81 ms
22,764 KB
testcase_22 AC 81 ms
22,968 KB
testcase_23 AC 81 ms
24,868 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 81 ms
24,744 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 81 ms
22,828 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

// http://yukicoder.me/problems/11
open System

let dprintfn fmt = Printf.kprintf Diagnostics.Debug.WriteLine fmt

let bitcount n =
    let rec loop bits num =
        if bits = 0 then num
        else loop (bits &&& (bits-1)) (num+1)
    loop n 0

let solve N =
    let dp = Array.init (N+1) (fun _ -> -1)
    let rec f i ans =
        dp.[i] <- if dp.[i] > 0 then min dp.[i] ans else ans
        if i = N then () else
        let n = bitcount i
        if i+n < N+1 && dp.[i+n] = -1 then
            f (i+n) (ans+1)
        if i-n > 0 && dp.[i-n] = -1 then
            f (i-n) (ans+1)
    f 1 1
    dp.[N]

[<EntryPoint>]
let main argv = 
    let N = Console.ReadLine() |> int
    solve N
    |> printfn "%d" 
    0
0