結果

問題 No.3 ビットすごろく
ユーザー NoNo
提出日時 2015-06-24 23:11:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 1,870 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 107,468 KB
実行使用メモリ 23,760 KB
最終ジャッジ日時 2023-09-13 23:15:07
合計ジャッジ時間 5,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,744 KB
testcase_01 AC 59 ms
21,808 KB
testcase_02 AC 63 ms
23,620 KB
testcase_03 AC 63 ms
23,760 KB
testcase_04 AC 63 ms
23,684 KB
testcase_05 AC 64 ms
23,712 KB
testcase_06 AC 63 ms
21,604 KB
testcase_07 AC 62 ms
21,716 KB
testcase_08 AC 62 ms
19,516 KB
testcase_09 AC 65 ms
23,656 KB
testcase_10 AC 66 ms
21,636 KB
testcase_11 AC 64 ms
23,636 KB
testcase_12 AC 64 ms
21,772 KB
testcase_13 AC 62 ms
21,688 KB
testcase_14 AC 66 ms
21,688 KB
testcase_15 AC 67 ms
21,568 KB
testcase_16 AC 66 ms
21,656 KB
testcase_17 AC 67 ms
21,588 KB
testcase_18 AC 62 ms
21,784 KB
testcase_19 AC 66 ms
21,684 KB
testcase_20 AC 62 ms
19,708 KB
testcase_21 AC 62 ms
21,812 KB
testcase_22 AC 66 ms
21,676 KB
testcase_23 AC 67 ms
21,664 KB
testcase_24 AC 67 ms
21,720 KB
testcase_25 AC 67 ms
21,624 KB
testcase_26 AC 61 ms
21,588 KB
testcase_27 AC 64 ms
23,648 KB
testcase_28 AC 66 ms
21,748 KB
testcase_29 AC 64 ms
23,672 KB
testcase_30 AC 60 ms
19,536 KB
testcase_31 AC 62 ms
23,688 KB
testcase_32 AC 64 ms
21,676 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.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] = int.MaxValue;
            }
            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)
                    {
                        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)
                    {
                        li.Add(li[0] + bit);
                        m[li[0] + bit] = m[li[0]] + 1;
                    }
                }

                li.RemoveAt(0);
            }

            if (m[N] == int.MaxValue)
            {
                Console.WriteLine(-1);
            }
            else
            {
                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