結果

問題 No.150 "良問"(良問とは言っていない
ユーザー pekempeypekempey
提出日時 2015-07-25 12:36:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,833 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 161,432 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 09:26:01
合計ジャッジ時間 1,977 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 1 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
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define itall(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-8;
template<typename T> inline T sq(T a) { return a * a; }
template<typename T> inline T cb(T a) { return a * a * a; }
template<typename T> inline bool umin(T &a, const T &b) { return b < a && (a = b, true); }
template<typename T> inline bool umax(T &a, const T &b) { return a < b && (a = b, true); }

const int infP = inf;

string a = "good", b = "problem";

int sum[1000010];
int hamA[1000010], hamB[1000010];
int hamBmin[1000010];

int main() {
    int q;
    cin >> q;

    rep (z, q) {
        string s;
        cin >> s;

        fill(sum, sum + s.length() + 10, 0);
        fill(hamA, hamA + s.length(), 0);
        fill(hamB, hamB + s.length(), 0);
        fill(hamBmin, hamBmin + s.length(), inf);

        for (int i = s.find(b); i != string::npos; i = s.find(b, i + 1)) {
            sum[i + b.length()]++;
        }

        rep2 (i, 1, s.length()) {
            sum[i] += sum[i - 1];
        }

        rep (i, s.length() - 3) {
            rep (k, 4) hamA[i] += s[i + k] != a[k];
        }

        rep (i, s.length() - 6) {
            rep (k, 7) hamB[i] += s[i + k] != b[k];
        }

        hamBmin[s.length() - 7] = hamB[s.length() - 7];
        repr (i, s.length() - 7) {
            umin(hamBmin[i], min(hamB[i], hamBmin[i + 1]));
        }

        int ans = inf;
        rep (i, s.length() - 10) {
            umin(ans, hamA[i] + hamBmin[i + 4]);
        }

        cout << ans << endl;
    }
}
0