結果
問題 | No.233 めぐるはめぐる (3) |
ユーザー |
![]() |
提出日時 | 2015-06-27 00:12:17 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 269 ms / 1,000 ms |
コード長 | 2,425 bytes |
コンパイル時間 | 937 ms |
コンパイル使用メモリ | 91,932 KB |
実行使用メモリ | 13,440 KB |
最終ジャッジ日時 | 2024-07-07 19:30:22 |
合計ジャッジ時間 | 4,989 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 |
ソースコード
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <iostream> #include <queue> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; map<string,int> memo; bool finished; bool isvowel(char c){ if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o') return true; return false; } void solve(string& str, string& dst, bool flg, int cnt){ if(finished) return; if(str == "***********"){ if(isvowel(dst[dst.size()-1]) && memo.count(dst) == 0){ cout << dst << endl; finished = true; } return; } vector<int> used(30, 0); if(dst == ""){ rep(i,str.length()){ char c = str[i]; str[i] = '*'; string tmp = dst+c; if(isvowel(c) && used[c-'a']==0){ used[c-'a'] = 1; solve(str, tmp, flg, 1); }else{ solve(str, tmp, flg, 0); } str[i] = c; } }else{ if(!isvowel(dst[dst.size()-1])){ rep(i,str.length()){ if(str[i] == '*') continue; if(!isvowel(str[i])) continue; char c = str[i]; str[i] = '*'; string tmp = dst+c; if(used[c-'a']==0){ used[c-'a'] = 1; solve(str, tmp, flg, 1); } str[i] = c; } }else if(cnt == 2 || flg){ rep(i,str.length()){ if(str[i] == '*') continue; if(isvowel(str[i])) continue; char c = str[i]; str[i] = '*'; string tmp = dst+c; solve(str, tmp, true, 0); str[i] = c; } }else{ rep(i,str.length()){ if(str[i] == '*') continue; char c = str[i]; str[i] = '*'; string tmp = dst+c; if(used[c-'a']==0){ used[c-'a'] = 1; solve(str, tmp, flg, cnt+1); } str[i] = c; } } } } int main(){ ios::sync_with_stdio(false); int N; cin >> N; rep(i,N){ string str; cin >> str; memo[str]++; } finished = false; string name = "inabameguru"; string dst = ""; solve(name, dst, false, 0); if(!finished){ cout << "NO" << endl; } return 0; }