結果

問題 No.3 ビットすごろく
ユーザー y-ty-t
提出日時 2018-08-10 13:38:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,094 bytes
コンパイル時間 2,877 ms
コンパイル使用メモリ 103,628 KB
実行使用メモリ 22,896 KB
最終ジャッジ日時 2023-09-14 01:04:54
合計ジャッジ時間 5,349 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
22,796 KB
testcase_01 AC 55 ms
20,752 KB
testcase_02 AC 57 ms
22,772 KB
testcase_03 AC 56 ms
20,936 KB
testcase_04 AC 56 ms
20,692 KB
testcase_05 AC 57 ms
22,792 KB
testcase_06 AC 56 ms
20,664 KB
testcase_07 AC 56 ms
22,796 KB
testcase_08 AC 56 ms
22,756 KB
testcase_09 AC 57 ms
22,792 KB
testcase_10 AC 57 ms
22,824 KB
testcase_11 AC 56 ms
22,772 KB
testcase_12 AC 57 ms
20,728 KB
testcase_13 AC 56 ms
18,752 KB
testcase_14 AC 57 ms
22,896 KB
testcase_15 AC 56 ms
20,652 KB
testcase_16 AC 56 ms
20,836 KB
testcase_17 AC 56 ms
22,852 KB
testcase_18 AC 56 ms
20,744 KB
testcase_19 AC 56 ms
20,720 KB
testcase_20 AC 57 ms
22,764 KB
testcase_21 AC 56 ms
20,768 KB
testcase_22 AC 57 ms
22,808 KB
testcase_23 AC 58 ms
20,760 KB
testcase_24 AC 57 ms
22,748 KB
testcase_25 AC 57 ms
22,772 KB
testcase_26 AC 56 ms
20,928 KB
testcase_27 AC 56 ms
20,768 KB
testcase_28 AC 56 ms
20,752 KB
testcase_29 AC 58 ms
20,828 KB
testcase_30 AC 56 ms
20,728 KB
testcase_31 AC 57 ms
22,860 KB
testcase_32 AC 56 ms
20,780 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.Collections;

class Program
{
    static int N;
    static int[] Map = new int[10001];
    static void Main(string[] args)
    {
        N = int.Parse(Console.ReadLine());

        Map[1] = 1;
        Move();
        Console.WriteLine(Map[N] != 0 ? Map[N] : -1);
    }

    static void Move()
    {
        Queue q = new Queue();
        q.Enqueue(1);
        while(q.Count != 0)
        {
            int n = (int)q.Dequeue();
            int bit = BitCount(n);

            if (n + bit <= N && Map[n + bit] == 0)
            {
                Map[n + bit] = Map[n] + 1;
                q.Enqueue(n + bit);
            }

            if (0 < n - bit && Map[n - bit] == 0)
            {
                Map[n - bit] = Map[n] + 1;
                q.Enqueue(n - bit);
            }
        }
        
    }

    static int BitCount(int i)
    {
        i = i - ((i >> 1) & 0x55555555);
        i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
        i = (i + (i >> 4)) & 0x0f0f0f0f;
        i = i + (i >> 8);
        i = i + (i >> 16);
        return i & 0x3f;
    }
}
0