結果

問題 No.3 ビットすごろく
ユーザー yuki2006yuki2006
提出日時 2017-07-01 15:33:32
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,809 bytes
コンパイル時間 2,519 ms
コンパイル使用メモリ 109,888 KB
実行使用メモリ 25,920 KB
最終ジャッジ日時 2024-04-15 10:16:49
合計ジャッジ時間 3,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,492 KB
testcase_01 AC 26 ms
23,876 KB
testcase_02 AC 26 ms
23,856 KB
testcase_03 AC 26 ms
23,620 KB
testcase_04 AC 26 ms
23,876 KB
testcase_05 AC 29 ms
23,804 KB
testcase_06 AC 27 ms
25,724 KB
testcase_07 AC 25 ms
23,728 KB
testcase_08 AC 26 ms
23,860 KB
testcase_09 AC 27 ms
23,496 KB
testcase_10 AC 26 ms
23,816 KB
testcase_11 AC 26 ms
25,836 KB
testcase_12 AC 28 ms
25,716 KB
testcase_13 AC 26 ms
23,744 KB
testcase_14 AC 27 ms
23,484 KB
testcase_15 AC 29 ms
23,832 KB
testcase_16 AC 28 ms
25,656 KB
testcase_17 AC 26 ms
23,748 KB
testcase_18 AC 26 ms
23,752 KB
testcase_19 AC 27 ms
23,984 KB
testcase_20 AC 25 ms
21,812 KB
testcase_21 AC 25 ms
23,744 KB
testcase_22 AC 28 ms
23,560 KB
testcase_23 AC 28 ms
23,692 KB
testcase_24 AC 29 ms
25,600 KB
testcase_25 AC 27 ms
25,656 KB
testcase_26 WA -
testcase_27 AC 26 ms
24,000 KB
testcase_28 AC 28 ms
23,884 KB
testcase_29 AC 27 ms
23,744 KB
testcase_30 AC 26 ms
25,920 KB
testcase_31 AC 27 ms
25,580 KB
testcase_32 AC 26 ms
23,596 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;
            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