結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
masakt
|
| 提出日時 | 2017-03-26 18:55:26 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,006 bytes |
| コンパイル時間 | 975 ms |
| コンパイル使用メモリ | 113,144 KB |
| 実行使用メモリ | 29,096 KB |
| 最終ジャッジ日時 | 2024-07-06 06:32:17 |
| 合計ジャッジ時間 | 4,843 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
コンパイルメッセージ
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 void DepthFirstSearch(int goal)
{
int x = path[path.Count - 1];
int step = Convert.ToString(x, 2).Replace("0", "").Length;
if (x == goal)
{
result.Add(path.Count);
}
else
{
int post = x + step;
if (!path.Contains(post) && 1 <= post && post <= goal)
{
path.Add(post);
DepthFirstSearch(goal);
}
int pre = x - step;
if (!path.Contains(pre) && 1 <= pre && pre <= goal)
{
path.Add(pre);
DepthFirstSearch(goal);
}
}
}
static List<int> path = new List<int>() { 1 };
static List<int> result = new List<int>();
static void Main()
{
DepthFirstSearch(int.Parse(Console.ReadLine()));
Console.WriteLine(result.Count == 0 ? -1 : result.Min());
}
}
masakt