結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
pocarist
|
| 提出日時 | 2015-09-01 13:56:13 |
| 言語 | F# (F# 10.0) |
| 結果 |
AC
|
| 実行時間 | 588 ms / 5,000 ms |
| コード長 | 906 bytes |
| 記録 | |
| コンパイル時間 | 4,906 ms |
| コンパイル使用メモリ | 212,204 KB |
| 実行使用メモリ | 87,760 KB |
| 最終ジャッジ日時 | 2026-03-22 03:40:56 |
| 合計ジャッジ時間 | 15,914 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (163 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net10.0/main.dll main -> /home/judge/data/code/bin/Release/net10.0/publish/
ソースコード
// http://yukicoder.me/problems/11
open System
open System.Collections.Generic
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 visited = Array.init (N+1) (fun _ -> false)
let q = new Queue<int*int>()
q.Enqueue(1,1)
let rec bfs () =
if q.Count = 0 then -1 else
let i, cnt = q.Dequeue()
if i = N then cnt else
visited.[i] <- true
let n = bitcount i
if i+n = N then cnt+1 else
if i+n < N && not visited.[i+n] then
q.Enqueue(i+n, cnt+1)
if i-n >= 1 && not visited.[i-n] then
q.Enqueue(i-n, cnt+1)
bfs ()
bfs ()
[<EntryPoint>]
let main argv =
let N = Console.ReadLine() |> int
solve N
|> printfn "%d"
0
pocarist