結果

問題 No.3 ビットすごろく
ユーザー _matumo_
提出日時 2018-06-02 23:21:58
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,222 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 112,668 KB
実行使用メモリ 27,228 KB
最終ジャッジ日時 2024-07-01 09:00:58
合計ジャッジ時間 2,979 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

namespace YukiCoder
{
    class Program
    {
        static int[] bitCnt = new int[] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
        static int[] pnStep;
        static int nMax;

        static int pnBitN(int ni)
        {
            return bitCnt[ni % 16]
                 + bitCnt[ni / 16 % 16]
                 + bitCnt[ni / 16 / 16 % 16]
                 + bitCnt[ni / 16 / 16 / 16 % 16];
        }

        static int zzz(int ns, int ni)
        {
            if (ni < 1 || ni > nMax) return nMax;
            if (ni == nMax) return 1;

            if (ns >= pnStep[ni]) return nMax;
            pnStep[ni] = ns;

            int n = pnBitN(ni);
            int na = zzz(ns + 1, ni + n);
            int nb = zzz(ns + 1, ni - n);
            return (na < nb ? na : nb) + 1;
        }

        static void Main(string[] args)
        {
            nMax = int.Parse(Console.ReadLine());
            pnStep = (new Int32[nMax+1]).Select(s => nMax).ToArray();
            int n = zzz(1, 1);
            if (n >= nMax && n != 1) n = -1;
            Console.WriteLine(n);
            Console.ReadLine();
        }
    }
}
0