結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-04-09 03:50:20 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,028 bytes |
コンパイル時間 | 1,177 ms |
コンパイル使用メモリ | 112,228 KB |
実行使用メモリ | 26,092 KB |
最終ジャッジ日時 | 2024-10-04 05:02:15 |
合計ジャッジ時間 | 4,592 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; namespace No3_1{ public class Program{ private static List<int> stack = new List<int>(); public static void Main(string[] args){ var result = Function(int.Parse(Console.ReadLine()), 1, 1); if(result == int.MaxValue) result = -1; Console.WriteLine(result); } public static int Function(int input, int place, int cnt){ if(place == input) return cnt; if(cnt >= input || stack.Contains(place) || place < 1 || input < place) return int.MaxValue; stack.Add(place); var result = Math.Min(Function(input, place + BitOne(place), cnt + 1), Function(input, place - BitOne(place), cnt + 1)); return result; } public static int BitOne(int num){ var result = 0; while(true){ if(num % 2 == 1) result++; if((num /= 2) == 0) break; } return result; } } }