結果

問題 No.233 めぐるはめぐる (3)
ユーザー cormorancormoran
提出日時 2016-01-14 17:52:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 664 ms / 1,000 ms
コード長 2,031 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 88,108 KB
実行使用メモリ 13,776 KB
最終ジャッジ日時 2023-10-19 23:06:13
合計ジャッジ時間 6,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
13,372 KB
testcase_01 AC 58 ms
9,948 KB
testcase_02 AC 24 ms
6,784 KB
testcase_03 AC 67 ms
10,640 KB
testcase_04 AC 553 ms
13,776 KB
testcase_05 AC 497 ms
13,776 KB
testcase_06 AC 468 ms
13,776 KB
testcase_07 AC 660 ms
13,776 KB
testcase_08 AC 664 ms
13,776 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 55 ms
10,016 KB
testcase_13 AC 98 ms
13,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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
// n m b g r

// ni na ne nu 

const string MEGURU = "inabameguru";

const char consonant[] = {'a','i','u','e','o'};
bool is_consonant(char c){
    rep(i,5) if(c == consonant[i]) return true;
    return false;
}

string ans = "";
set<string> S;

bool make(string s,unsigned int used){
    if(__builtin_popcount(used) == (int)MEGURU.size()){
        if(is_consonant(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_consonant(s.back()) and
           not is_consonant(MEGURU[i])) continue;
        if( make( s + MEGURU[i], used | (1<<i)) ) return true;
    }
    return false;
}

bool solve(){
    
    int N; cin >> N;
    rep(i,N){
        string s; cin >> s;
        S.insert(s);
    }
    if( make("",0) ){
        cout << ans <<endl;
    } else {
        cout << "NO" << endl;
    }
    
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}
0