結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
ProgramingWe
|
| 提出日時 | 2017-10-31 08:59:41 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,020 bytes |
| コンパイル時間 | 2,484 ms |
| コンパイル使用メモリ | 104,576 KB |
| 実行使用メモリ | 21,376 KB |
| 最終ジャッジ日時 | 2024-11-22 09:44:12 |
| 合計ジャッジ時間 | 7,659 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 19 |
コンパイルメッセージ
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());
List<int> queue = new List<int>();
List<int> al = new List<int>();
List<int> visit = new List<int>();
int R = 1;
al.Add(R);
queue.Add(R);
visit.Add(R);
while (queue.Contains(R) && (R != N || al.Count != 0))
{
bool exist = false;
string strR = Convert.ToString(R, 2);
char[] cR = new char[strR.Length];
for (int i = 0; i < strR.Length; i++)
{
cR[i] = strR[i];
}
int count = 0;
for (int i = 0; i < cR.Length; i++)
{
if (cR[i].ToString() == "1")
{
count++;
}
}
int[] node = new int[2];
node[0] = R - count;
node[1] = R + count;
foreach (int cnode in node)
{
if (1 <= cnode && cnode <= N && !visit.Contains(cnode))
{
al.Add(cnode);
queue.Add(cnode);
visit.Add(cnode);
exist = true;
}
}
if (exist == false)
{
queue.Remove(R);
}
al.Remove(R);
if (al.Count != 0)
{
R = al[0];
}
}
if (R == N)
{
queue.Add(R);
Console.WriteLine(queue.Count);
}
else
{
Console.WriteLine(-1);
}
}
}
}
ProgramingWe