結果
問題 | No.3 ビットすごろく |
ユーザー | guricerin |
提出日時 | 2020-02-04 12:43:32 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 72 ms / 5,000 ms |
コード長 | 1,387 bytes |
コンパイル時間 | 3,623 ms |
コンパイル使用メモリ | 162,168 KB |
実行使用メモリ | 26,404 KB |
最終ジャッジ日時 | 2023-09-14 01:35:52 |
合計ジャッジ時間 | 7,309 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
26,404 KB |
testcase_01 | AC | 62 ms
22,204 KB |
testcase_02 | AC | 65 ms
22,424 KB |
testcase_03 | AC | 68 ms
22,328 KB |
testcase_04 | AC | 65 ms
24,208 KB |
testcase_05 | AC | 69 ms
24,252 KB |
testcase_06 | AC | 66 ms
22,356 KB |
testcase_07 | AC | 65 ms
22,244 KB |
testcase_08 | AC | 68 ms
22,136 KB |
testcase_09 | AC | 69 ms
24,212 KB |
testcase_10 | AC | 69 ms
24,208 KB |
testcase_11 | AC | 67 ms
24,208 KB |
testcase_12 | AC | 68 ms
22,340 KB |
testcase_13 | AC | 67 ms
24,276 KB |
testcase_14 | AC | 70 ms
22,352 KB |
testcase_15 | AC | 72 ms
22,236 KB |
testcase_16 | AC | 71 ms
24,396 KB |
testcase_17 | AC | 72 ms
22,328 KB |
testcase_18 | AC | 65 ms
24,188 KB |
testcase_19 | AC | 72 ms
24,388 KB |
testcase_20 | AC | 65 ms
22,132 KB |
testcase_21 | AC | 63 ms
22,228 KB |
testcase_22 | AC | 70 ms
24,460 KB |
testcase_23 | AC | 71 ms
22,400 KB |
testcase_24 | AC | 71 ms
24,348 KB |
testcase_25 | AC | 70 ms
20,152 KB |
testcase_26 | AC | 62 ms
22,232 KB |
testcase_27 | AC | 66 ms
22,352 KB |
testcase_28 | AC | 70 ms
24,464 KB |
testcase_29 | AC | 67 ms
22,248 KB |
testcase_30 | AC | 64 ms
22,412 KB |
testcase_31 | AC | 63 ms
20,240 KB |
testcase_32 | AC | 66 ms
22,316 KB |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved.
ソースコード
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 inf = Int32.MaxValue let dist = Array.init (n + 1) (fun _ -> inf) let len = dist |> Array.length dist.[1] <- 1 let que = Queue<int>() que.Enqueue(1) let inner a = 1 <= a && a < len while que.Count > 0 do let i = que.Dequeue() let b = bitcount i let l = i - b let r = i + b let next = dist.[i] + 1 if inner l && dist.[l] > next then dist.[l] <- next que.Enqueue(l) if inner r && dist.[r] > next then dist.[r] <- next que.Enqueue(r) if dist.[n] = inf then -1 else dist.[n] |> puts () main() writer.Close()