結果

問題 No.3 ビットすごろく
ユーザー AdamantiteAdamantite
提出日時 2023-06-29 21:33:41
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 725 ms / 5,000 ms
コード長 1,357 bytes
コンパイル時間 8,607 ms
コンパイル使用メモリ 148,172 KB
実行使用メモリ 164,564 KB
最終ジャッジ日時 2023-09-20 16:34:32
合計ジャッジ時間 17,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
28,524 KB
testcase_01 AC 52 ms
28,472 KB
testcase_02 AC 52 ms
28,672 KB
testcase_03 AC 53 ms
28,672 KB
testcase_04 AC 52 ms
28,560 KB
testcase_05 AC 69 ms
28,752 KB
testcase_06 AC 54 ms
28,560 KB
testcase_07 AC 53 ms
28,692 KB
testcase_08 AC 59 ms
30,560 KB
testcase_09 AC 149 ms
29,016 KB
testcase_10 AC 310 ms
29,560 KB
testcase_11 AC 112 ms
31,152 KB
testcase_12 AC 66 ms
30,644 KB
testcase_13 AC 53 ms
28,696 KB
testcase_14 AC 270 ms
29,568 KB
testcase_15 AC 632 ms
30,724 KB
testcase_16 AC 385 ms
29,752 KB
testcase_17 AC 568 ms
30,584 KB
testcase_18 AC 53 ms
28,524 KB
testcase_19 AC 716 ms
32,816 KB
testcase_20 AC 52 ms
28,416 KB
testcase_21 AC 53 ms
30,676 KB
testcase_22 AC 281 ms
29,596 KB
testcase_23 AC 725 ms
32,564 KB
testcase_24 AC 722 ms
34,804 KB
testcase_25 AC 631 ms
30,552 KB
testcase_26 AC 52 ms
28,796 KB
testcase_27 AC 53 ms
28,564 KB
testcase_28 AC 364 ms
29,740 KB
testcase_29 AC 115 ms
29,036 KB
testcase_30 AC 52 ms
28,532 KB
testcase_31 AC 53 ms
30,572 KB
testcase_32 AC 91 ms
164,564 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 158 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;

namespace No00003_BitSugoroku
{
    internal class Program
    {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());

            int[] map = new int[n + 1];
            map[1] = 1;
            Queue<int> q = new Queue<int>();
            q.Enqueue(1);

            while (0 < q.Count) {
                int x = q.Dequeue();
                if(x == n) {
                    break;
                }
                int diff = BitCount(x);

                if (x + diff <= n) {
                    if (map[x + diff] == 0 || map[x] < map[x + diff]) {
                        q.Enqueue(x + diff);
                        map[x + diff] = map[x] + 1;
                    }
                }
                if (0 < x - diff) {
                    if (map[x - diff] == 0 || map[x] < map[x - diff]) {
                        q.Enqueue(x - diff);
                        map[x - diff] = map[x] + 1;
                    }
                }
            }
            Console.WriteLine(map[n] == 0 ? -1: map[n]);
        }

        static int BitCount(int x) {
            int count = 0;
            while (0 < x) {
                if(x % 2 == 1) {
                    count++;
                }
                x /= 2;
            }
            return count;
        }
    }
}
0