結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-26 20:46:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,188 bytes |
| コンパイル時間 | 1,301 ms |
| コンパイル使用メモリ | 161,640 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 01:54:54 |
| 合計ジャッジ時間 | 2,046 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 25;
const string good = "good";
const string problem = "problem";
int main(){
int T; cin >> T;
while(T--){
string S; cin >> S;
int N = (int)S.size();
vector<int> G(N, INF), P(N, INF);
for(int i=0;i<N;i++){
int t = i;
int s = t - (int)good.size() + 1;
if(s < 0)
continue;
int dif = 0;
for(int j=0;j<good.size();j++){
dif += S[s+j] != good[j];
}
G[i] = min(G[i-1], dif);
}
for(int i=N-1;i>=0;i--){
int s = i;
int t = s + (int)problem.size() - 1;
if(t >= N)
continue;
int dif = 0;
for(int j=0;j<problem.size();j++){
dif += S[s+j] != problem[j];
}
P[i] = min(P[i+1], dif);
}
int res = INF;
for(int i=1;i<N;i++)
res = min(res, G[i-1] + P[i]);
cout << res << endl;
}
return 0;
}