結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 7 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
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 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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

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