結果

問題 No.3 ビットすごろく
ユーザー guriceringuricerin
提出日時 2020-02-04 12:16:50
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 1,262 bytes
コンパイル時間 21,569 ms
コンパイル使用メモリ 193,844 KB
実行使用メモリ 33,096 KB
最終ジャッジ日時 2023-10-20 11:30:55
合計ジャッジ時間 24,156 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
33,040 KB
testcase_01 AC 68 ms
33,040 KB
testcase_02 AC 68 ms
33,028 KB
testcase_03 AC 68 ms
33,028 KB
testcase_04 WA -
testcase_05 AC 68 ms
33,028 KB
testcase_06 AC 68 ms
33,028 KB
testcase_07 AC 69 ms
33,028 KB
testcase_08 AC 69 ms
33,028 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 70 ms
33,028 KB
testcase_13 AC 69 ms
33,028 KB
testcase_14 AC 69 ms
33,028 KB
testcase_15 AC 69 ms
33,028 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 70 ms
33,028 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 69 ms
33,040 KB
testcase_22 AC 69 ms
33,028 KB
testcase_23 AC 71 ms
33,028 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 69 ms
33,040 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 69 ms
33,032 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (812 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

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 .. 1 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