結果

問題 No.3 ビットすごろく
ユーザー NoNo
提出日時 2015-06-24 22:52:03
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,752 bytes
コンパイル時間 3,261 ms
コンパイル使用メモリ 103,188 KB
実行使用メモリ 27,848 KB
最終ジャッジ日時 2023-09-22 00:35:09
合計ジャッジ時間 7,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,824 KB
testcase_01 AC 59 ms
19,664 KB
testcase_02 AC 61 ms
21,588 KB
testcase_03 AC 63 ms
19,768 KB
testcase_04 WA -
testcase_05 AC 71 ms
21,652 KB
testcase_06 AC 66 ms
23,772 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 69 ms
21,624 KB
testcase_13 AC 64 ms
19,652 KB
testcase_14 AC 75 ms
25,724 KB
testcase_15 AC 79 ms
23,640 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 59 ms
23,700 KB
testcase_22 AC 73 ms
23,680 KB
testcase_23 AC 77 ms
23,704 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 58 ms
21,700 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.Linq;
using System.Text;
using System.Threading.Tasks;

namespace foryuki
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] m = new int[N + 1];
            m[1] = 1;
            for (int i = 2; i < N + 1; i++)
            {
                m[i] = -1;
            }
            var li = new List<int>();
            li.Add(1);

            while (li.Count() != 0)
            {
                int bit = Convert.ToString(li[0], 2).Where(x => x == '1').Count();
                if (li[0] - bit >= 1)
                {
                    if (m[li[0] - bit] > m[li[0]] + 1 || m[li[0] - bit] == -1)
                    {
                        li.Add(li[0] - bit);
                        m[li[0] - bit] = m[li[0]] + 1;
                    }
                }

                if (li[0] + bit <= N)
                {
                    if (m[li[0] + bit] > m[li[0] + 1] || m[li[0] + bit] == -1)
                    {
                        li.Add(li[0] + bit);
                        m[li[0] + bit] = m[li[0]] + 1;
                    }
                }

                li.RemoveAt(0);
            }

            Console.WriteLine(m[N]);
        }

        //-------------------------------------------------------------

        static int[] ConvertStringArrayToIntArray(string[] array)
        {
            return Array.ConvertAll(array, str => int.Parse(str));
        }

        static List<int> ConvertStringArrayToIntList(string[] str)
        {
            var list = new List<int>();
            foreach (var c in str) list.Add(int.Parse(c));
            return list;
        }
    }
}
0