結果

問題 No.3 ビットすごろく
ユーザー masaktmasakt
提出日時 2017-03-26 20:08:21
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,245 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 103,692 KB
実行使用メモリ 21,572 KB
最終ジャッジ日時 2023-09-20 11:06:40
合計ジャッジ時間 8,717 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,572 KB
testcase_01 AC 60 ms
21,440 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class P
{
    static int Search(int goal)
    {
        int x = path.Last();
        int step = Convert.ToString(x, 2).Replace("0", "").Length;
        int post = x + step;
        int pre = x - step;
        path.Add(post);

        while (path.Count != 0)
        {
            if (x == goal)
            {
                path.Add(goal);
                return path.Count;
            }
            else
            {
                x = path.Last();
                step = Convert.ToString(x, 2).Replace("0", "").Length;
                post = x + step;
                pre = x - step;

                if (!path.Contains(post) && 1 <= post && post <= goal)
                {
                    path.Add(post);
                }
                else if (!path.Contains(pre) && 1 <= pre && pre <= goal)
                {
                    path.Add(pre);
                }
                else
                {
                    path.Remove(x);
                }
            }
        }
        return  -1;
    }

    static List<int> path = new List<int>() { 1 };

    static void Main()
    {
        Console.WriteLine(Search(int.Parse(Console.ReadLine())));
    }
}
0