結果

問題 No.150 "良問"(良問とは言っていない
ユーザー krotonkroton
提出日時 2015-05-26 20:46:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,188 bytes
コンパイル時間 1,226 ms
コンパイル使用メモリ 147,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-01 09:53:39
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int INF = 1 << 25;
const string good = "good";
const string problem = "problem";

int main(){
    int T; cin >> T;
    
    while(T--){
        string S; cin >> S;
        
        int N = (int)S.size();
        vector<int> G(N, INF), P(N, INF);
        
        for(int i=0;i<N;i++){
            int t = i;
            int s = t - (int)good.size() + 1;
            if(s < 0)
                continue;
            
            int dif = 0;
            for(int j=0;j<good.size();j++){
                dif += S[s+j] != good[j];
            }
            
            G[i] = min(G[i-1], dif);
        }
        
        for(int i=N-1;i>=0;i--){
            int s = i;
            int t = s + (int)problem.size() - 1;
            if(t >= N)
                continue;
            
            int dif = 0;
            for(int j=0;j<problem.size();j++){
                dif += S[s+j] != problem[j];
            }
            
            P[i] = min(P[i+1], dif);
        }
        
        int res = INF;
        for(int i=1;i<N;i++)
            res = min(res, G[i-1] + P[i]);
        
        cout << res << endl;
    }
    
    return 0;
}
0