結果
問題 | No.252 "良問"(良問とは言っていない (2) |
ユーザー |
![]() |
提出日時 | 2016-03-30 23:40:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 1,682 bytes |
コンパイル時間 | 740 ms |
コンパイル使用メモリ | 85,112 KB |
実行使用メモリ | 16,228 KB |
最終ジャッジ日時 | 2024-10-02 08:18:17 |
合計ジャッジ時間 | 2,016 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 |
ソースコード
/* -*- coding: utf-8 -*-** 252.cc: No.252 "良問"(良問とは言っていない (2) - yukicoder*/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<deque>#include<algorithm>#include<numeric>#include<utility>#include<complex>#include<functional>using namespace std;/* constant */const int MAX_N = 1000000;const int INF = 1 << 30;const string STR_G("good");const string STR_P("problem");/* typedef *//* global variables */int egs[MAX_N + 1], eps[MAX_N + 1], pcs[MAX_N + 1];/* subroutines */void make_es(const string &s, const string &t, int es[]) {int sn = s.size(), tn = t.size();for (int i = 0; i <= sn - tn; i++) {int cnt = 0;for (int j = 0; j < tn; j++)if (s[i + j] != t[j]) cnt++;es[i] = cnt;}}/* main */int main() {int tn;cin >> tn;while (tn--) {string s;cin >> s;make_es(s, STR_G, egs);make_es(s, STR_P, eps);int sn = s.size(), egn = sn - 4 + 1, epn = sn - 7 + 1;if (false) {cout << s << endl;for (int i = 0; i < egn; i++) printf("%d ", egs[i]); putchar('\n');for (int i = 0; i < epn; i++) printf("%d ", eps[i]); putchar('\n');}pcs[0] = 0;for (int i = 0; i < epn; i++)pcs[i + 1] = pcs[i] + (eps[i] == 0 ? 1 : 0);int mind = INF, minp = INF;for (int i = epn - 1; i >= 4; i--) {if (minp > eps[i]) minp = eps[i];int d = pcs[i - 4] + egs[i - 4] + minp;if (mind > d) mind = d;}printf("%d\n", mind);}return 0;}