結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-05-21 12:27:44 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,377 bytes |
| コンパイル時間 | 772 ms |
| コンパイル使用メモリ | 110,708 KB |
| 実行使用メモリ | 54,892 KB |
| 最終ジャッジ日時 | 2024-06-28 14:55:50 |
| 合計ジャッジ時間 | 7,274 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
public class Amatsuki
{
public static void Main()
{
var target = int.Parse(Console.ReadLine());
var pass = new int[0];
var result = new List<int>();
check(1, target, pass, ref result);
if (result.Any())
{
Console.WriteLine(result.Count);
}
else
{
Console.WriteLine(-1);
}
}
public static void check(int now, int target, int[] pass, ref List<int> result)
{
var passList = pass.ToList();
if (passList.Contains(now)) { return; }
passList.Add(now);
if (now == target)
{
if(passList.Count < result.Count || result.Count == 0)
{
result = passList;
}
}
var bit = bitCount(now);
if (now + bit <= target)
{
check(now + bit, target, passList.ToArray(), ref result);
}
if (now - bit > 1)
{
check(now - bit, target, passList.ToArray(), ref result);
}
}
public static int bitCount(int dec)
{
var result = 0;
while (dec > 0)
{
if (dec % 2 == 1)
{
result++;
}
dec /= 2;
}
return result;
}
}