結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2016-09-08 03:05:18 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 714 bytes |
コンパイル時間 | 824 ms |
コンパイル使用メモリ | 102,784 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-11-15 22:15:38 |
合計ジャッジ時間 | 2,599 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; public class Program { public static void Main() { int N = int.Parse(Console.ReadLine()); var isUsed = new bool[N]; isUsed[0] = true; for (int i = 1; i < N; i++) { isUsed[i] = false; } int ans = 1; int current = 1; while (current != N) { int move = 0; for (int temp = current; temp > 0; temp /= 2) { move += temp % 2; } if (current + move <= N && !isUsed[current + move - 1]) { ++ans; isUsed[(current += move) - 1] = true; } else if (current - move < 0 || isUsed[current - move - 1]) { Console.WriteLine(-1); return; } else { ++ans; isUsed[(current -= move) - 1] = true; } } Console.WriteLine(ans); } }