結果

問題 No.3 ビットすごろく
ユーザー outoforderoutoforder
提出日時 2017-07-22 22:25:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 2,020 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 105,320 KB
実行使用メモリ 24,804 KB
最終ジャッジ日時 2023-09-14 00:47:12
合計ジャッジ時間 5,531 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,732 KB
testcase_01 AC 60 ms
24,704 KB
testcase_02 AC 61 ms
22,768 KB
testcase_03 AC 63 ms
24,704 KB
testcase_04 AC 59 ms
22,732 KB
testcase_05 AC 63 ms
24,800 KB
testcase_06 AC 61 ms
22,860 KB
testcase_07 AC 59 ms
22,712 KB
testcase_08 AC 64 ms
24,804 KB
testcase_09 AC 64 ms
22,816 KB
testcase_10 AC 64 ms
22,800 KB
testcase_11 AC 62 ms
22,812 KB
testcase_12 AC 62 ms
22,728 KB
testcase_13 AC 61 ms
22,664 KB
testcase_14 AC 67 ms
24,768 KB
testcase_15 AC 64 ms
22,616 KB
testcase_16 AC 62 ms
20,716 KB
testcase_17 AC 61 ms
22,712 KB
testcase_18 AC 62 ms
22,732 KB
testcase_19 AC 69 ms
24,700 KB
testcase_20 AC 61 ms
20,524 KB
testcase_21 AC 58 ms
22,680 KB
testcase_22 AC 64 ms
22,628 KB
testcase_23 AC 63 ms
22,636 KB
testcase_24 AC 63 ms
20,756 KB
testcase_25 AC 66 ms
24,636 KB
testcase_26 AC 58 ms
22,652 KB
testcase_27 AC 62 ms
24,764 KB
testcase_28 AC 64 ms
20,724 KB
testcase_29 AC 62 ms
22,652 KB
testcase_30 AC 58 ms
22,768 KB
testcase_31 AC 61 ms
22,684 KB
testcase_32 AC 63 ms
24,744 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;

namespace CompetitiveProgramming
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var list = new int[n];
            for (int i = 0; i < list.Length; i++)
            {
                list[i] = Convert.ToString(i + 1, 2).Where(s => s == '1').Count();
            }

            var q = new Queue<int>();
            q.Enqueue(0);
            var history = new HashSet<int>();
            var count = 1;

            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }

            while (true)
            {
                var tmp_q = new Queue<int>();
                count++;

                while (q.Count > 0)
                {
                    var cur = q.Dequeue();
                    var move1 = cur + list[cur];
                    var move2 = cur - list[cur];

                    if(move1==list.Length-1)
                    {
                        Console.WriteLine(count);
                        return;
                    }

                    if (move1 < list.Length)
                    {
                        if (!history.Contains(move1))
                        {
                            tmp_q.Enqueue(move1);
                            history.Add(move1);
                        }
                    }
                    if (0 <= move2)
                    {
                        if (!history.Contains(move2))
                        {
                            tmp_q.Enqueue(move2);
                            history.Add(move2);
                        }
                    }
                }
                q.Clear();
                q = tmp_q;

                if (count >= list.Length)
                {
                    Console.WriteLine(-1);
                    break;
                }
            }
        }
    }
}
0