結果
問題 |
No.150 "良問"(良問とは言っていない
|
ユーザー |
![]() |
提出日時 | 2017-01-12 14:28:27 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 45 ms / 5,000 ms |
コード長 | 2,184 bytes |
コンパイル時間 | 2,307 ms |
コンパイル使用メモリ | 112,708 KB |
実行使用メモリ | 18,048 KB |
最終ジャッジ日時 | 2024-10-11 02:10:35 |
合計ジャッジ時間 | 3,676 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 20 |
コンパイルメッセージ
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; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static private Magatro M = new Magatro(); static private void Main(string[]args) { M.Scan(); M.Solve(); } } public class Scanner { private string[] S; private int Index; private char Separator; public Scanner(char separator = ' ') { Index = 0; Separator = separator; } private string[] Line() { return Console.ReadLine().Split(Separator); } public string Next() { string result; if (S == null || Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } } public class Magatro { private int T; private Scanner Sc = new Scanner(); private const string good= "good"; private const string problem = "problem"; public void Scan() { T = Sc.NextInt(); } public void Solve() { for(int i = 0; i < T; i++) { string S = Sc.Next(); Console.WriteLine(Anser(S)); } } private int Anser(string s) { int result = int.MaxValue; for(int i = 0; i <= s.Length - good.Length - problem.Length; i++) { for(int j = i + 4; j <= s.Length - problem.Length; j++) { result = Math.Min(result, Change(s,i,good) + Change(s,j,problem)); } } return result; } private int Change(string s,int index,string b) { int result = b.Length; if (s.Length-index < b.Length) throw new Exception(); for(int i = 0; i < b.Length; i++) { if (s[index+i] == b[i]) result--; } return result; } }