結果
問題 | No.150 "良問"(良問とは言っていない |
ユーザー | masa |
提出日時 | 2015-02-13 00:09:32 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,307 bytes |
コンパイル時間 | 840 ms |
コンパイル使用メモリ | 66,888 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-19 09:16:03 |
合計ジャッジ時間 | 1,410 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 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 | 2 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 | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
ソースコード
#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; }