結果

問題 No.3 ビットすごろく
ユーザー kishida.shinyakishida.shinya
提出日時 2018-06-28 13:52:31
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,844 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 100,084 KB
実行使用メモリ 24,892 KB
最終ジャッジ日時 2023-09-13 14:44:49
合計ジャッジ時間 4,958 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
20,692 KB
testcase_01 AC 53 ms
20,636 KB
testcase_02 AC 53 ms
20,652 KB
testcase_03 AC 54 ms
20,756 KB
testcase_04 WA -
testcase_05 AC 54 ms
22,700 KB
testcase_06 AC 54 ms
20,776 KB
testcase_07 AC 53 ms
20,760 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 53 ms
18,672 KB
testcase_13 AC 54 ms
22,764 KB
testcase_14 AC 53 ms
22,696 KB
testcase_15 AC 52 ms
20,732 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 52 ms
18,668 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 53 ms
20,640 KB
testcase_22 AC 53 ms
20,732 KB
testcase_23 AC 54 ms
22,776 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
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;
using System.Text;
using System.Threading.Tasks;

namespace bitscreen
{
    class Program
    {

        static int modoru(int cur, int goal, ref int step_counter, ref int modoru_counter)
        {
            int modoru_num = bitCounter(cur);
            modoru_num = cur - modoru_num;
            int ret = 0;

            if (modoru_num < 0)
            {
                modoru_counter++;
                return -2;
            }
            else if (modoru_num == goal)
            {
                step_counter++;
                return 0;
            }
            else
            {
                step_counter++;
                modoru_counter++;

                ret = susumu(modoru_num, goal, ref step_counter, ref modoru_counter);
                if(ret != 0)
                {
                    return -2;
                }
                return ret;
            }
        }

        static int susumu(int cur, int goal, ref int step_counter, ref int modoru_counter)
        {
            int susumu_num = bitCounter(cur);
            susumu_num += cur;
            if(susumu_num > goal)
            {
                return -1;
            }
            else if (susumu_num == goal)
            {
                step_counter++;
                return 0;
            }
            else
            {
                step_counter++;
                int ret;
                if (susumu_num == 0) susumu_num++;
                ret = susumu(susumu_num, goal, ref step_counter, ref modoru_counter);
                if (ret == -1)
                {
                    if(modoru_counter == 1)
                    {
                        return -1;
                    }
                    ret = modoru(susumu_num, goal, ref step_counter, ref modoru_counter);
                    if (ret == -2)
                    {
                        return -3;
                    }
                }
                return ret;
            }
        }

        static int bitCounter(int n)
        {
            int bitmask = 0x00000001;
            int data = n;
            int count = 0;
            for (int j = 0; j < 32; j++)
            {
                if ((data & bitmask) == 1) count++;
                data = data >> 1;
            }
            return count;
        }

        static void Main(string[] args)
        {
                       string s = Console.ReadLine();

           int step_counter = 0;
            int ret = 0;
            int modoru_counter = 0;

            ret = susumu(0,int.Parse(s), ref step_counter, ref modoru_counter);


            if (ret == 0)
            {
                Console.WriteLine(step_counter);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}
0