結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
masakt
|
| 提出日時 | 2017-03-26 20:23:12 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,368 bytes |
| コンパイル時間 | 807 ms |
| コンパイル使用メモリ | 113,984 KB |
| 実行使用メモリ | 29,080 KB |
| 最終ジャッジ日時 | 2024-07-06 06:32:53 |
| 合計ジャッジ時間 | 2,525 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 17 |
コンパイルメッセージ
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.Linq;
class P
{
static int Search(int goal)
{
int x = path.Last();
int step = Convert.ToString(x, 2).Replace("0", "").Length;
int post = x + step;
int pre = x - step;
int count = 0;
path.Add(post);
if (x == goal)
{
return 1;
}
while (path.Count != 0 && count != path.Count)
{
if (x == goal)
{
return path.Count + 1;
}
else
{
x = path.Last();
step = Convert.ToString(x, 2).Replace("0", "").Length;
post = x + step;
pre = x - step;
if (!path.Contains(post) && 1 <= post && post <= goal)
{
path.Add(post);
}
else if (!path.Contains(pre) && 1 <= pre && pre <= goal)
{
path.Add(pre);
}
else
{
count = path.Count;
path.Remove(x);
}
}
}
return -1;
}
static List<int> path = new List<int>() { 1 };
static void Main()
{
Console.WriteLine(Search(int.Parse(Console.ReadLine())));
}
}
masakt