結果

問題 No.3 ビットすごろく
ユーザー suzusuzu
提出日時 2023-04-26 15:02:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,766 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 112,548 KB
実行使用メモリ 28,924 KB
最終ジャッジ日時 2024-04-27 17:57:18
合計ジャッジ時間 2,315 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
24,488 KB
testcase_01 AC 22 ms
24,684 KB
testcase_02 AC 21 ms
22,964 KB
testcase_03 AC 23 ms
24,468 KB
testcase_04 AC 23 ms
24,304 KB
testcase_05 AC 24 ms
24,680 KB
testcase_06 AC 22 ms
26,704 KB
testcase_07 AC 22 ms
24,500 KB
testcase_08 AC 24 ms
24,624 KB
testcase_09 AC 26 ms
26,856 KB
testcase_10 AC 24 ms
24,960 KB
testcase_11 AC 23 ms
24,684 KB
testcase_12 AC 23 ms
24,816 KB
testcase_13 AC 22 ms
24,496 KB
testcase_14 AC 24 ms
24,560 KB
testcase_15 AC 25 ms
27,000 KB
testcase_16 AC 25 ms
26,476 KB
testcase_17 AC 26 ms
26,732 KB
testcase_18 AC 23 ms
24,684 KB
testcase_19 AC 27 ms
27,016 KB
testcase_20 AC 21 ms
22,584 KB
testcase_21 AC 21 ms
24,812 KB
testcase_22 AC 24 ms
26,724 KB
testcase_23 AC 26 ms
26,504 KB
testcase_24 AC 26 ms
28,924 KB
testcase_25 AC 25 ms
26,740 KB
testcase_26 AC 19 ms
23,664 KB
testcase_27 AC 21 ms
24,436 KB
testcase_28 AC 25 ms
24,432 KB
testcase_29 AC 24 ms
26,596 KB
testcase_30 AC 23 ms
26,672 KB
testcase_31 AC 22 ms
24,496 KB
testcase_32 AC 24 ms
26,856 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;
namespace yukicoder{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var list = new Queue<int>();//幅優先探索。探索保留場所
            var moveMin = new int[N];//最短移動数保持。また、探索済みかどうか。
            var movePlace = new int[N];//移動前の場所
            
            for(int i = 0;i < N;i++)
            {
            	movePlace[i] = -1;
            	moveMin[i] = -1;
            }
            moveMin[0] = 1;
            list.Enqueue(1);
            
            while(list.Count > 0 && moveMin[N - 1] == -1)
            {
            	int explore = list.Dequeue();
            	int bitNum = bitCul(explore);
            	
            	int next = explore + bitNum;
            	if(next <= N && moveMin[next - 1] == -1)
            	{
            		moveMin[next - 1] = moveMin[explore - 1] + 1;
            		movePlace[next - 1] = explore;
            		list.Enqueue(next);
            	}
            	next = explore - bitNum;
            	if(next > 0 && moveMin[next -1] == -1)
            	{
            		moveMin[next - 1] = moveMin[explore - 1] + 1;
            		movePlace[next - 1] = explore;
            		list.Enqueue(next);
            	}
            }
            Console.WriteLine(moveMin[N-1]);
            
            
        }
        static int bitCul(int n)
        {
        	var list = new List<int>();
        	while(n > 0)
        	{
        		if(n % 2 == 1)
        		{
        			list.Add(1);
        		}else
        		{
        			list.Add(0);
        		}
        		n /= 2;
        	}
        	return list.Sum();
        }
    }
}
0