結果

問題 No.3 ビットすごろく
ユーザー mban
提出日時 2016-10-31 14:02:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 937 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 109,920 KB
実行使用メモリ 27,324 KB
最終ジャッジ日時 2024-07-01 08:08:57
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Magatro
{

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] w = (new int[N + 1]).Select(s=>-1).ToArray();
        w[1] = 1;
        Queue<int> q = new Queue<int>();
        q.Enqueue(1);
        while (q.Count > 0)
        {
            int e = q.Dequeue();
            if (e + bit(e) <= N&& w[e + bit(e)]==-1)
            {
                w[e + bit(e)] = w[e] + 1;
                q.Enqueue(e + bit(e));
            }
            if (e - bit(e) >= 1&& w[e - bit(e)]==-1)
            {
                w[e - bit(e)] = w[e] + 1;
                q.Enqueue(e - bit(e));
            }
        }
        Console.WriteLine(w[N]);

    }
    static int bit(int n)
    {
        if (n == 0)
        {
            return 0;
        }
        return bit(n / 2) + n % 2;
    }
 
}


0