結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2017-06-25 14:45:07 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 5,000 ms |
| コード長 | 1,588 bytes |
| コンパイル時間 | 1,091 ms |
| コンパイル使用メモリ | 113,296 KB |
| 実行使用メモリ | 19,584 KB |
| 最終ジャッジ日時 | 2024-07-01 08:46:12 |
| 合計ジャッジ時間 | 3,334 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / 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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program
{
public void Proc()
{
int num = int.Parse(Reader.ReadLine());
int[] map = new int[num + 1];
map[1] = 1;
Queue<int> q = new Queue<int>();
q.Enqueue(1);
while(q.Count()>0) {
int cur = q.Dequeue();
int step = map[cur];
int move = Convert.ToString(cur, 2).Count(a => a == '1');
int[] nextPos = new int[] { cur - move, cur + move };
foreach(int next in nextPos) {
if(next<=1) {
continue;
}
if(next>num) {
continue;
}
if(map[next]==0||map[next]>step+1) {
map[next] = step + 1;
q.Enqueue(next);
}
}
}
if(map[num]==0) {
Console.WriteLine(-1);
} else {
Console.WriteLine(map[num]);
}
}
public class Reader
{
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine()
{
if (IsDebug)
{
if (sr == null)
{
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
private static string InputText = @"
5
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
バカらっく