結果

問題 No.150 "良問"(良問とは言っていない
ユーザー koyumeishikoyumeishi
提出日時 2015-02-12 23:40:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 960 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 75,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 09:12:59
合計ジャッジ時間 1,338 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

string good = "good";
string problem = "problem";

int main(){
	int T;
	cin >> T;
	while(T--){
		string s;
		cin >> s;

		auto a = s.find(good);
		auto b = s.find(problem);

		if((a!=string::npos) && (b!=string::npos) && (a < b)){
			cout << 0 << endl;
			continue;
		}else{
			int ans = 1<<30;
			for(int i=0; i+good.size()+problem.size()<=s.size(); i++){
				int cost = 0;
				for(int j=0; j<good.size(); j++){
					if(s[i+j] != good[j]) cost++;
				}
				int cost_ = 1<<30;
				for(int j=i+4; j+problem.size()<=s.size(); j++){
					int cost__ = 0;
					for(int k=0; k<problem.size(); k++){
						if(s[j+k] != problem[k]) cost__++;
					}
					cost_ = min(cost_, cost__);
				}
				ans = min(ans, cost+cost_);
			}
			cout << ans << endl;
		}
	}
	return 0;
}
0