結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー mamekinmamekin
提出日時 2016-04-07 21:08:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 103,564 KB
実行使用メモリ 8,196 KB
最終ジャッジ日時 2023-08-01 07:40:55
合計ジャッジ時間 2,603 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
4,380 KB
testcase_01 AC 131 ms
4,376 KB
testcase_02 AC 97 ms
4,672 KB
testcase_03 AC 99 ms
8,104 KB
testcase_04 AC 98 ms
8,196 KB
testcase_05 AC 99 ms
8,160 KB
testcase_06 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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