結果

問題 No.3 ビットすごろく
ユーザー guriceringuricerin
提出日時 2020-02-04 12:22:15
言語 F#
(F# 4.0)
結果
AC  
実行時間 864 ms / 5,000 ms
コード長 1,264 bytes
コンパイル時間 3,469 ms
コンパイル使用メモリ 165,444 KB
実行使用メモリ 28,416 KB
最終ジャッジ日時 2023-09-14 01:36:47
合計ジャッジ時間 34,007 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 856 ms
28,404 KB
testcase_01 AC 856 ms
28,416 KB
testcase_02 AC 854 ms
26,332 KB
testcase_03 AC 858 ms
28,404 KB
testcase_04 AC 855 ms
28,216 KB
testcase_05 AC 860 ms
26,328 KB
testcase_06 AC 853 ms
26,292 KB
testcase_07 AC 856 ms
26,276 KB
testcase_08 AC 856 ms
26,284 KB
testcase_09 AC 858 ms
26,244 KB
testcase_10 AC 862 ms
28,280 KB
testcase_11 AC 858 ms
28,340 KB
testcase_12 AC 855 ms
26,452 KB
testcase_13 AC 854 ms
28,388 KB
testcase_14 AC 864 ms
24,196 KB
testcase_15 AC 864 ms
24,384 KB
testcase_16 AC 861 ms
28,288 KB
testcase_17 AC 863 ms
28,252 KB
testcase_18 AC 855 ms
26,368 KB
testcase_19 AC 860 ms
26,464 KB
testcase_20 AC 853 ms
24,448 KB
testcase_21 AC 854 ms
26,420 KB
testcase_22 AC 858 ms
24,116 KB
testcase_23 AC 863 ms
26,220 KB
testcase_24 AC 864 ms
24,232 KB
testcase_25 AC 864 ms
28,304 KB
testcase_26 AC 855 ms
28,292 KB
testcase_27 AC 854 ms
24,300 KB
testcase_28 AC 864 ms
26,564 KB
testcase_29 AC 859 ms
26,296 KB
testcase_30 AC 852 ms
24,292 KB
testcase_31 AC 851 ms
26,240 KB
testcase_32 AC 856 ms
26,344 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let bitcount (a: int) =
    a
    |> fun x -> Convert.ToString(a, 2)
    |> fun x -> x.Replace("0", "")
    |> fun x -> x.Length

let main() =
    let n = read int
    let len = 10100
    let lim = Int32.MaxValue
    let dp = Array.init len (fun _ -> lim)
    dp.[0] <- 0
    dp.[1] <- 1
    for _ in 0 .. 100 do
        for i in 1 .. 10000 do
            let b = bitcount i
            let l = i - b
            let r = i + b
            let ok = dp.[i] <> lim
            if 1 <= l && l <= n && ok then dp.[l] <- min dp.[l] (dp.[i] + 1)
            if 1 <= r && r <= n && ok then dp.[r] <- min dp.[r] (dp.[i] + 1)

    if dp.[n] = lim then -1 else dp.[n]
    |> puts
    ()

main()
writer.Close()
0