結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー 👑 kmjpkmjp
提出日時 2015-07-24 22:45:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 145,608 KB
実行使用メモリ 20,528 KB
最終ジャッジ日時 2023-09-22 22:38:07
合計ジャッジ時間 2,260 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,452 KB
testcase_01 AC 67 ms
9,496 KB
testcase_02 AC 29 ms
16,552 KB
testcase_03 AC 32 ms
20,528 KB
testcase_04 AC 31 ms
20,528 KB
testcase_05 AC 32 ms
20,528 KB
testcase_06 AC 3 ms
9,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int T;
string S;
int G[1010101];
int P[1010101];
int M[1010101];

int NG[1010101],NP[1010101];
int L;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	int mp=10000000;
	while(T--) {
		cin>>S;
		L=S.size();
		FOR(i,L+10) {
			NP[i]=(i)?NP[i-1]:0;
			M[i]=1010100;
			if(i+6>=L) P[i]=1010100;
			else {
				P[i]=0;
				FOR(x,7) if(S[i+x]!="problem"[x]) P[i]++;
				if(P[i]==0) NP[i]++;
			}
		}
		int mi=1010;
		for(i=L;i>=0;i--) M[i]=min(P[i],M[i+1]);
		FOR(i,L-4) {
			NG[i]=(i)?NG[i-1]:0;
			int cnt=0;
			FOR(x,4) if(S[i+x]!="good"[x]) cnt++;
			mi=min(mi,cnt+M[i+4]+((i>=4)?NG[i-4]:0)+((i>=7)?NP[i-7]:0));
			if(cnt==0) NG[i]++;
		}
		cout<<mi<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0