結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-31 18:17:26 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 5,000 ms |
| コード長 | 798 bytes |
| コンパイル時間 | 2,113 ms |
| コンパイル使用メモリ | 108,528 KB |
| 実行使用メモリ | 17,920 KB |
| 最終ジャッジ日時 | 2024-07-01 08:02:06 |
| 合計ジャッジ時間 | 3,919 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / 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.Collections.Generic;
class BitSugoroku
{
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
int[] steps = new int[N+1];
Queue<int> queue = new Queue<int>();
for(int i=0; i<=N; i++)
{
steps[i] = -1;
}
steps[1] = 1;
queue.Enqueue(1);
while(queue.Count != 0)
{
int t = queue.Dequeue();
int step = bitCount(t);
if(t+step <= N && steps[t+step] == -1)
{
steps[t+step] = steps[t] + 1;
queue.Enqueue(t+step);
}
if(t-step >= 1 && steps[t-step] == -1)
{
steps[t-step] = steps[t] + 1;
queue.Enqueue(t-step);
}
}
Console.WriteLine(steps[N]);
}
static int bitCount(int n)
{
int count=0;
while(n > 0)
{
if((n & 0x01) == 0x01)
count++;
n >>= 1;
}
return count;
}
}