結果

問題 No.3 ビットすごろく
ユーザー pirorirori_n712pirorirori_n712
提出日時 2018-10-18 02:07:14
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,132 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 104,832 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-04-20 22:24:57
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 23 ms
18,688 KB
testcase_03 AC 23 ms
18,432 KB
testcase_04 WA -
testcase_05 AC 23 ms
18,688 KB
testcase_06 AC 23 ms
18,432 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 23 ms
18,432 KB
testcase_13 AC 22 ms
18,432 KB
testcase_14 AC 23 ms
18,432 KB
testcase_15 AC 22 ms
18,560 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 23 ms
18,432 KB
testcase_23 AC 23 ms
18,560 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 23 ms
18,176 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.Linq;
using System.Collections.Generic;

class No3
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var array = new int[N];
        for (int i = 0; i < N; ++i) array[i] = -1;
        array[0] = 1;
        var list = new Queue<int>();
        list.Enqueue(0);

        while (list.Count>0)
        {
            var u = list.Dequeue();
           
            var b = GetBit(u);
            if ((u + b) < N && array[u + b] == -1)
            {
                list.Enqueue(u + b);
                array[u + b] = array[u] + 1;
            }
            if (-1 < (u - b) && array[u - b] == -1)
            {
                list.Enqueue(u - b);
                array[u - b] = array[u] + 1;
            }
        }
        Console.WriteLine(array[N - 1]);
    }

    //二進数に直す
    static int GetBit(int num)
    {
        var list = new List<int>();
        while (num != 0 && num != 1)
        {
            if (num % 2 == 1) list.Add(1);
            else list.Add(0);
            num /= 2;
        }
        list.Add(num);
        return list.Sum();
    }
}
0