結果

問題 No.3 ビットすごろく
ユーザー HimatsubushinHimatsubushin
提出日時 2019-01-22 16:14:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,207 bytes
コンパイル時間 1,221 ms
コンパイル使用メモリ 67,548 KB
実行使用メモリ 23,776 KB
最終ジャッジ日時 2023-09-14 01:10:49
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
23,688 KB
testcase_01 AC 58 ms
21,624 KB
testcase_02 AC 58 ms
21,724 KB
testcase_03 AC 59 ms
23,680 KB
testcase_04 AC 58 ms
21,632 KB
testcase_05 AC 60 ms
23,636 KB
testcase_06 AC 60 ms
23,672 KB
testcase_07 AC 58 ms
21,852 KB
testcase_08 AC 59 ms
21,672 KB
testcase_09 AC 59 ms
23,776 KB
testcase_10 AC 60 ms
21,656 KB
testcase_11 AC 60 ms
23,656 KB
testcase_12 AC 60 ms
21,740 KB
testcase_13 AC 60 ms
21,768 KB
testcase_14 AC 60 ms
21,664 KB
testcase_15 AC 60 ms
21,780 KB
testcase_16 AC 60 ms
21,860 KB
testcase_17 AC 59 ms
19,676 KB
testcase_18 AC 60 ms
21,576 KB
testcase_19 AC 60 ms
21,756 KB
testcase_20 AC 58 ms
21,632 KB
testcase_21 AC 59 ms
23,612 KB
testcase_22 AC 60 ms
23,628 KB
testcase_23 AC 61 ms
23,660 KB
testcase_24 AC 60 ms
19,572 KB
testcase_25 AC 59 ms
21,620 KB
testcase_26 AC 58 ms
21,748 KB
testcase_27 AC 59 ms
23,660 KB
testcase_28 AC 60 ms
21,864 KB
testcase_29 AC 58 ms
19,624 KB
testcase_30 AC 59 ms
21,736 KB
testcase_31 AC 59 ms
21,856 KB
testcase_32 AC 59 ms
21,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

namespace No003_ビットすごろく
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] box = Enumerable.Repeat(-1, N + 1).ToArray();
            Queue<int> que = new Queue<int>();

            box[1] = 1;
            que.Enqueue(1);

            while (que.Count != 0)
            {
                int pos = que.Dequeue();
                int bit = BitNumber(pos);

                if (pos - bit > 0 && box[pos - bit] == -1)
                {
                    box[pos - bit] = box[pos] + 1;
                    que.Enqueue(pos - bit);
                }

                if (pos + bit <= N && box[pos + bit] == -1)
                {
                    box[pos + bit] = box[pos] + 1;
                    que.Enqueue(pos + bit);
                }
            }

            Console.WriteLine(box[N]);
        }

        static int BitNumber(int a)
        {
            int temp = 0;

            do
            {
                temp += a % 2;
                a /= 2;
            } while (a > 0);

            return temp;
        }
    }
}
0