結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-21 13:14:44 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,139 bytes | 
| コンパイル時間 | 903 ms | 
| コンパイル使用メモリ | 114,812 KB | 
| 実行使用メモリ | 27,680 KB | 
| 最終ジャッジ日時 | 2024-09-15 13:11:05 | 
| 合計ジャッジ時間 | 2,882 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 WA * 15 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
using System.Collections.Generic;
namespace No003_ビットすごろく
{
    class Program
    {
        static private int N;
        static private int M;
        static private int[] Bit;
        static private List<int> Count = new List<int>();
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            BitCheck();
            bool[] CheckerF = Enumerable.Repeat<bool>(false, M).ToArray();
            bool[] CheckerB = Enumerable.Repeat<bool>(false, M).ToArray();
            Recursive(1, 1, CheckerF, CheckerB);
            if (Count.Count == 0)
                Console.WriteLine(-1);
            else
                Console.WriteLine(Count.Min());
        }
        static void BitCheck()
        {
            M = (int)Math.Pow(2.0, Math.Log((double)N, 2.0) + 1.0);
            int[] log2 = new int[M];
            int temp, count;
            Bit = new int[M];
            log2[0] = 1;
            log2[1] = 1;
            Bit[0] = 0;
            Bit[1] = 1;
            temp = 1;
            count = 0;
            for (int i = 2; i <= N; i++)
            {
                log2[i] = (int)Math.Log((double)i, 2.0) + 1;
                if (log2[i] != temp)
                {
                    temp = log2[i];
                    count = 0;
                }
                Bit[i] = Bit[count] + 1;
                count++;
            }
        }
        static void Recursive(int level, int count, bool[] CheckerF, bool[] CheckerB)
        {
            if (level > M || level < 1)
                return;
            else if (level == N)
            {
                Count.Add(count);
                return;
            }
            if (!CheckerF[level])
            {
                CheckerF[level] = true;
                Recursive(level + Bit[level], count + 1, CheckerF, CheckerB);
            }
            if (!CheckerB[level])
            {
                CheckerB[level] = true;
                Recursive(level - Bit[level], count + 1, CheckerF, CheckerB);
            }
            return;
        }
    }
}
            
            
            
        