結果
| 問題 | No.252 "良問"(良問とは言っていない (2) |
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2026-11-01 16:55:06 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
不安定
|
| 実行時間 | 333 ms / 2,000 ms |
| + 544µs | |
| コード長 | 4,388 bytes |
| 記録 | |
| コンパイル時間 | 2,198 ms |
| コンパイル使用メモリ | 116,508 KB |
| 実行使用メモリ | 102,684 KB |
| 最終ジャッジ日時 | 2026-11-01 16:55:13 |
| 合計ジャッジ時間 | 6,479 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
// https://yukicoder.me/problems/no/252
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");
}
else if (InputPattern == "Input2") {
WillReturn.Add("2");
WillReturn.Add("goodproblem");
WillReturn.Add("agdddekproblemsdl");
}
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");
}
else if (InputPattern == "Input4") {
return System.IO.File.ReadAllLines(@"C:\CSharp\TestConsole\yukicoder_test.txt").ToList();
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static long[] GetSplitArr(string pStr)
{
return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray();
}
static string mS;
static char[] mCharArr;
static int UB_S;
static void Main()
{
List<string> InputList = GetInputList();
var sb = new System.Text.StringBuilder();
foreach (string EachStr in InputList.Skip(1)) {
mS = EachStr;
mCharArr = EachStr.ToCharArray();
UB_S = mCharArr.GetUpperBound(0);
long Answer = Solve();
sb.Append(Answer);
sb.AppendLine();
}
Console.Write(sb.ToString());
}
static int Solve()
{
Dictionary<int, int> CostDictGood = DeriveCost("good");
Dictionary<int, int> CostDictProb = DeriveCost("problem");
// 累積Min作成
int[] ValuesArr = CostDictProb.Values.ToArray();
int UB_ValuesArr = ValuesArr.GetUpperBound(0);
var RunMinDict = new Dictionary<int, int>();
for (int I = ValuesArr.GetUpperBound(0); 0 <= I; I--) {
RunMinDict[I] = ValuesArr[I];
if (RunMinDict.ContainsKey(I + 1)) {
RunMinDict[I] = Math.Min(RunMinDict[I], RunMinDict[I + 1]);
}
}
HashSet<int> PosSet = GetPosSet();
int Answer = int.MaxValue;
int BaseCnt = 0;
// goodにする位置を全探索
for (int I = 0; I <= UB_S; I++) {
int Cost = BaseCnt;
int RangeSta = I + 4;
int RangeEnd = UB_ValuesArr;
if (RangeSta <= RangeEnd) {
Cost += CostDictGood[I] + RunMinDict[RangeSta];
Answer = Math.Min(Answer, Cost);
}
if (PosSet.Contains(I)) {
BaseCnt++;
}
}
return Answer;
}
// 文字列を引数とし、コスト[開始Ind]なDictを返す
static Dictionary<int, int> DeriveCost(string pTarget)
{
var CostDict = new Dictionary<int, int>();
for (int I = 0; I <= UB_S; I++) {
if (I + pTarget.Length - 1 > UB_S) break;
int Cost = 0;
for (int J = 0; J <= pTarget.Length - 1; J++) {
if (mCharArr[I + J] != pTarget[J]) {
Cost++;
}
}
CostDict[I] = Cost;
}
return CostDict;
}
// problemのmの位置のSetを返す
static HashSet<int> GetPosSet()
{
var PosList = new HashSet<int>();
for (int I = 0; I <= UB_S; I++) {
if (I + "problem".Length - 1 > UB_S) break;
string SubStr = mS.Substring(I, "problem".Length);
if (SubStr == "problem") {
PosList.Add(I + "problem".Length - 1);
}
}
return PosList;
}
}
aketijyuuzou