結果

問題 No.150 "良問"(良問とは言っていない
ユーザー 0w10w1
提出日時 2016-03-21 12:23:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,088 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 159,324 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 09:32:04
合計ジャッジ時間 2,040 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 2;
const int INF = 0x3f3f3f3f;

int n;
string s;

const string GOOD = "good";
const string PROB = "problem";

int gv[ MAXN ], pv[ MAXN ];
int pgv[ MAXN ], spv[ MAXN ];

void solve(){
    for(int i = 3; i < n; ++i){
        gv[ i ] = 4;
        for(int j = 0; j < 4; ++j)
            if( s[ i - 3 + j ] == GOOD[ j ] )
                --gv[ i ];
    }
    for(int i = 0; i + 6 < n; ++i){
        pv[ i ] = 7;
        for(int j = 0; j < 7; ++j)
            if( s[ i + j ] == PROB[ j ] )
                --pv[ i ];
    }
    memset( pgv, INF, sizeof(pgv) );
    for(int i = 3; i < n; ++i)
        pgv[ i ] = min( pgv[ i - 1 ], gv[ i ] );
    memset( spv, INF, sizeof(spv) );
    for(int i = n - 7; i >= 0; --i)
        spv[ i ] = min( spv[ i + 1 ], pv[ i ] );
    int ans = INF;
    for(int i = 3; i + 6 < n; ++i)
        ans = min( ans, pgv[ i ] + spv[ i + 1 ] );
    cout << ans << endl;
}

int main(){
    int T; cin >> T;
    while( T-- ){
        cin >> s;
        n = s.size();
        solve();
    }
    return 0;
}
0