結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
ty70
|
| 提出日時 | 2015-05-29 10:08:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 5,000 ms |
| コード長 | 1,921 bytes |
| コンパイル時間 | 767 ms |
| コンパイル使用メモリ | 90,120 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 01:54:56 |
| 合計ジャッジ時間 | 1,669 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#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;
}
ty70