結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-31 14:15:12
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,128 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 106,708 KB
実行使用メモリ 32,236 KB
最終ジャッジ日時 2023-09-25 21:00:10
合計ジャッジ時間 4,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 185 ms
26,160 KB
testcase_03 AC 182 ms
26,188 KB
testcase_04 AC 182 ms
28,272 KB
testcase_05 AC 181 ms
24,192 KB
testcase_06 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = "Input6";

    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 if (InputPattern == "Input5") {
            WillReturn.Add("1");
            WillReturn.Add(new string('a', 1000));
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        var sw = System.Diagnostics.Stopwatch.StartNew();

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

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

    //GoodProblemに変換する際の最小コストを求める
    static void DeriveCost(string pBeforeStr)
    {
        //Goodに変換するコストのDict
        var CostGoodDict = DeriveNeedCostDict(pBeforeStr, "good");

        //Problemに変換するコストの配列
        var CostProblemDict = DeriveNeedCostDict(pBeforeStr, "problem");

        int MinCost = int.MaxValue;
        foreach (var EachPair1 in CostGoodDict) {
            foreach (var EachPair2 in CostProblemDict) {
                if (EachPair1.Value + 3 >= EachPair2.Value) continue;
                int CurrCost = EachPair1.Key + EachPair2.Key;
                if (MinCost > CurrCost)
                    MinCost = CurrCost;
            }
        }
        Console.WriteLine(MinCost);
    }

    //指定文字列の各Indから指定文字列に変換する際のコストのDictを返す
    static Dictionary<int, int> DeriveNeedCostDict(string pBeforeStr, string pNeedStr)
    {
        var WillReturnDict = new Dictionary<int, int>();

        for (int I = 0; I <= pBeforeStr.Length - 1; I++) {
            if (I + pNeedStr.Length > pBeforeStr.Length)
                break;
            int Cost = 0;
            for (int J = 0; J <= pNeedStr.Length - 1; J++) {
                if (pNeedStr[J] != pBeforeStr[I + J])
                    Cost++;
            }
            //goodなら最左を優先
            if (pNeedStr == "good") {
                if (WillReturnDict.ContainsKey(Cost)) {
                    continue;
                }
                WillReturnDict.Add(Cost, I);
            }
            //Problemなら最右を優先
            if (pNeedStr == "problem") {
                WillReturnDict[Cost] = I;
            }
        }
        return WillReturnDict;
    }
}
0