結果

問題 No.3 ビットすごろく
ユーザー oemonoemon
提出日時 2016-11-27 22:21:26
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 1,114 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 105,052 KB
実行使用メモリ 23,828 KB
最終ジャッジ日時 2023-09-14 00:13:27
合計ジャッジ時間 5,694 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
23,708 KB
testcase_01 AC 59 ms
23,696 KB
testcase_02 AC 59 ms
21,744 KB
testcase_03 AC 61 ms
19,632 KB
testcase_04 AC 62 ms
21,844 KB
testcase_05 AC 63 ms
21,832 KB
testcase_06 AC 61 ms
21,568 KB
testcase_07 AC 60 ms
21,572 KB
testcase_08 AC 62 ms
21,656 KB
testcase_09 AC 64 ms
21,868 KB
testcase_10 AC 67 ms
21,924 KB
testcase_11 AC 63 ms
21,748 KB
testcase_12 AC 63 ms
21,700 KB
testcase_13 AC 60 ms
23,828 KB
testcase_14 AC 67 ms
19,696 KB
testcase_15 AC 71 ms
21,740 KB
testcase_16 AC 70 ms
21,716 KB
testcase_17 AC 69 ms
21,696 KB
testcase_18 AC 60 ms
21,660 KB
testcase_19 AC 69 ms
21,640 KB
testcase_20 AC 59 ms
21,668 KB
testcase_21 AC 60 ms
23,712 KB
testcase_22 AC 67 ms
21,548 KB
testcase_23 AC 70 ms
21,800 KB
testcase_24 AC 71 ms
23,720 KB
testcase_25 AC 71 ms
23,692 KB
testcase_26 AC 60 ms
23,656 KB
testcase_27 AC 61 ms
23,652 KB
testcase_28 AC 69 ms
21,760 KB
testcase_29 AC 68 ms
23,544 KB
testcase_30 AC 61 ms
21,764 KB
testcase_31 AC 61 ms
21,576 KB
testcase_32 AC 64 ms
21,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

namespace No3
{
    class Program
    {
        private static int N;
        private static int[] map;

        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            map = Enumerable.Repeat(-1, N).ToArray();

            Rec(0, 0);
            Console.Write(map.Last());
        }

        static void Rec(int index, int preventCount)
        {
            if (index < 0) return;
            if (index >= N) return;
            if (map[index] != -1
                && map[index] <= preventCount + 1) return;

            map[index] = preventCount + 1;
            if (index == N - 1) return;

            var bitcount = BitCount(index + 1);

            Rec(index + bitcount, preventCount + 1);
            Rec(index - bitcount, preventCount + 1);
        }

        static int BitCount(int value)
        {
            var count = 0;
            for (var i = 0; i < 32; i++)
            {
                var tmp = 1 << i;
                if ((value & tmp) != 0) count++;
            }

            return count;
        }
    }
}
0