結果
問題 | No.252 "良問"(良問とは言っていない (2) |
ユーザー | kopricky |
提出日時 | 2017-09-12 03:57:53 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 2,134 bytes |
コンパイル時間 | 1,155 ms |
コンパイル使用メモリ | 146,808 KB |
実行使用メモリ | 11,948 KB |
最終ジャッジ日時 | 2023-08-07 12:12:33 |
合計ジャッジ時間 | 2,366 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
5,476 KB |
testcase_01 | AC | 98 ms
5,496 KB |
testcase_02 | AC | 66 ms
8,816 KB |
testcase_03 | AC | 69 ms
11,948 KB |
testcase_04 | AC | 68 ms
11,884 KB |
testcase_05 | AC | 68 ms
11,880 KB |
testcase_06 | AC | 2 ms
5,436 KB |
ソースコード
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a,b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl #define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl #define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl #define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl using namespace std; typedef pair<int,int>P; const int MAX_N = 1000005; int pre[MAX_N],pos[MAX_N]; int main() { cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; rep(id,t){ string s; int n; cin >> s; n = (int)s.size(); rep(i,n+1){ pre[i] = 0; pos[i] = INF; } rep(i,n-6){ string hoge = s.substr(i,7); if(hoge == "problem"){ pre[i+6] = 1; i += 6; } } rep(i,n-6){ string hoge = s.substr(i,7); string cri = "problem"; int num = 0; rep(j,7){ if(hoge[j] != cri[j]){ num++; } } pos[i] = num; } rep(i,n){ pre[i+1] += pre[i]; } for(int i=n-1;i>=0;i--){ pos[i] = min(pos[i],pos[i+1]); } int ans = INF; rep(i,n-10){ string hoge = s.substr(i,4); string cri = "good"; int num = 0; rep(j,4){ if(hoge[j] != cri[j]){ num++; } } if(i == 0){ ans = min(ans,num+pos[4]); }else{ ans = min(ans,num+pre[i-1]+pos[i+4]); } } cout << ans << endl; } return 0; }