結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-13 00:09:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,307 bytes |
| コンパイル時間 | 876 ms |
| コンパイル使用メモリ | 66,520 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 01:48:24 |
| 合計ジャッジ時間 | 1,354 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
const string good = "good";
const string problem = "problem";
int ns, ng, np;
string str;
int check_good(int pos) {
int count = 0;
for (int i = 0; i < ng; i++) {
if (str[pos + i] != good[i]) {
count++;
}
}
return count;
}
int check_problem(int pos) {
int count = 0;
for (int i = 0; i < np; i++) {
if (str[pos + i] != problem[i]) {
count++;
}
}
return count;
}
int main() {
int t;
cin >> t;
vector<string> s(t, "");
vector<int> ans(t, 0);
for (int i = 0; i < t; i++) {
cin >> s[i];
}
ng = good.size();
np = problem.size();
vector<int> count_g(101, 1e9);
vector<int> count_p(101, 1e9);
for (int i = 0; i < t; i++) {
fill(count_g.begin(), count_g.end(), 1e9);
fill(count_p.begin(), count_p.end(), 1e9);
str = s[i];
ns = str.size();
for (int j = 0; j <= ns - ng; j++) {
count_g[j] = check_good(j);
}
for (int j = ng; j <= ns - np; j++) {
count_p[j] = check_problem(j);
}
int tmp = 1e9;
for (int k = 0; k <= ns; k++) {
for (int l = k + ng; l <= ns; l++) {
tmp = min(tmp, count_g[k] + count_p[l]);
}
}
ans[i] = tmp;
}
for (int i = 0; i < t; i++) {
cout << ans[i] << endl;
}
return 0;
}