結果

問題 No.3 ビットすごろく
ユーザー abL8ZLsTbFabL8ZLsTbF
提出日時 2016-10-19 22:35:20
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 1,009 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 105,552 KB
実行使用メモリ 23,556 KB
最終ジャッジ日時 2023-09-14 00:09:31
合計ジャッジ時間 5,589 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,332 KB
testcase_01 AC 59 ms
21,376 KB
testcase_02 AC 59 ms
21,456 KB
testcase_03 AC 60 ms
21,396 KB
testcase_04 AC 59 ms
23,384 KB
testcase_05 AC 60 ms
21,360 KB
testcase_06 AC 62 ms
23,448 KB
testcase_07 AC 61 ms
23,424 KB
testcase_08 AC 60 ms
23,460 KB
testcase_09 AC 61 ms
23,460 KB
testcase_10 AC 59 ms
21,460 KB
testcase_11 AC 60 ms
21,332 KB
testcase_12 AC 61 ms
23,456 KB
testcase_13 AC 60 ms
21,420 KB
testcase_14 AC 61 ms
23,320 KB
testcase_15 AC 60 ms
21,404 KB
testcase_16 AC 61 ms
23,460 KB
testcase_17 AC 60 ms
21,420 KB
testcase_18 AC 59 ms
21,468 KB
testcase_19 AC 60 ms
23,472 KB
testcase_20 AC 59 ms
19,372 KB
testcase_21 AC 58 ms
21,404 KB
testcase_22 AC 60 ms
21,372 KB
testcase_23 AC 60 ms
21,380 KB
testcase_24 AC 59 ms
21,332 KB
testcase_25 AC 61 ms
23,436 KB
testcase_26 AC 58 ms
21,408 KB
testcase_27 AC 60 ms
23,416 KB
testcase_28 AC 62 ms
21,404 KB
testcase_29 AC 60 ms
23,556 KB
testcase_30 AC 59 ms
23,468 KB
testcase_31 AC 59 ms
21,408 KB
testcase_32 AC 60 ms
21,460 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;
using System.Linq;

public class Program
{
	public static void Main()
	{
		int N = int.Parse(Console.ReadLine());
		var q = new Queue<Square>();
		q.Enqueue(new Square(1, 1));
		var already = new bool[N];
		if (N == 1)
		{
			Console.WriteLine(1);
			return;
		}
		while (q.Any())
		{
			var pop = q.Dequeue();
			int num = pop.Num;
			int mov = 0;
			for (int i = num; i > 0; i >>= 1)
			{
				mov += i & 1;
			}
			int go = num + mov;
			if (go < N && !already[go - 1])
			{
				already[go - 1] = true;
				q.Enqueue(new Square(go, pop.Count + 1));
			}
			if (go == N)
			{
				Console.WriteLine(pop.Count + 1);
				return;
			}
			int back = num - mov;
			if (back > 0 && !already[back - 1])
			{
				already[back - 1] = true;
				q.Enqueue(new Square(back, pop.Count + 1));
			}
		}
		Console.WriteLine(-1);
	}
}

public class Square
{
	public Square(int num, int count)
	{
		this.Num = num;
		this.Count = count;
	}
	
	public int Num;
	public int Count;
}
0