結果

問題 No.3 ビットすごろく
ユーザー HimatsubushinHimatsubushin
提出日時 2019-01-23 07:49:01
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,761 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 61,676 KB
実行使用メモリ 23,812 KB
最終ジャッジ日時 2023-10-14 09:21:04
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
23,812 KB
testcase_01 AC 50 ms
21,616 KB
testcase_02 AC 47 ms
21,564 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace No003_ビットすごろく
{
    class Program
    {
        static private int Min;
        static private int N;

        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            Min = N;
            bool[] progression = Enumerable.Repeat(false, N + 1).ToArray();

            Search(1, 1, progression);

            if (Min == N)
                Console.WriteLine(-1);
            else
                Console.WriteLine(Min);
        }

        static void Search(int level, int count, bool[] progressionB)
        {
            bool[] progression = new bool[progressionB.Count()];
            Array.Copy(progressionB, progression, progressionB.Count());

            if (level == N)
            {
//                Console.WriteLine("★★★ " + level.ToString() + " " + BitNumber(level).ToString()+" "+count.ToString());
                if (Min > count)
                    Min = count;
            }
            else if (Min < count)
            {
                return;
            }
            else if (level > 0 && level <= N && !progression[level])
            {
//                Console.WriteLine(level.ToString() + " " + BitNumber(level).ToString() + " " + count.ToString());
                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;
        }
    }
}
0