結果
問題 | No.252 "良問"(良問とは言っていない (2) |
ユーザー |
![]() |
提出日時 | 2015-07-25 01:22:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 807 ms |
コンパイル使用メモリ | 82,888 KB |
実行使用メモリ | 12,168 KB |
最終ジャッジ日時 | 2024-07-16 04:15:00 |
合計ジャッジ時間 | 1,766 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 |
ソースコード
#include <iostream>#include <vector>#include <cstdio>#include <sstream>#include <map>#include <string>#include <algorithm>#include <queue>#include <cmath>#include <set>using namespace std;string good = "good";string problem = "problem";int main(){int t;cin >> t;while(t--){string s;cin >> s;int n = s.size();vector<int> g(n, 1e9);int num_good = 0;for(int i=0; i+good.size()<=n; i++){int cnt = 0;for(int j=0; j<good.size(); j++){if(s[i+j] != good[j]) cnt++;}g[i] = cnt + num_good;if(cnt == 0) num_good++;}vector<int> p(n, 1e9);set<int> e;int num_pro = 0;for(int i=0; i+problem.size()<=n; i++){int cnt = 0;for(int j=0; j<problem.size(); j++){if(s[i+j] != problem[j]) cnt++;}p[i] = cnt + num_pro;if(cnt == 0){num_pro++;e.insert(i);}}for(int i=n-2; i>=0; i--){p[i] = min(p[i], p[i+1]);}int ans = 1e9;for(int i=0; i+good.size()+problem.size()<=n; i++){ans = min(ans, g[i] + p[i+good.size()] + (e.count(i) + e.count(i-1)?-1:0) );}cout << ans << endl;}return 0;}