結果

問題 No.150 "良問"(良問とは言っていない
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-28 21:12:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 4,143 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 114,112 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-04-19 09:26:42
合計ジャッジ時間 2,307 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
18,816 KB
testcase_01 AC 26 ms
18,816 KB
testcase_02 AC 26 ms
18,688 KB
testcase_03 AC 26 ms
18,560 KB
testcase_04 AC 26 ms
18,560 KB
testcase_05 AC 27 ms
18,816 KB
testcase_06 AC 64 ms
19,200 KB
testcase_07 AC 26 ms
18,816 KB
testcase_08 AC 26 ms
18,944 KB
testcase_09 AC 27 ms
18,816 KB
testcase_10 AC 36 ms
18,944 KB
testcase_11 AC 37 ms
18,944 KB
testcase_12 AC 33 ms
18,944 KB
testcase_13 AC 36 ms
18,560 KB
testcase_14 AC 39 ms
19,200 KB
testcase_15 AC 38 ms
19,328 KB
testcase_16 AC 27 ms
18,816 KB
testcase_17 AC 30 ms
18,688 KB
testcase_18 AC 37 ms
19,328 KB
testcase_19 AC 39 ms
18,944 KB
testcase_20 AC 41 ms
19,072 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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("3");
            WillReturn.Add("veryverygoodproblem");
            WillReturn.Add("goodexcellentproblems");
            WillReturn.Add("problemgood");
            //0
            //0
            //10
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            WillReturn.Add("goodproblem");
            WillReturn.Add("agdddekproblemsdl");
            //0
            //2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("9");
            WillReturn.Add("geodaaaproblem");
            WillReturn.Add("goodproblen");
            WillReturn.Add("badendlessprobrem");
            WillReturn.Add("podpdpprrobleem");
            WillReturn.Add("problemgoodprobremgood");
            WillReturn.Add("smallproblem");
            WillReturn.Add("proproprefurohobbyhobby");
            WillReturn.Add("gooeproblemd");
            WillReturn.Add("itisproblemcoolgoodproblem");
            //1
            //1
            //4
            //5
            //1
            //4
            //8
            //1
            //0
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("5");
            WillReturn.Add("problemgoodproblem");
            WillReturn.Add("problemproblem");
            WillReturn.Add("goodgoodgood");
            WillReturn.Add("xxxxxxxxxxxxx");
            WillReturn.Add("badendlessproblemactivetogood");
            //0
            //3
            //6
            //11
            //3
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string[] SArr = InputList.Skip(1).ToArray();

        Array.ForEach(SArr, X => DeriveCost(X));
    }

    //GoodProblemに変換する際の最小コストを求める
    static void DeriveCost(string pBeforeStr)
    {
        //Goodに変換するコストの配列
        int[] CostGoodArr = DeriveNeedCostArr(pBeforeStr, "good");

        //Problemに変換するコストの配列
        int[] CostProblemArr = DeriveNeedCostArr(pBeforeStr, "problem");

        //Console.WriteLine("{0}のGoodへのコスト", pBeforeStr);
        //Array.ForEach(CostGoodArr, X => Console.Write(X));
        //Console.WriteLine();

        //Console.WriteLine("{0}のProblemへのコスト", pBeforeStr);
        //Array.ForEach(CostProblemArr, X => Console.Write(X));
        //Console.WriteLine();

        //最小のコスト合計を求める
        int Answer = int.MaxValue;
        for (int I = 0; I <= CostGoodArr.GetUpperBound(0); I++) {
            //下限値枝切り
            if (Answer < CostGoodArr[I]) continue;

            int StaInd = I + "good".Length;
            for (int J = StaInd; J <= CostProblemArr.GetUpperBound(0); J++) {
                int CostSum = CostGoodArr[I] + CostProblemArr[J];
                //Console.WriteLine("I={0},J={1},CostSum={2}", I, J, CostSum);
                if (Answer > CostSum) {
                    Answer = CostSum;
                }
            }
        }
        Console.WriteLine(Answer);
    }

    //指定文字列の各Indから指定文字列に変換する際のコストの配列を返す
    static int[] DeriveNeedCostArr(string pBeforeStr, string pNeedStr)
    {
        var WillReturnList = new List<int>();

        for (int I = 0; I <= pBeforeStr.Length - 1; I++) {
            if (I + pNeedStr.Length > pBeforeStr.Length)
                break;
            int Cnt = 0;
            for (int J = 0; J <= pNeedStr.Length - 1; J++) {
                if (pNeedStr[J] != pBeforeStr[I + J])
                    Cnt++;
            }
            WillReturnList.Add(Cnt);
        }
        return WillReturnList.ToArray();
    }
}
0