結果

問題 No.3 ビットすごろく
ユーザー yuki2006yuki2006
提出日時 2017-07-01 15:34:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,951 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 102,960 KB
実行使用メモリ 22,800 KB
最終ジャッジ日時 2023-09-14 00:46:31
合計ジャッジ時間 4,970 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
22,736 KB
testcase_01 AC 53 ms
20,612 KB
testcase_02 AC 55 ms
20,684 KB
testcase_03 AC 54 ms
20,800 KB
testcase_04 AC 53 ms
20,848 KB
testcase_05 AC 55 ms
20,664 KB
testcase_06 AC 56 ms
22,724 KB
testcase_07 AC 55 ms
20,744 KB
testcase_08 AC 55 ms
22,716 KB
testcase_09 AC 54 ms
18,780 KB
testcase_10 AC 54 ms
20,736 KB
testcase_11 AC 53 ms
22,672 KB
testcase_12 AC 55 ms
20,668 KB
testcase_13 AC 54 ms
22,792 KB
testcase_14 AC 55 ms
22,800 KB
testcase_15 AC 58 ms
20,744 KB
testcase_16 AC 53 ms
20,656 KB
testcase_17 AC 53 ms
20,796 KB
testcase_18 AC 55 ms
18,636 KB
testcase_19 AC 56 ms
20,740 KB
testcase_20 AC 55 ms
20,660 KB
testcase_21 AC 53 ms
20,744 KB
testcase_22 AC 55 ms
22,792 KB
testcase_23 AC 53 ms
22,788 KB
testcase_24 AC 53 ms
22,784 KB
testcase_25 AC 51 ms
20,624 KB
testcase_26 AC 51 ms
20,696 KB
testcase_27 AC 50 ms
20,768 KB
testcase_28 AC 54 ms
20,656 KB
testcase_29 AC 52 ms
22,728 KB
testcase_30 AC 51 ms
20,780 KB
testcase_31 AC 52 ms
20,740 KB
testcase_32 AC 54 ms
20,736 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.Generic;
namespace Procon
{
    class MainClass
    {
        static int popCount(int v)
        {
            int count = 0;
            while (v > 0)
            {
                if (v % 2 == 1)
                {
                    count++;
                }
                v /= 2;

            }
            return count;
        }
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            bool[] check = new bool[N + 1];
            List<int> current = new List<int>();
            current.Add(1);
            check[1] = true;
            int turn = 1;

            if (N == 1)
            {
                Console.WriteLine(1);
                return;
            }

            while (current.Count > 0)
            {
                List<int> next = new List<int>();

                foreach (var cur in current)
                {
                    var count = popCount(cur);

                    int nextR = cur + count;
                    int nextL = cur - count;
                    if (nextR == N)
                    {
                        Console.WriteLine(turn + 1);
                        return;
                    }
                    if (0 < nextR && nextR < N)
                    {
                        if (!check[nextR])
                        {
                            next.Add(nextR);
                            check[nextR] = true;
                        }

                    }
                    if (0 < nextL && nextL < N)
                    {
                        if (!check[nextL])
                        {
                            next.Add(nextL);
                            check[nextL] = true;

                        }
                    }
                }
                turn++;
                current = next;
            }
            Console.WriteLine(-1);
        }
    }
}
0