結果

問題 No.3 ビットすごろく
ユーザー masaktmasakt
提出日時 2017-04-02 21:49:44
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,694 bytes
コンパイル時間 3,127 ms
コンパイル使用メモリ 103,480 KB
実行使用メモリ 25,384 KB
最終ジャッジ日時 2023-09-22 07:47:59
合計ジャッジ時間 5,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 62 ms
21,392 KB
testcase_03 AC 62 ms
21,292 KB
testcase_04 WA -
testcase_05 AC 64 ms
21,416 KB
testcase_06 AC 62 ms
21,396 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 62 ms
23,340 KB
testcase_13 AC 62 ms
21,384 KB
testcase_14 AC 63 ms
23,400 KB
testcase_15 AC 62 ms
21,428 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 62 ms
21,480 KB
testcase_22 AC 62 ms
23,456 KB
testcase_23 AC 62 ms
21,348 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 56 ms
21,424 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;

class P
{
    static int Search(int goal)
    {
        int x = 1;
        int c = 1;
        int step = 1;
        Tuple<int, int> post;
        Tuple<int, int> pre;
        path.Add(Tuple.Create(x,c));

        if (x == goal)
        {
            return 1;
        }

        while (path.Count != 0)
        {
            if (x < c)
            {
                break;
            }
            else if (x == goal)
            {
                return c;
            }
            else
            {
                Tuple<int, int> t = path.Last();
                x = t.Item1;
                c = t.Item2;
                step = Convert.ToString(x, 2).Replace("0", "").Length;
                post = Tuple.Create(x + step, c + 1);
                pre = Tuple.Create(x - step, c + 1);
                if (1 <= post.Item1 && post.Item1 <= goal)
                {
                    if (path.Contains(post))
                    {
                    }
                    else
                    {
                        path.Add(post);
                    }
                }
                if (1 <= pre.Item1 && pre.Item1 <= goal)
                {
                    if (path.Contains(pre))
                    {
                    }
                    else
                    {
                        path.Add(pre);
                    }
                }
                path.Remove(t);
            }
        }
        return -1;
    }

    static List<Tuple<int, int>> path = new List<Tuple<int, int>>();

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