結果

問題 No.3 ビットすごろく
ユーザー pirorirori_n712pirorirori_n712
提出日時 2018-10-18 02:08:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 1,134 bytes
コンパイル時間 4,917 ms
コンパイル使用メモリ 106,008 KB
実行使用メモリ 25,652 KB
最終ジャッジ日時 2023-09-14 01:08:56
合計ジャッジ時間 6,232 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
21,420 KB
testcase_01 AC 55 ms
21,388 KB
testcase_02 AC 59 ms
21,324 KB
testcase_03 AC 61 ms
23,592 KB
testcase_04 AC 60 ms
19,272 KB
testcase_05 AC 60 ms
21,560 KB
testcase_06 AC 58 ms
19,600 KB
testcase_07 AC 59 ms
21,452 KB
testcase_08 AC 60 ms
21,604 KB
testcase_09 AC 60 ms
21,500 KB
testcase_10 AC 60 ms
21,452 KB
testcase_11 AC 58 ms
23,560 KB
testcase_12 AC 60 ms
23,664 KB
testcase_13 AC 57 ms
21,468 KB
testcase_14 AC 61 ms
21,556 KB
testcase_15 AC 63 ms
23,732 KB
testcase_16 AC 62 ms
23,676 KB
testcase_17 AC 63 ms
23,684 KB
testcase_18 AC 57 ms
19,348 KB
testcase_19 AC 61 ms
25,652 KB
testcase_20 AC 56 ms
21,460 KB
testcase_21 AC 57 ms
21,664 KB
testcase_22 AC 61 ms
21,464 KB
testcase_23 AC 63 ms
25,544 KB
testcase_24 AC 61 ms
25,408 KB
testcase_25 AC 61 ms
23,484 KB
testcase_26 AC 54 ms
21,316 KB
testcase_27 AC 61 ms
23,596 KB
testcase_28 AC 60 ms
21,544 KB
testcase_29 AC 58 ms
23,496 KB
testcase_30 AC 56 ms
21,436 KB
testcase_31 AC 57 ms
23,540 KB
testcase_32 AC 59 ms
21,624 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;
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+1);
            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