結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
oemon
|
| 提出日時 | 2016-11-27 22:21:26 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 5,000 ms |
| コード長 | 1,114 bytes |
| コンパイル時間 | 849 ms |
| コンパイル使用メモリ | 112,908 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2024-07-01 08:10:40 |
| 合計ジャッジ時間 | 2,872 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
namespace No3
{
class Program
{
private static int N;
private static int[] map;
static void Main(string[] args)
{
N = int.Parse(Console.ReadLine());
map = Enumerable.Repeat(-1, N).ToArray();
Rec(0, 0);
Console.Write(map.Last());
}
static void Rec(int index, int preventCount)
{
if (index < 0) return;
if (index >= N) return;
if (map[index] != -1
&& map[index] <= preventCount + 1) return;
map[index] = preventCount + 1;
if (index == N - 1) return;
var bitcount = BitCount(index + 1);
Rec(index + bitcount, preventCount + 1);
Rec(index - bitcount, preventCount + 1);
}
static int BitCount(int value)
{
var count = 0;
for (var i = 0; i < 32; i++)
{
var tmp = 1 << i;
if ((value & tmp) != 0) count++;
}
return count;
}
}
}
oemon