結果

問題 No.3 ビットすごろく
ユーザー yuki2006yuki2006
提出日時 2017-07-01 15:30:25
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,837 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 110,136 KB
実行使用メモリ 27,752 KB
最終ジャッジ日時 2024-04-15 10:08:48
合計ジャッジ時間 2,775 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
23,980 KB
testcase_01 WA -
testcase_02 AC 25 ms
23,412 KB
testcase_03 AC 26 ms
25,468 KB
testcase_04 WA -
testcase_05 AC 26 ms
23,420 KB
testcase_06 AC 25 ms
23,668 KB
testcase_07 AC 26 ms
23,596 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 26 ms
25,332 KB
testcase_13 AC 25 ms
25,720 KB
testcase_14 AC 25 ms
23,540 KB
testcase_15 AC 25 ms
25,740 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 26 ms
25,572 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 26 ms
24,004 KB
testcase_22 AC 27 ms
25,728 KB
testcase_23 AC 27 ms
23,748 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
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.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;
            while (current.Count > 0)
            {
                List<int> next = new List<int>();

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

                    int nextR = count + cur;
                    int nextL = count - cur;
                    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