結果

問題 No.3 ビットすごろく
ユーザー AreTrashAreTrash
提出日時 2016-04-09 03:43:52
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,127 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 112,464 KB
実行使用メモリ 26,220 KB
最終ジャッジ日時 2024-04-14 23:31:20
合計ジャッジ時間 4,294 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
21,680 KB
testcase_01 AC 24 ms
23,792 KB
testcase_02 AC 24 ms
23,796 KB
testcase_03 AC 32 ms
23,672 KB
testcase_04 AC 26 ms
25,856 KB
testcase_05 AC 59 ms
25,748 KB
testcase_06 AC 32 ms
23,888 KB
testcase_07 AC 27 ms
25,620 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 59 ms
25,708 KB
testcase_13 AC 31 ms
23,600 KB
testcase_14 AC 104 ms
25,772 KB
testcase_15 AC 142 ms
21,936 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 30 ms
25,708 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 23 ms
23,668 KB
testcase_22 AC 107 ms
25,776 KB
testcase_23 AC 155 ms
26,048 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 22 ms
23,416 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 26 ms
25,592 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;

namespace No3_1{
    public class Program{
        private static List<int> stack = new List<int>();
        private static int min = int.MaxValue;
        public static void Main(string[] args){
            var result = Function(int.Parse(Console.ReadLine()), 1, 1);
            if(result == int.MaxValue) result = -1;
            Console.WriteLine(result);
            Console.ReadLine();
        }

        public static int Function(int input, int place, int cnt){
            if(place == input) return min = cnt;
            if(cnt >= input || cnt >= min || stack.Contains(place) || place < 1 || input < place) return int.MaxValue;
            stack.Add(place);
            var result = Math.Min(Function(input, place + BitOne(place), cnt + 1), Function(input, place - BitOne(place), cnt + 1));
            return result;
        }

        public static int BitOne(int num){
            var result = 0;
            while(true){
                if(num % 2 == 1) result++;
                if((num /= 2) == 0) break;
            }
            return result;
        }
    }
}
0