結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  suzu | 
| 提出日時 | 2023-04-26 15:02:00 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 31 ms / 5,000 ms | 
| コード長 | 1,766 bytes | 
| コンパイル時間 | 845 ms | 
| コンパイル使用メモリ | 112,672 KB | 
| 実行使用メモリ | 20,992 KB | 
| 最終ジャッジ日時 | 2024-11-15 22:16:47 | 
| 合計ジャッジ時間 | 2,856 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
        }
    }
}
            
            
            
        