結果

問題 No.150 "良問"(良問とは言っていない
ユーザー ty70ty70
提出日時 2015-05-29 10:08:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 1,921 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 91,664 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 09:25:27
合計ジャッジ時間 1,513 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<10

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

int hamming (string s, string t ){
	int n = s.length();
	int res = 0;
	rep (i, n )
		if (s[i] != t[i] ) res++;

	return res;
}

int calc (string s, int base ){

	int score1 = INF, score2 = INF;
	for (int i = 0; i <= base - good.length(); i++ ){
		string t = s.substr (i, good.length() );
//		cerr << "t: " << t << endl;
		int curr1 = hamming (t, good );
		score1 = min (score1, curr1 );
	} // end for

	for (int j = base; j <= s.length() - problem.length(); j++ ){
		string u = s.substr (j, problem.length() );
//		cerr << "u: " << u << endl;
		int curr2 = hamming (u, problem );
		score2 = min (score2, curr2 );
	} // end for

	return score1 + score2;
} 

int main()
{
	ios_base::sync_with_stdio(0);
	int T; cin >> T;
	while (T-- ){
		string S; cin >> S;
		int res = good.length() + problem.length();
		for (int i = good.length(); i + problem.length() <= S.length(); i++ ){
			int curr = calc (S, i );
			res = min (res, curr );
		} // end for
		cout << res << endl;
	} // end while 
	return 0;
}
0