結果

問題 No.3 ビットすごろく
ユーザー ototonariototonari
提出日時 2017-03-18 03:31:24
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,871 bytes
コンパイル時間 2,524 ms
コンパイル使用メモリ 100,344 KB
実行使用メモリ 29,068 KB
最終ジャッジ日時 2023-09-17 20:00:51
合計ジャッジ時間 5,925 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,644 KB
testcase_01 AC 58 ms
22,712 KB
testcase_02 AC 59 ms
22,796 KB
testcase_03 AC 64 ms
22,796 KB
testcase_04 WA -
testcase_05 AC 74 ms
26,972 KB
testcase_06 AC 66 ms
22,896 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 72 ms
25,144 KB
testcase_13 AC 63 ms
22,748 KB
testcase_14 AC 82 ms
24,968 KB
testcase_15 AC 86 ms
25,048 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 59 ms
22,668 KB
testcase_22 AC 82 ms
25,116 KB
testcase_23 AC 87 ms
25,072 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 58 ms
20,616 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;
using System.Text;
using System.Threading.Tasks;

namespace yukicoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int pos = 1;int c = 0;
            int[] flag = new int[N + 1];
            foreach(int i in flag)
            {
                flag[i] = 0;
            }
            Console.WriteLine("{0}", checker(ref flag,pos, c, N));
            Console.ReadLine();
        }

        //10進数を2進数にした時の1ビットの数を返す関数
        static int bits(int num)
        {
            string bits = "";
            for(int i = num;0 < i;i /= 2)
            {
                if (i % 2 == 1) bits += (i % 2);
            }
            return num = bits.Length;
        }

        //再帰処理 cを返す
        static int checker(ref int[] flag, int pos, int c, int N)
        {
            while (flag[pos] == 0)
            {
                flag[pos] = 1;
                c++;;
                if (pos == N) return c;

                int l = -1;int r = -1;
                if(0 < (pos - bits(pos)))
                {
                    l = checker(ref flag, pos - bits(pos), c, N);
                }
                if((pos + bits(pos)) <= N)
                {
                    r = checker(ref flag, pos + bits(pos), c, N);
                }
                
                if(l != -1)
                {
                    return l;
                }else if(r != -1)
                {
                    return r;
                }
                else
                {
                    return -1;
                }

                
            }
            return -1;
        }

    }
}
0