結果

問題 No.3 ビットすごろく
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-07-25 09:03:26
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 1,042 bytes
コンパイル時間 7,230 ms
コンパイル使用メモリ 169,960 KB
実行使用メモリ 186,100 KB
最終ジャッジ日時 2024-04-10 02:17:27
合計ジャッジ時間 10,149 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
29,952 KB
testcase_01 AC 51 ms
30,080 KB
testcase_02 AC 52 ms
29,952 KB
testcase_03 AC 52 ms
30,456 KB
testcase_04 AC 52 ms
30,208 KB
testcase_05 AC 52 ms
30,592 KB
testcase_06 AC 52 ms
30,592 KB
testcase_07 AC 51 ms
30,328 KB
testcase_08 AC 52 ms
30,336 KB
testcase_09 AC 53 ms
30,592 KB
testcase_10 AC 53 ms
31,104 KB
testcase_11 AC 54 ms
30,848 KB
testcase_12 AC 53 ms
30,464 KB
testcase_13 AC 51 ms
30,436 KB
testcase_14 AC 53 ms
30,976 KB
testcase_15 AC 55 ms
31,232 KB
testcase_16 AC 54 ms
30,976 KB
testcase_17 AC 54 ms
31,360 KB
testcase_18 AC 51 ms
30,444 KB
testcase_19 AC 66 ms
32,384 KB
testcase_20 AC 51 ms
30,336 KB
testcase_21 AC 51 ms
30,464 KB
testcase_22 AC 54 ms
30,964 KB
testcase_23 AC 54 ms
31,084 KB
testcase_24 AC 66 ms
32,512 KB
testcase_25 AC 54 ms
30,976 KB
testcase_26 AC 51 ms
29,952 KB
testcase_27 AC 51 ms
30,204 KB
testcase_28 AC 54 ms
31,104 KB
testcase_29 AC 54 ms
30,848 KB
testcase_30 AC 52 ms
30,208 KB
testcase_31 AC 51 ms
30,208 KB
testcase_32 AC 54 ms
186,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (91 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace yukicoder
{
    public class Program
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = new int[n];
            var b = new int[n];
            var c = new Queue<int>();
            for (var i = 0; i < n; i++)
            {
                a[i] = Convert.ToString(i + 1, 2).Count(m => m == '1');
                b[i] = -1;
            }
            c.Enqueue(0);
            b[0] = 1;
            while (c.Count > 0)
            {
                var k = c.Dequeue();
                if (k + a[k] < n && b[k + a[k]] == -1)
                {
                    c.Enqueue(k + a[k]);
                    b[k + a[k]] = b[k] + 1;
                }
                if (k - a[k] >= 0 && b[k - a[k]] == -1)
                {
                    c.Enqueue(k - a[k]);
                    b[k - a[k]] = b[k] + 1;
                }
            }
            Console.WriteLine(b[n - 1]);
        }
    }
}
0