結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
ProgramingWe
|
| 提出日時 | 2017-10-31 11:06:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 5,000 ms |
| コード長 | 1,712 bytes |
| コンパイル時間 | 814 ms |
| コンパイル使用メモリ | 110,852 KB |
| 実行使用メモリ | 28,052 KB |
| 最終ジャッジ日時 | 2024-07-01 08:50:06 |
| 合計ジャッジ時間 | 2,739 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
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 (q.Count > 0)
{
int count = 0;
int search = q.Dequeue();
int step = map[search];
string strR = Convert.ToString(search, 2);
char[] cR = new char[strR.Length];
for (int i = 0; i < strR.Length; i++)
{
cR[i] = strR[i];
}
for (int i = 0; i < cR.Length; i++)
{
if (cR[i].ToString() == "1")
{
count++;
}
}
int[] node = new int[2];
node[0] = search - count;
node[1] = search + count;
foreach (int next in node)
{
if (1 >= next || next > N)
{
continue;
}
if (map[next] == 0 || map[next] > step + 1)
{
map[next] = step + 1;
q.Enqueue(next);
}
}
}
if (map[N] == 0)
{
Console.WriteLine(-1);
}
else
{
Console.WriteLine(map[N]);
}
}
}
}
ProgramingWe