結果

問題 No.3 ビットすごろく
ユーザー hogekihogeki
提出日時 2016-07-31 18:17:26
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 798 bytes
コンパイル時間 4,260 ms
コンパイル使用メモリ 104,408 KB
実行使用メモリ 22,728 KB
最終ジャッジ日時 2023-09-14 00:04:42
合計ジャッジ時間 6,869 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,640 KB
testcase_01 AC 58 ms
20,632 KB
testcase_02 AC 58 ms
20,716 KB
testcase_03 AC 58 ms
20,728 KB
testcase_04 AC 57 ms
22,664 KB
testcase_05 AC 58 ms
20,652 KB
testcase_06 AC 57 ms
22,684 KB
testcase_07 AC 56 ms
18,588 KB
testcase_08 AC 59 ms
22,696 KB
testcase_09 AC 58 ms
20,644 KB
testcase_10 AC 57 ms
20,592 KB
testcase_11 AC 58 ms
22,728 KB
testcase_12 AC 59 ms
20,692 KB
testcase_13 AC 57 ms
20,720 KB
testcase_14 AC 59 ms
20,724 KB
testcase_15 AC 59 ms
20,664 KB
testcase_16 AC 58 ms
18,628 KB
testcase_17 AC 58 ms
22,696 KB
testcase_18 AC 57 ms
20,648 KB
testcase_19 AC 59 ms
20,644 KB
testcase_20 AC 57 ms
20,816 KB
testcase_21 AC 56 ms
20,688 KB
testcase_22 AC 58 ms
20,616 KB
testcase_23 AC 59 ms
20,608 KB
testcase_24 AC 58 ms
22,656 KB
testcase_25 AC 57 ms
20,692 KB
testcase_26 AC 56 ms
20,660 KB
testcase_27 AC 56 ms
20,648 KB
testcase_28 AC 56 ms
20,628 KB
testcase_29 AC 56 ms
20,680 KB
testcase_30 AC 56 ms
20,608 KB
testcase_31 AC 56 ms
20,608 KB
testcase_32 AC 56 ms
20,560 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.Collections.Generic;

class BitSugoroku
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[] steps = new int[N+1];
		Queue<int> queue = new Queue<int>();

		for(int i=0; i<=N; i++)
		{
			steps[i] = -1;
		}

		steps[1] = 1;
		queue.Enqueue(1);

		while(queue.Count != 0)
		{
			int t = queue.Dequeue();
			int step = bitCount(t);
			if(t+step <= N && steps[t+step] == -1)
			{
				steps[t+step] = steps[t] + 1;
				queue.Enqueue(t+step);
			}
			if(t-step >= 1 && steps[t-step] == -1)
			{
				steps[t-step] = steps[t] + 1;
				queue.Enqueue(t-step);
			}
		}
		Console.WriteLine(steps[N]);
	}
	
	static int bitCount(int n)
	{
		int count=0;
		while(n > 0)
		{
			if((n & 0x01) == 0x01)
				count++;
			n >>= 1;
		}
		return count;
	}
}
0