結果

問題 No.3 ビットすごろく
ユーザー AdamantiteAdamantite
提出日時 2023-06-29 21:17:46
言語 C#
(.NET 8.0.203)
結果
TLE  
実行時間 -
コード長 1,087 bytes
コンパイル時間 10,920 ms
コンパイル使用メモリ 145,544 KB
実行使用メモリ 188,108 KB
最終ジャッジ日時 2023-09-20 16:18:21
合計ジャッジ時間 40,548 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
31,280 KB
testcase_01 AC 51 ms
29,212 KB
testcase_02 AC 51 ms
29,104 KB
testcase_03 AC 64 ms
31,388 KB
testcase_04 AC 54 ms
29,388 KB
testcase_05 AC 205 ms
52,424 KB
testcase_06 AC 65 ms
31,616 KB
testcase_07 AC 58 ms
30,204 KB
testcase_08 AC 104 ms
39,692 KB
testcase_09 AC 973 ms
55,140 KB
testcase_10 AC 2,383 ms
53,596 KB
testcase_11 AC 596 ms
54,852 KB
testcase_12 AC 176 ms
54,208 KB
testcase_13 AC 59 ms
30,860 KB
testcase_14 AC 2,020 ms
55,608 KB
testcase_15 TLE -
testcase_16 AC 3,079 ms
55,704 KB
testcase_17 AC 4,750 ms
56,760 KB
testcase_18 AC 59 ms
30,320 KB
testcase_19 TLE -
testcase_20 AC 54 ms
29,436 KB
testcase_21 AC 53 ms
31,080 KB
testcase_22 AC 2,113 ms
57,972 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 53 ms
31,256 KB
testcase_27 AC 61 ms
31,232 KB
testcase_28 AC 2,891 ms
57,680 KB
testcase_29 AC 623 ms
55,136 KB
testcase_30 AC 51 ms
31,056 KB
testcase_31 AC 52 ms
31,060 KB
testcase_32 AC 400 ms
188,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 157 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;
using System.Linq;

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();
                int diff = Convert.ToString(x, 2).Count(x => x == '1');

                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]);
        }
    }
}
0