結果
問題 | No.150 "良問"(良問とは言っていない |
ユーザー | tubo28 |
提出日時 | 2015-02-13 00:00:34 |
言語 | C++11 (gcc 11.4.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 3 ms
6,816 KB |
testcase_04 | AC | 3 ms
6,816 KB |
testcase_05 | AC | 3 ms
6,820 KB |
testcase_06 | AC | 99 ms
6,816 KB |
testcase_07 | AC | 3 ms
6,820 KB |
testcase_08 | AC | 3 ms
6,820 KB |
testcase_09 | AC | 7 ms
6,816 KB |
testcase_10 | AC | 43 ms
6,816 KB |
testcase_11 | AC | 47 ms
6,820 KB |
testcase_12 | AC | 31 ms
6,820 KB |
testcase_13 | AC | 48 ms
6,816 KB |
testcase_14 | AC | 57 ms
6,820 KB |
testcase_15 | AC | 54 ms
6,816 KB |
testcase_16 | AC | 7 ms
6,816 KB |
testcase_17 | AC | 21 ms
6,816 KB |
testcase_18 | AC | 62 ms
6,816 KB |
testcase_19 | AC | 65 ms
6,816 KB |
testcase_20 | AC | 68 ms
6,816 KB |
ソースコード
#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; } } }