結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー aketijyuuzouaketijyuuzou
提出日時 2024-10-10 23:44:44
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 4,269 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 113,648 KB
実行使用メモリ 27,392 KB
最終ジャッジ日時 2024-10-10 23:44:48
合計ジャッジ時間 3,795 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = "InputX";
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
//2
//4
//8
//1
//1
}
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)
{
//problemm
DeriveProblemIndMArr(pBeforeStr);
//GoodDict
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 + "good".Length - 1 >= EachPair2.Value) continue;
int CurrCost = EachPair1.Key + EachPair2.Key;
if (MinCost > CurrCost)
MinCost = CurrCost;
}
}
Console.WriteLine(MinCost);
}
//problemm
static int[] ProblemIndMArr;
static void DeriveProblemIndMArr(string pBeforeStr)
{
var wkList = new List<int>();
int StaInd = 0;
int wkInd = -1;
while ((wkInd = pBeforeStr.IndexOf("problem", StaInd)) > -1) {
StaInd = wkInd + "problem".Length;
wkList.Add(StaInd - 1);
if (StaInd > pBeforeStr.Length - 1) break;
}
ProblemIndMArr = wkList.ToArray();
}
//IndDict
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") {
//problem
Cost += ProblemIndMArr.Count(X => X < I);
if (WillReturnDict.ContainsKey(Cost))
continue;
WillReturnDict.Add(Cost, I);
}
//Problem
if (pNeedStr == "problem") {
WillReturnDict[Cost] = I;
}
}
return WillReturnDict;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0