結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-23 07:49:01 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,761 bytes |
| コンパイル時間 | 826 ms |
| コンパイル使用メモリ | 105,600 KB |
| 実行使用メモリ | 27,392 KB |
| 最終ジャッジ日時 | 2024-09-16 04:20:47 |
| 合計ジャッジ時間 | 7,380 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 29 |
コンパイルメッセージ
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;
using System.Linq;
namespace No003_ビットすごろく
{
class Program
{
static private int Min;
static private int N;
static void Main(string[] args)
{
N = int.Parse(Console.ReadLine());
Min = N;
bool[] progression = Enumerable.Repeat(false, N + 1).ToArray();
Search(1, 1, progression);
if (Min == N)
Console.WriteLine(-1);
else
Console.WriteLine(Min);
}
static void Search(int level, int count, bool[] progressionB)
{
bool[] progression = new bool[progressionB.Count()];
Array.Copy(progressionB, progression, progressionB.Count());
if (level == N)
{
// Console.WriteLine("★★★ " + level.ToString() + " " + BitNumber(level).ToString()+" "+count.ToString());
if (Min > count)
Min = count;
}
else if (Min < count)
{
return;
}
else if (level > 0 && level <= N && !progression[level])
{
// Console.WriteLine(level.ToString() + " " + BitNumber(level).ToString() + " " + count.ToString());
progression[level] = true;
Search(level + BitNumber(level), count + 1, progression);
Search(level - BitNumber(level), count + 1, progression);
}
}
static int BitNumber(int a)
{
int temp = 0;
do
{
temp += a % 2;
a /= 2;
} while (a > 0);
return temp;
}
}
}