結果

問題 No.3 ビットすごろく
ユーザー nemuneminemunemi
提出日時 2021-02-06 20:09:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 2,138 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 101,044 KB
実行使用メモリ 23,708 KB
最終ジャッジ日時 2023-09-16 06:34:35
合計ジャッジ時間 5,972 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,680 KB
testcase_01 AC 58 ms
21,684 KB
testcase_02 AC 57 ms
21,584 KB
testcase_03 AC 60 ms
21,568 KB
testcase_04 AC 58 ms
21,688 KB
testcase_05 AC 58 ms
21,544 KB
testcase_06 AC 60 ms
21,496 KB
testcase_07 AC 59 ms
23,676 KB
testcase_08 AC 59 ms
23,708 KB
testcase_09 AC 58 ms
21,608 KB
testcase_10 AC 59 ms
19,648 KB
testcase_11 AC 59 ms
21,548 KB
testcase_12 AC 58 ms
21,696 KB
testcase_13 AC 58 ms
21,632 KB
testcase_14 AC 59 ms
21,628 KB
testcase_15 AC 60 ms
23,476 KB
testcase_16 AC 60 ms
21,696 KB
testcase_17 AC 59 ms
21,680 KB
testcase_18 AC 58 ms
21,696 KB
testcase_19 AC 60 ms
23,600 KB
testcase_20 AC 59 ms
21,604 KB
testcase_21 AC 58 ms
23,592 KB
testcase_22 AC 60 ms
21,632 KB
testcase_23 AC 59 ms
21,684 KB
testcase_24 AC 59 ms
21,684 KB
testcase_25 AC 58 ms
21,488 KB
testcase_26 AC 57 ms
21,640 KB
testcase_27 AC 58 ms
21,612 KB
testcase_28 AC 59 ms
23,684 KB
testcase_29 AC 59 ms
21,548 KB
testcase_30 AC 58 ms
23,592 KB
testcase_31 AC 58 ms
21,644 KB
testcase_32 AC 59 ms
21,616 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace PProgram
{
    class Program
    {
        static void Main(string[] args)
        {

            int Masu = int.Parse(Console.ReadLine());

            var myQ = new Queue();
            bool[] Tansakuzumi = Enumerable.Repeat(false,Masu + 1).ToArray();
            int[] KaisuKiroku = Enumerable.Repeat(0, Masu + 1).ToArray();

            myQ.Enqueue(1);
            KaisuKiroku[1] = 1;

            while(myQ.Count != 0)
            {
                var target = (int)myQ.Dequeue();

                int idoukyori = BitCount(target);

                int NextIndex = target + idoukyori;

                if( 1 <= NextIndex && NextIndex <= Masu)
                {
                    if(!Tansakuzumi[NextIndex])
                    {
                        myQ.Enqueue(NextIndex);
                        Tansakuzumi[NextIndex] = true;
                        KaisuKiroku[NextIndex] = KaisuKiroku[target] + 1;
                    }
                }

                NextIndex = target - idoukyori;
                if(1 <= NextIndex && NextIndex <= Masu)
                {
                    if(!Tansakuzumi[NextIndex])
                    {
                        myQ.Enqueue(NextIndex);
                        Tansakuzumi[NextIndex] = true;
                        KaisuKiroku[NextIndex] = KaisuKiroku[target] + 1;
                    }
                }
            }

            if (KaisuKiroku[Masu] == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(KaisuKiroku[Masu]);
            }

        }
        
        private static int BitCount (int number)
        {
            int bitCount = 0;

            for(int i = 0; number > 0; i++)
            {
                int onezero = number % 2;
                if(onezero == 1)
                {
                    bitCount++;
                }

                number = number / 2;
            }

            return bitCount;
        }
    }
}
0