結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-03-26 20:08:21 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,245 bytes |
コンパイル時間 | 1,084 ms |
コンパイル使用メモリ | 110,808 KB |
実行使用メモリ | 53,144 KB |
最終ジャッジ日時 | 2024-07-06 06:32:50 |
合計ジャッジ時間 | 7,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 TLE * 1 -- * 30 |
コンパイルメッセージ
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; path.Add(post); while (path.Count != 0) { if (x == goal) { path.Add(goal); return path.Count; } 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 { path.Remove(x); } } } return -1; } static List<int> path = new List<int>() { 1 }; static void Main() { Console.WriteLine(Search(int.Parse(Console.ReadLine()))); } }