結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-03 22:17:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 947 bytes |
| コンパイル時間 | 469 ms |
| コンパイル使用メモリ | 55,540 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 01:53:21 |
| 合計ジャッジ時間 | 1,169 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <cstdio>
const int INF = 1001001001;
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 INF;}
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+7 > L){return INF;}
return cost(index, 0, P);
}
int solve(int index){
if(index+11 > L){return INF;}
int res = INF;
for(int i=index+4;i<L;i++){
res = std::min(res, cost(index, 0, G) + solve2(i));
}
return res;
}
int main(){
int N;
std::cin >> N;
while(N--){
std::cin >> S;
L = S.size();
int res = INF;
for(int i=0;i<L;i++){
res = std::min(res, solve(i));
}
std::cout << res << std::endl;
}
}
tottoripaper