結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
tubo28
|
| 提出日時 | 2015-02-13 00:00:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 5,000 ms |
| コード長 | 4,096 bytes |
| コンパイル時間 | 1,413 ms |
| コンパイル使用メモリ | 160,836 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-11 01:47:07 |
| 合計ジャッジ時間 | 2,629 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream & operator>>(istream & is, vector<T> &);
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream &, tuple<T...> &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream & is, tuple<T...> & t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream & operator>>(istream & is, tuple<T...> & t){ _it<0>(is, t); return is; }
template<class T, class U> istream & operator<<(istream & is, pair<T,U> & p){ return is >> p.first >> p.second; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> istream & operator>>(istream & is, vector<T> & v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
char good[] = "good";
char prob[] = "problem";
int popcount(unsigned long long x){
x = ((x & 0xaaaaaaaaaaaaaaaaULL) >> 1) + (x & 0x5555555555555555ULL);
x = ((x & 0xccccccccccccccccULL) >> 2) + (x & 0x3333333333333333ULL);
x = ((x & 0xf0f0f0f0f0f0f0f0ULL) >> 4) + (x & 0x0f0f0f0f0f0f0f0fULL);
x = ((x & 0xff00ff00ff00ff00ULL) >> 8) + (x & 0x00ff00ff00ff00ffULL);
x = ((x & 0xffff0000ffff0000ULL) >> 16) + (x & 0x0000ffff0000ffffULL);
x = ((x & 0xffffffff00000000ULL) >> 32) + (x & 0x00000000ffffffffULL);
return (int)x;
}
int find_good(string const & good, string const & s){
rep(i,s.size()-3){
bool ok = true;
rep(j,4){
if(good[j]=='*') continue;
if(s[i+j]!=good[j]){
ok = false;
break;
}
}
if(ok) return i;
}
return -1;
}
int find_prob(string const & prob, string const & s){
for(int i = s.size()-7; i>=0; i--){
bool ok = true;
rep(j,7){
if(prob[j]=='*') continue;
if(s[i+j]!=prob[j]){
//dump(s[i+j],prob[j]);
ok = false;
break;
}
}
if(ok) return i;
}
return -1;
}
int main(){
// string s = "problemgood";
// cout << find_prob("problem",s) << endl;
// cout << find_good("good",s) << endl;
// return 0;
int n;
while(cin >> n){
rep(i,n){
int ans = 11;
string s; cin >> s;
rep(X,1<<4){
rep(Y,1<<7){
string x = good, y = prob;
rep(j,4)if(X>>j&1) x[j] = '*';
rep(j,7)if(Y>>j&1) y[j] = '*';
int a = find_good(x,s);
int b = find_prob(y,s);
int p = popcount(X)+popcount(Y);
if(a==-1 || b==-1) continue;
if(a+4<=b){
if(ans > p){
ans = p;
//dump(a,b);
}
}
}
}
cout << ans << endl;
}
}
}
tubo28