結果

問題 No.3 ビットすごろく
ユーザー 明智重蔵明智重蔵
提出日時 2015-07-20 19:57:16
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,659 bytes
コンパイル時間 3,353 ms
コンパイル使用メモリ 105,896 KB
実行使用メモリ 53,756 KB
最終ジャッジ日時 2023-09-22 20:40:23
合計ジャッジ時間 9,828 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
22,660 KB
testcase_01 AC 67 ms
22,748 KB
testcase_02 AC 66 ms
22,636 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class Program
{
    static string InputPattern = "Input5";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("11");
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("4");
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("10000");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        //すごろくのマスの数
        int MasuCnt = int.Parse(InputList[0]);

        //各マスの1のビット数の配列
        int[] BitCntArr = new int[MasuCnt];
        for (int I = 1; I <= BitCntArr.GetUpperBound(0); I++) {
            int wkBitCnt = Convert.ToString(I, 2).ToCharArray().Count(X => X == '1');
            BitCntArr[I] = wkBitCnt;
        }

        //移動回数と訪問済マスのDict
        var VisitedArrDict = new Dictionary<int, bool[]>();

        for (int MaxMoveCnt = 1; MaxMoveCnt <= MasuCnt; MaxMoveCnt++) {
            bool[] VisitedArr = new bool[MasuCnt + 1];
            VisitedArr[1] = true;

            for (int CurrMoveCnt = 2; CurrMoveCnt <= MaxMoveCnt; CurrMoveCnt++) {
                var VisitedIndSet = new HashSet<int>();

                for (int I = 1; I <= VisitedArr.GetUpperBound(0); I++) {
                    if (VisitedArr[I] == false) continue;
                    int wkLeftInd = I - BitCntArr[I];
                    int wkRightInd = I + BitCntArr[I];

                    if (wkLeftInd >= 1) VisitedIndSet.Add(wkLeftInd);
                    if (wkRightInd <= MasuCnt) VisitedIndSet.Add(wkRightInd);
                }

                foreach (int EachVisitedInd in VisitedIndSet) {
                    VisitedArr[EachVisitedInd] = true;
                }
            }
            if (VisitedArr[MasuCnt]) {
                Console.WriteLine(MaxMoveCnt);
                return;
            }

            //移動回数が1少ない場合と、訪問済マスが同じなら、解なし
            VisitedArrDict.Add(MaxMoveCnt, VisitedArr);
            if (MaxMoveCnt >= 2) {
                if (VisitedArrDict[MaxMoveCnt - 1].SequenceEqual(VisitedArrDict[MaxMoveCnt])) {
                    Console.WriteLine(-1);
                }
            }
        }
    }
}
0