結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー mamekinmamekin
提出日時 2016-04-07 21:05:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,225 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 106,344 KB
実行使用メモリ 8,460 KB
最終ジャッジ日時 2024-04-14 22:25:07
合計ジャッジ時間 3,018 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 85 ms
6,940 KB
testcase_03 AC 86 ms
8,344 KB
testcase_04 AC 87 ms
8,252 KB
testcase_05 AC 86 ms
8,460 KB
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int countDiff(const string& s, const string& t)
{
    int n = s.size();
    int diff = 0;
    for(int i=0; i<n; ++i){
        if(s[i] != t[i])
            ++ diff;
    }
    return diff;
}

const int INF = INT_MAX / 4;

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

    while(--t >= 0){
        string s;
        cin >> s;
        int n = s.size();

        vector<int> v(n, INF);
        for(int i=n-7; i>=0; --i)
            v[i] = min(v[i+1], countDiff(s.substr(i, 7), "problem"));

        int ans = INF;
        int cnt = 0;
        for(int i=0; i<=n-4; ++i){
            if(i - 7 >= 0 && s.substr(i-7, 7) == "problem")
                ++ cnt;
            int diff = countDiff(s.substr(i, 4), "good") + v[i+4];
            ans = min(ans, diff + cnt);
        }
        cout << ans << endl;
    }
}
0