結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー parukiparuki
提出日時 2016-07-27 12:56:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,548 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 165,264 KB
実行使用メモリ 161,792 KB
最終ジャッジ日時 2024-04-24 10:20:09
合計ジャッジ時間 3,218 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

static const int MAX_LEN = 1000001;
string nstr(){
    static char res_[MAX_LEN];
    scanf("%s",res_);
    return string(res_);
}

const int INF = INT_MAX;
const string G = "good", P = "problem";
int dp[MAX_LEN][5][8];

void solve(string &S){
    const int N = sz(S);

    rep(i, N + 1)rep(j, 5)rep(k, 8)dp[i][j][k] = INF;
    dp[0][0][0] = 0;

    rep(i, N)rep(j, 5)rep(k, 8)if(dp[i][j][k] != INF){
        if(j != 4 && k == 7)continue;

        int x = dp[i][j][k];
        
        // good
        if(j < 4)smin(dp[i + 1][j + 1][0], x + (S[i] != G[j]));
        // problem
        if(k < 7)smin(dp[i + 1][j == 4 ? 4 : 0][k + 1], x + (S[i] != P[k]));
        // good & problem

        // not
        smin(dp[i + 1][j == 4 ? 4 : 0][k == 7 ? 7 : 0], x + ((j < 4 && S[i] == G[j]) || (k < 7 && S[i] == P[k])));

        // comp
        if(j == 4 && k == 7)smin(dp[i + 1][j][k], x);
    }
    cout << dp[N][4][7] << endl;
}

int main(){
    int T;
    cin >> T;
    while(T--){
        string S = nstr();
        
        solve(S);
    }
}
0