結果

問題 No.3 ビットすごろく
ユーザー HimatsubushinHimatsubushin
提出日時 2019-01-22 14:20:09
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,350 bytes
コンパイル時間 3,905 ms
コンパイル使用メモリ 103,988 KB
実行使用メモリ 25,652 KB
最終ジャッジ日時 2023-10-13 17:40:42
合計ジャッジ時間 7,394 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
21,508 KB
testcase_01 AC 52 ms
19,504 KB
testcase_02 AC 49 ms
23,524 KB
testcase_03 AC 49 ms
23,456 KB
testcase_04 AC 50 ms
21,572 KB
testcase_05 AC 50 ms
23,484 KB
testcase_06 AC 51 ms
23,376 KB
testcase_07 AC 51 ms
21,580 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 51 ms
23,588 KB
testcase_13 AC 51 ms
21,424 KB
testcase_14 AC 50 ms
23,576 KB
testcase_15 AC 53 ms
21,460 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 53 ms
21,416 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 55 ms
23,436 KB
testcase_22 AC 51 ms
21,468 KB
testcase_23 AC 54 ms
23,588 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 52 ms
21,532 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 49 ms
19,456 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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;
        }
    }
}
0