結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-11-24 22:53:19 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,082 bytes |
コンパイル時間 | 1,008 ms |
コンパイル使用メモリ | 104,448 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-11-27 10:50:07 |
合計ジャッジ時間 | 3,164 ms |
ジャッジサーバーID (参考情報) |
judge4 / 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; namespace No3 { class Program { private static int N; private static bool[] map; static void Main(string[] args) { N = int.Parse(Console.ReadLine()); map = new bool[N]; var result = Rec(0); Console.Write(result); } static int Rec(int index) { if (index == N - 1) return 1; if (index < 0) return -1; if (index >= N) return -1; if (map[index]) return -1; map[index] = true; var count = 0; for (var i = 0; i < 32; i++) { var tmp = 1 << i; if ((index + 1 & tmp) != 0) count++; } var front = Rec(index + count); var back = Rec(index - count); if (front == -1) { return back == -1 ? -1 : back + 1; } else { return back == -1 ? front + 1 : Math.Min(front, back) + 1; } } } }