結果

問題 No.3 ビットすごろく
ユーザー masaktmasakt
提出日時 2017-03-26 18:55:26
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 104,060 KB
実行使用メモリ 23,924 KB
最終ジャッジ日時 2023-09-20 11:05:55
合計ジャッジ時間 7,559 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
23,580 KB
testcase_01 AC 59 ms
23,600 KB
testcase_02 AC 58 ms
21,520 KB
testcase_03 AC 71 ms
23,620 KB
testcase_04 AC 61 ms
21,492 KB
testcase_05 AC 111 ms
21,808 KB
testcase_06 AC 73 ms
23,632 KB
testcase_07 AC 64 ms
19,616 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 107 ms
21,632 KB
testcase_13 AC 67 ms
21,528 KB
testcase_14 AC 173 ms
21,784 KB
testcase_15 AC 234 ms
21,812 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 66 ms
21,616 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 59 ms
21,604 KB
testcase_22 AC 176 ms
21,692 KB
testcase_23 AC 241 ms
23,696 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 57 ms
21,612 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 60 ms
21,488 KB
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;

class P
{
    static void DepthFirstSearch(int goal)
    {
        int x = path[path.Count - 1];
        int step = Convert.ToString(x, 2).Replace("0", "").Length;
        if (x == goal)
        {
            result.Add(path.Count);
        }
        else
        {
            int post = x + step;
            if (!path.Contains(post) && 1 <= post && post <= goal)
            {
                path.Add(post);
                DepthFirstSearch(goal);
            }

            int pre = x - step;
            if (!path.Contains(pre) && 1 <= pre && pre <= goal)
            {
                path.Add(pre);
                DepthFirstSearch(goal);
            }
        }
    }

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

    static void Main()
    {
        DepthFirstSearch(int.Parse(Console.ReadLine()));
        Console.WriteLine(result.Count == 0 ? -1 : result.Min());
    }
}
0