結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー hirokazu1020hirokazu1020
提出日時 2015-07-25 00:06:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 79,332 KB
実行使用メモリ 8,184 KB
最終ジャッジ日時 2023-09-23 01:59:46
合計ジャッジ時間 1,721 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
4,380 KB
testcase_01 AC 86 ms
4,376 KB
testcase_02 AC 47 ms
4,556 KB
testcase_03 AC 49 ms
7,992 KB
testcase_04 AC 48 ms
8,164 KB
testcase_05 AC 49 ms
8,184 KB
testcase_06 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())



const string good="good",problem="problem";



int main(){
	int t;
	cin>>t;
	rep(_,t){
		string s;
		cin>>s;
		vector<int> repP(s.size(),INF);
		int n=s.size();
		for(int i=n-problem.size();i>=0;i--){
			int cnt=0;
			for(int j=0;j<problem.size();j++){
				cnt+=problem[j]!=s[i+j];
			}
			repP[i]=min(cnt,repP[i+1]);
		}
		int ans=INF,c=0;
		for(int i=0;i<=n-good.size()-problem.size();i++){
			if(problem.size()<=i){
				if(s.substr(i-problem.size(),problem.size())==problem)c++;
			}
			int cnt=0;
			for(int j=0;j<good.size();j++){
				cnt+=good[j]!=s[i+j];
			}
			ans=min(ans,c+cnt+repP[i+good.size()]);
		}
		cout<<ans<<endl;
	}
	return 0;
}
0