結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー IL_mstaIL_msta
提出日時 2015-07-25 00:58:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,911 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 86,476 KB
実行使用メモリ 5,172 KB
最終ジャッジ日時 2023-09-23 04:02:44
合計ジャッジ時間 1,732 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 57 ms
4,376 KB
testcase_03 AC 9 ms
5,172 KB
testcase_04 AC 5 ms
5,140 KB
testcase_05 AC 39 ms
5,116 KB
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int ans[100000];

bool check(string str){
	int a,b;
	a = str.find("good");
	if(a == -1){
		return false;
	}
	b = str.find("problem",a);
	if( b == -1){
		return false;
	}
	return true;
}

int solve(string str){
	//goodp roble m
	int LenA,LenB;
	int minLA = 5,minLApos=-1;
	int minLB = 8,minLBpos=-1;
	int ans=12,tans;
	for(int i=0;i<=str.size()-11;++i){
		LenA = 0;
		if(str[i  ] != 'g')LenA++;
		if(str[i+1] != 'o')LenA++;
		if(str[i+2] != 'o')LenA++;
		if(str[i+3] != 'd')LenA++;
		if(ans <= LenA) continue;
		if( i+4 <= minLBpos ){
			tans = LenA + minLB;
			ans = min(ans,tans);
			if(ans == 0){
				break;
			}
			continue;
		}
		for(int j=i+4; j<=str.size()-7; ++j){
			LenB = 0;
			if(str[j  ] != 'p')LenB++;
			if(str[j+1] != 'r')LenB++;
			if(str[j+2] != 'o')LenB++;
			if(str[j+3] != 'b')LenB++;
			if(str[j+4] != 'l')LenB++;
			if(str[j+5] != 'e')LenB++;
			if(str[j+6] != 'm')LenB++;
			if( minLBpos < i+4 || LenB < minLB){
				minLB = LenB;
				minLBpos = j;
			}
			tans = LenA+LenB;
			ans = min(ans,tans);
			if(LenB == 0){
				break;
			}
			if(ans == 0){
				break;
			}
		}
		if(ans == 0){
			break;
		}
	}

	return ans;
}
int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(16);//
	
	int T;
	cin>>T;
	string str;
	rep(i,T){
		cin>>str;
		ans[i] = solve(str);
	}
	rep(i,T){
		P(ans[i]);
	}
	return 0;
}
0