結果
問題 | No.233 めぐるはめぐる (3) |
ユーザー | cormoran |
提出日時 | 2016-01-14 18:04:51 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 307 ms / 1,000 ms |
コード長 | 2,293 bytes |
コンパイル時間 | 864 ms |
コンパイル使用メモリ | 88,260 KB |
実行使用メモリ | 13,696 KB |
最終ジャッジ日時 | 2023-10-19 23:07:18 |
合計ジャッジ時間 | 5,485 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 114 ms
13,292 KB |
testcase_01 | AC | 60 ms
9,868 KB |
testcase_02 | AC | 24 ms
6,704 KB |
testcase_03 | AC | 69 ms
10,560 KB |
testcase_04 | AC | 265 ms
13,696 KB |
testcase_05 | AC | 253 ms
13,696 KB |
testcase_06 | AC | 236 ms
13,696 KB |
testcase_07 | AC | 307 ms
13,696 KB |
testcase_08 | AC | 303 ms
13,696 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 63 ms
9,936 KB |
testcase_13 | AC | 120 ms
13,536 KB |
ソースコード
#include<iostream> #include<vector> #include<cassert> #include<string> #include<algorithm> #include<cstdio> #include<cstdlib> #include<cmath> #include<stack> #include<queue> #include<set> #include<map> #include<tuple> #include<unistd.h> using namespace std; typedef pair<int,int> pii; typedef long long ll; typedef ll int__; #define rep(i,j) for(int__ i=0;i<(int__)(j);i++) #define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++) #define all(v) v.begin(),v.end() template<typename T> ostream& operator << (ostream &os , const vector<T> &v){ rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : "\n"); return os; } template<typename T> istream& operator >> (istream &is , vector<T> &v){ rep(i,v.size()) is >> v[i]; return is; } #ifdef DEBUG void debug(){ cerr << endl; } #endif template<class F,class...R> void debug(const F &car,const R&... cdr){ #ifdef DEBUG cerr << car << " "; debug(cdr...); #endif } // 11 // inabameguru // i a a e u u : 6 // n m b g r : 5 // ni na ne nu const string MEGURU = "inabameguru"; const char vowel[] = {'a','i','u','e','o'}; bool is_vowel(char c){ rep(i,5) if(c == vowel[i]) return true; return false; } string ans = ""; set<string> S; bool make(string &s,unsigned int used,int used_vowel){ int cnt = __builtin_popcount(used); int left = MEGURU.size() - cnt; int left_none_vowel = left - (6 - used_vowel); if(6 - used_vowel < left_none_vowel) return false; if(cnt == (int)MEGURU.size()){ if(is_vowel(s.back()) and not S.count(s)){ ans = s; return true; } return false; } rep(i,MEGURU.size()){ if(used & (1<<i)) continue; if(s.size() > 0 and not is_vowel(s.back()) and not is_vowel(MEGURU[i])) continue; s.push_back(MEGURU[i]); if( make( s, used | (1<<i) , used_vowel + (is_vowel(MEGURU[i])))) return true; s.pop_back(); } return false; } bool solve(){ int N; cin >> N; rep(i,N){ string s; cin >> s; S.insert(s); } string s = ""; if( make(s,0,0) ){ cout << ans <<endl; } else { cout << "NO" << endl; } return false; } int main() { ios::sync_with_stdio(false); while(solve()); return 0; }