結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2017-07-01 15:32:20 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,837 bytes |
コンパイル時間 | 693 ms |
コンパイル使用メモリ | 108,324 KB |
実行使用メモリ | 25,916 KB |
最終ジャッジ日時 | 2024-10-05 03:56:57 |
合計ジャッジ時間 | 2,407 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 21 |
コンパイルメッセージ
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 Procon { class MainClass { static int popCount(int v) { int count = 0; while (v > 0) { if (v % 2 == 1) { count++; } v /= 2; } return count; } public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); bool[] check = new bool[N + 1]; List<int> current = new List<int>(); current.Add(1); check[1] = true; int turn = 1; while (current.Count > 0) { List<int> next = new List<int>(); foreach (var cur in current) { var count = popCount(cur); int nextR = cur + count; int nextL = cur - count; if (nextR == N) { Console.WriteLine(turn+1); return; } if (0 < nextR && nextR < N) { if (!check[nextR]) { next.Add(nextR); check[nextR] = true; } } if (0 < nextL && nextL < N) { if (!check[nextL]) { next.Add(nextL); check[nextL] = true; } } turn++; } current = next; } Console.WriteLine(-1); } } }