結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  tak | 
| 提出日時 | 2019-04-27 22:34:42 | 
| 言語 | F# (F# 4.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,013 bytes | 
| コンパイル時間 | 12,293 ms | 
| コンパイル使用メモリ | 186,712 KB | 
| 実行使用メモリ | 30,976 KB | 
| 最終ジャッジ日時 | 2024-11-29 20:27:03 | 
| 合計ジャッジ時間 | 15,477 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 WA * 19 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (590 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
open System
let bitCount x =
    let mutable x = x
    x <- x - ((x >>> 1) &&& 0x55555555)
    x <- (x &&& 0x33333333) + ((x >>> 2) &&& 0x33333333)
    x <- (x + (x >>> 4)) &&& 0x0f0f0f0f;
    x <- x + (x >>> 8);
    x <- x + (x >>> 16);
    x &&& 0x3f
let isLeachable n =
    let dis = Array.zeroCreate (n + 1)
    dis.[1] <- 1
    let rec visit x =        
        let bit = bitCount x
        let f = x - bit
        let b = x + bit
        let f1 = f >= 1 && dis.[f] = 0
        let f2 = b <= n && dis.[b] = 0
        match (f1, f2) with
        | true, true -> 
            dis.[f] <- dis.[x] + 1
            dis.[b] <- dis.[x] + 1
            visit f
            visit b
        | true, false ->
            dis.[f] <- dis.[x] + 1
            visit f
        | false, true ->
            dis.[b] <- dis.[x] + 1
            visit b
        | false, false ->
            ()
    visit 1
    dis.[n]
        
let N = Console.ReadLine() |> int
isLeachable N
|> function
| 0 -> -1
| x -> x
|> Console.WriteLine
            
            
            
        