結果

問題 No.3 ビットすごろく
ユーザー HimatsubushinHimatsubushin
提出日時 2019-01-21 13:14:44
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,139 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 104,988 KB
実行使用メモリ 24,892 KB
最終ジャッジ日時 2023-10-13 17:15:23
合計ジャッジ時間 5,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
22,252 KB
testcase_01 AC 59 ms
20,144 KB
testcase_02 AC 58 ms
22,208 KB
testcase_03 AC 60 ms
22,212 KB
testcase_04 AC 60 ms
22,184 KB
testcase_05 AC 60 ms
22,396 KB
testcase_06 AC 60 ms
22,164 KB
testcase_07 AC 60 ms
22,304 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 60 ms
22,484 KB
testcase_13 AC 60 ms
22,324 KB
testcase_14 AC 60 ms
22,632 KB
testcase_15 AC 61 ms
22,752 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 60 ms
22,220 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 61 ms
24,084 KB
testcase_22 AC 61 ms
22,584 KB
testcase_23 AC 61 ms
20,788 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 61 ms
23,868 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 59 ms
22,224 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.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;
        }
    }
}
0