結果

問題 No.3 ビットすごろく
ユーザー AdamantiteAdamantite
提出日時 2023-06-29 21:27:51
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,161 bytes
コンパイル時間 3,859 ms
コンパイル使用メモリ 103,924 KB
実行使用メモリ 28,220 KB
最終ジャッジ日時 2023-09-20 16:28:29
合計ジャッジ時間 20,716 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,464 KB
testcase_01 AC 59 ms
21,384 KB
testcase_02 AC 58 ms
23,404 KB
testcase_03 AC 71 ms
23,568 KB
testcase_04 AC 60 ms
21,348 KB
testcase_05 AC 240 ms
27,576 KB
testcase_06 AC 72 ms
23,560 KB
testcase_07 AC 64 ms
21,408 KB
testcase_08 AC 116 ms
25,540 KB
testcase_09 AC 1,151 ms
25,628 KB
testcase_10 AC 3,068 ms
26,220 KB
testcase_11 AC 754 ms
27,912 KB
testcase_12 AC 192 ms
25,672 KB
testcase_13 AC 66 ms
21,596 KB
testcase_14 AC 2,605 ms
28,220 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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();
                if(x == n) {
                    break;
                }
                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