結果

問題 No.3 ビットすごろく
ユーザー ototonariototonari
提出日時 2017-03-18 02:16:19
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,666 bytes
コンパイル時間 3,985 ms
コンパイル使用メモリ 105,084 KB
実行使用メモリ 22,960 KB
最終ジャッジ日時 2023-09-17 19:35:28
合計ジャッジ時間 6,056 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,876 KB
testcase_01 AC 57 ms
20,904 KB
testcase_02 AC 57 ms
20,752 KB
testcase_03 AC 58 ms
22,768 KB
testcase_04 AC 57 ms
22,664 KB
testcase_05 AC 59 ms
22,848 KB
testcase_06 AC 57 ms
20,680 KB
testcase_07 AC 57 ms
20,904 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 59 ms
22,796 KB
testcase_13 AC 57 ms
20,732 KB
testcase_14 AC 59 ms
20,844 KB
testcase_15 AC 60 ms
22,836 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 57 ms
20,840 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 58 ms
22,732 KB
testcase_22 AC 59 ms
20,704 KB
testcase_23 AC 60 ms
20,924 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 57 ms
22,868 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 57 ms
22,844 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;
using System.Text;
using System.Threading.Tasks;

namespace yukicoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int c = 1;
            int pos = 1;
            int[] flag = new int[N];
            foreach(int i in flag)
            {
                flag[i] = 0;
            }
            flag[0] = 1;
            while(pos != N)
            {
                //進む場合N以下になるかどうか
                if ((pos + bits(pos)) <= N)
                {
                    flag[pos] = 1;
                    pos += bits(pos);
                    c++;
                }
                else //戻る処理
                {
                    //戻るところが前の所の場合
                    if (flag[pos - bits(pos)] == 1)
                    {
                        Console.WriteLine("{0}", "-1");
                        break;
                    }

                    flag[pos] = 1;
                    pos -= bits(pos);
                    c++;
                }
            }

            if (pos == N) Console.WriteLine("{0}", c);
            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;
        }



    }
}
0