結果

問題 No.3 ビットすごろく
ユーザー ProgramingWeProgramingWe
提出日時 2017-10-31 11:06:20
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 1,712 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 107,440 KB
実行使用メモリ 24,928 KB
最終ジャッジ日時 2023-09-14 00:50:20
合計ジャッジ時間 5,478 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,820 KB
testcase_01 AC 56 ms
20,644 KB
testcase_02 AC 57 ms
20,776 KB
testcase_03 AC 59 ms
22,764 KB
testcase_04 AC 58 ms
22,832 KB
testcase_05 AC 61 ms
22,784 KB
testcase_06 AC 60 ms
20,832 KB
testcase_07 AC 58 ms
20,736 KB
testcase_08 AC 60 ms
20,828 KB
testcase_09 AC 62 ms
22,868 KB
testcase_10 AC 64 ms
22,908 KB
testcase_11 AC 62 ms
22,836 KB
testcase_12 AC 63 ms
22,796 KB
testcase_13 AC 60 ms
22,860 KB
testcase_14 AC 64 ms
24,928 KB
testcase_15 AC 65 ms
22,844 KB
testcase_16 AC 65 ms
24,884 KB
testcase_17 AC 64 ms
24,904 KB
testcase_18 AC 60 ms
20,792 KB
testcase_19 AC 65 ms
24,844 KB
testcase_20 AC 59 ms
20,900 KB
testcase_21 AC 58 ms
20,772 KB
testcase_22 AC 64 ms
22,708 KB
testcase_23 AC 65 ms
22,792 KB
testcase_24 AC 65 ms
22,832 KB
testcase_25 AC 63 ms
22,776 KB
testcase_26 AC 57 ms
20,828 KB
testcase_27 AC 59 ms
22,772 KB
testcase_28 AC 64 ms
24,816 KB
testcase_29 AC 63 ms
22,888 KB
testcase_30 AC 58 ms
20,664 KB
testcase_31 AC 59 ms
18,796 KB
testcase_32 AC 62 ms
22,828 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;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] map = new int[N + 1];
            map[1] = 1;
            Queue<int> q = new Queue<int>();
            q.Enqueue(1);
            while (q.Count > 0)
            {
                int count = 0;
                int search = q.Dequeue();
                int step = map[search];
                string strR = Convert.ToString(search, 2);
                char[] cR = new char[strR.Length];
                for (int i = 0; i < strR.Length; i++)
                {
                    cR[i] = strR[i];
                }

                for (int i = 0; i < cR.Length; i++)
                {
                    if (cR[i].ToString() == "1")
                    {
                        count++;
                    }
                }
                int[] node = new int[2];
                node[0] = search - count;
                node[1] = search + count;

                foreach (int next in node)
                {
                    if (1 >= next || next > N)
                    {
                        continue;
                    }
                    if (map[next] == 0 || map[next] > step + 1)
                    {
                        map[next] = step + 1;
                        q.Enqueue(next);
                    }
                }
            }
            if (map[N] == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(map[N]);
            }
        }
    }
}
0