結果

問題 No.3 ビットすごろく
ユーザー ProgramingWeProgramingWe
提出日時 2017-10-31 08:59:41
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,020 bytes
コンパイル時間 1,973 ms
コンパイル使用メモリ 103,548 KB
実行使用メモリ 24,956 KB
最終ジャッジ日時 2023-08-14 12:37:07
合計ジャッジ時間 7,800 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,868 KB
testcase_01 AC 51 ms
22,716 KB
testcase_02 AC 51 ms
22,920 KB
testcase_03 AC 61 ms
20,784 KB
testcase_04 WA -
testcase_05 AC 108 ms
20,700 KB
testcase_06 AC 68 ms
20,784 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 106 ms
22,752 KB
testcase_13 AC 61 ms
22,880 KB
testcase_14 AC 178 ms
22,864 KB
testcase_15 AC 238 ms
22,848 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 51 ms
22,788 KB
testcase_22 AC 180 ms
22,780 KB
testcase_23 AC 244 ms
22,904 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 51 ms
20,664 KB
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;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int> queue = new List<int>();
            List<int> al = new List<int>();
            List<int> visit = new List<int>();
            int R = 1;
            al.Add(R);
            queue.Add(R);
            visit.Add(R);
            while (queue.Contains(R) && (R != N || al.Count != 0))
            {
                bool exist = false;
                string strR = Convert.ToString(R, 2);
                char[] cR = new char[strR.Length];
                for (int i = 0; i < strR.Length; i++)
                {
                    cR[i] = strR[i];
                }
                int count = 0;
                for (int i = 0; i < cR.Length; i++)
                {
                    if (cR[i].ToString() == "1")
                    {
                        count++;
                    }
                }
                int[] node = new int[2];
                node[0] = R - count;
                node[1] = R + count;
                foreach (int cnode in node)
                {
                    if (1 <= cnode && cnode <= N && !visit.Contains(cnode))
                    {
                        al.Add(cnode);
                        queue.Add(cnode);
                        visit.Add(cnode);
                        exist = true;
                    }


                }
                if (exist == false)
                {
                    queue.Remove(R);
                }
                al.Remove(R);
                if (al.Count != 0)
                {
                    R = al[0];
                }
            }
            if (R == N)
            {
                queue.Add(R);
                Console.WriteLine(queue.Count);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}
0