結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-07-01 15:29:04 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,835 bytes | 
| コンパイル時間 | 860 ms | 
| コンパイル使用メモリ | 108,244 KB | 
| 実行使用メモリ | 28,136 KB | 
| 最終ジャッジ日時 | 2024-10-05 03:54:11 | 
| 合計ジャッジ時間 | 2,619 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 WA * 22 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
                        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);
        }
    }
}
            
            
            
        