結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-04-02 22:02:34 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,697 bytes |
コンパイル時間 | 930 ms |
コンパイル使用メモリ | 105,856 KB |
実行使用メモリ | 29,440 KB |
最終ジャッジ日時 | 2024-07-08 00:17:05 |
合計ジャッジ時間 | 7,502 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 TLE * 1 -- * 29 |
コンパイルメッセージ
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 = 1; int c = 1; int step = 1; Tuple<int, int> post; Tuple<int, int> pre; path.Add(Tuple.Create(x,c)); if (x == goal) { return 1; } while (path.Count != 0) { if (x == goal) { return c; } else if (goal < c) { break; } else { Tuple<int, int> t = path.First(); x = t.Item1; c = t.Item2; step = Convert.ToString(x, 2).Replace("0", "").Length; post = Tuple.Create(x + step, c + 1); pre = Tuple.Create(x - step, c + 1); if (1 <= post.Item1 && post.Item1 <= goal) { if (path.Contains(post)) { } else { path.Add(post); } } if (1 <= pre.Item1 && pre.Item1 <= goal) { if (path.Contains(pre)) { } else { path.Add(pre); } } path.Remove(t); } } return -1; } static List<Tuple<int, int>> path = new List<Tuple<int, int>>(); static void Main() { Console.WriteLine(Search(int.Parse(Console.ReadLine()))); } }