結果

問題 No.3 ビットすごろく
ユーザー mori_chibimori_chibi
提出日時 2017-08-24 12:06:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 1,587 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 100,332 KB
実行使用メモリ 22,840 KB
最終ジャッジ日時 2023-09-14 00:48:30
合計ジャッジ時間 4,993 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
20,740 KB
testcase_01 AC 53 ms
18,772 KB
testcase_02 AC 52 ms
20,788 KB
testcase_03 AC 52 ms
20,772 KB
testcase_04 AC 51 ms
20,732 KB
testcase_05 AC 53 ms
20,592 KB
testcase_06 AC 53 ms
20,656 KB
testcase_07 AC 52 ms
22,768 KB
testcase_08 AC 55 ms
20,816 KB
testcase_09 AC 54 ms
20,660 KB
testcase_10 AC 54 ms
20,840 KB
testcase_11 AC 53 ms
22,840 KB
testcase_12 AC 55 ms
20,776 KB
testcase_13 AC 53 ms
22,624 KB
testcase_14 AC 56 ms
22,700 KB
testcase_15 AC 55 ms
20,784 KB
testcase_16 AC 56 ms
22,708 KB
testcase_17 AC 56 ms
22,736 KB
testcase_18 AC 53 ms
22,708 KB
testcase_19 AC 54 ms
20,588 KB
testcase_20 AC 52 ms
20,768 KB
testcase_21 AC 53 ms
20,656 KB
testcase_22 AC 56 ms
18,584 KB
testcase_23 AC 56 ms
20,820 KB
testcase_24 AC 53 ms
20,660 KB
testcase_25 AC 54 ms
18,752 KB
testcase_26 AC 52 ms
22,784 KB
testcase_27 AC 52 ms
22,664 KB
testcase_28 AC 54 ms
20,632 KB
testcase_29 AC 55 ms
20,864 KB
testcase_30 AC 51 ms
20,736 KB
testcase_31 AC 51 ms
20,768 KB
testcase_32 AC 52 ms
20,772 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace BitSugoroku
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int R = MainProcess(N);
            Console.WriteLine(R);
        }

        private static int MainProcess(int N)
        {
            int[] Squares = new int[N + 1];
            Squares[1] = 1;
            int bits = 0;
            bool newdiscovery = true;
            while (newdiscovery)
            {
                newdiscovery = false;
                for (int x = 1; x <= N; x++)
                {
                    if (Squares[x] > 0)
                    {
                        bits = BitCounter(x);
                        if (x + bits <= N && (Squares[x + bits] == 0 || Squares[x + bits] > Squares[x] + 1))
                        {
                            Squares[x + bits] = Squares[x] + 1;
                            newdiscovery = true;
                        }
                        if (x - bits >= 0 && (Squares[x - bits] == 0 || Squares[x - bits] > Squares[x] + 1))
                        {
                            Squares[x - bits] = Squares[x] + 1;
                            newdiscovery = true;
                        }
                    }
                }

            }
            return (Squares[N] == 0) ? -1 : Squares[N];
        }

        private static int BitCounter(int x)
        {
            int b = 0;
            while (x > 0)
            {
                b += x % 2;
                x /= 2;
            }
            return b;
        }
    }
}
0