結果
| 問題 |
No.233 めぐるはめぐる (3)
|
| コンテスト | |
| ユーザー |
cormoran
|
| 提出日時 | 2016-01-14 18:04:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 265 ms / 1,000 ms |
| コード長 | 2,293 bytes |
| コンパイル時間 | 884 ms |
| コンパイル使用メモリ | 87,592 KB |
| 実行使用メモリ | 13,568 KB |
| 最終ジャッジ日時 | 2024-09-19 19:04:34 |
| 合計ジャッジ時間 | 4,268 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 |
ソースコード
#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;
}
cormoran