結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー ishizuishizu
提出日時 2015-07-31 21:41:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 71,008 KB
実行使用メモリ 11,916 KB
最終ジャッジ日時 2023-09-24 22:38:50
合計ジャッジ時間 1,428 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
5,448 KB
testcase_01 AC 69 ms
5,652 KB
testcase_02 AC 31 ms
8,668 KB
testcase_03 AC 33 ms
11,852 KB
testcase_04 AC 33 ms
11,916 KB
testcase_05 AC 32 ms
11,876 KB
testcase_06 AC 2 ms
5,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>

#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<30
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define ll long long
#define ull unsigned long long

int NG[1000020];
int M[1000020];


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int T;cin>>T;
	string problem="problem";
	string good="good";
	while(T--){
		string s;cin>>s;
		int len = s.size();
		REP(i,len+10){
			NG[i] = (i) ? NG[i-1]:0;
			M[i] = 1145140;
			if(i+6>=len) M[i] = 1145140;
			else{
				M[i]=0; 
				REP(x,7) if(s[i+x]!=problem[x]) M[i]++;
				if(M[i]==0) NG[i]++;
			}
		}
		int mini = 1145140;
		RREP(i,len+1) M[i] = min(M[i],M[i+1]);
		REP(i,len-4){
			int cnt=0;
			REP(x,4) if(s[i+x] != good[x]) cnt++;
			mini = min(mini,cnt+M[i+4]+((i>=7)? NG[i-7]:0));
		}
		cout<<mini<<endl;
	}
	 

}
0