結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-22 14:20:09 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,350 bytes | 
| コンパイル時間 | 2,443 ms | 
| コンパイル使用メモリ | 109,548 KB | 
| 実行使用メモリ | 26,888 KB | 
| 最終ジャッジ日時 | 2024-09-15 13:33:26 | 
| 合計ジャッジ時間 | 4,276 ms | 
| ジャッジサーバーID (参考情報) | judge6 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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.Collections.Generic;
using System.Linq;
namespace No003_ビットすごろく
{
    class Program
    {
        static private List<int> Number = new List<int>();
        static private int N;
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            bool[] progression = new bool[N + 1];
            Search(1, 1, progression);
            if (Number.Count == 0)
                Console.WriteLine(-1);
            else
                Console.WriteLine(Number.Min());
        }
        static void Search(int level, int count, bool[] progression)
        {
            if (level == N)
            {
                Number.Add(count);
                return;
            }
            else if (level < 1 || level > N || progression[level])
            {
                return;
            }
            else
            {
                progression[level] = true;
                Search(level + BitNumber(level), count + 1, progression);
                Search(level - BitNumber(level), count + 1, progression);
            }
        }
        static int BitNumber(int a)
        {
            int temp = 0;
            do
            {
                temp += a % 2;
                a /= 2;
            } while (a > 0);
            return temp;
        }
    }
}
            
            
            
        