結果
問題 |
No.150 "良問"(良問とは言っていない
|
ユーザー |
![]() |
提出日時 | 2015-02-22 01:11:58 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,543 bytes |
コンパイル時間 | 499 ms |
コンパイル使用メモリ | 57,780 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 21:49:03 |
合計ジャッジ時間 | 1,207 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 7 WA * 13 |
ソースコード
#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; } }