結果

問題 No.150 "良問"(良問とは言っていない
ユーザー tottoripapertottoripaper
提出日時 2015-02-22 01:11:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,543 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 53,432 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 02:56:31
合計ジャッジ時間 1,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>

const std::string G = "good", P = "problem";
std::string S;
int L;

int cost(int index, int offset, const std::string& s){
    if(index+offset < 0 || index+offset+s.size() > L){return 1001001001;}

    int res = 0;
    for(int i=0;i<s.size();i++){
        if(S[index+offset+i] != s[i]){res += 1;}
    }

    return res;
}

int solve2(int index){
    if(index >= L){return 1001001001;}

    int res = cost(index, -(P.size()+1), P);
    for(int i=index;i<L;i++){
        for(int j=0;j<P.size();j++){
            if(S[i] == P[j] && i-j >= index){
                // printf("%d, %d, %d: %d\n", index, i, j, cost(i, -j, P));
                res = std::min(res, cost(i, -j, P));
            }
        }
    }

    return res;
}

int solve(int index){
    int res;
    if(S[index] == 'g'){
        res = cost(index, 0, G) + solve2(index + 4);
    }else if(S[index] == 'o'){
        res = std::min(cost(index, -1, G) + solve2(index + 3), cost(index, -2, G) + solve2(index + 2));
        // printf("%d: %d, %d\n", index, solve2(index + 3), solve2(index + 2));
    }else if(S[index] == 'd'){
        res = cost(index, -3, G) + solve2(index + 1);
    }else{
        res = cost(index, -3, G) + solve2(index + 1);
    }
    return res;
}

int main(){
    int N;
    std::cin >> N;
    
    while(N--){
        std::cin >> S;
        L = S.size();
        
        int res = 1001001001;
        for(int i=0;i<L;i++){
            res = std::min(res, solve(i));
        }

        std::cout << res << std::endl;
    }
}
0