結果

問題 No.233 めぐるはめぐる (3)
ユーザー どららどらら
提出日時 2015-06-27 00:12:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 285 ms / 1,000 ms
コード長 2,425 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 13,556 KB
最終ジャッジ日時 2023-09-22 02:42:54
合計ジャッジ時間 5,479 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
13,220 KB
testcase_01 AC 67 ms
9,656 KB
testcase_02 AC 30 ms
6,568 KB
testcase_03 AC 80 ms
10,436 KB
testcase_04 AC 255 ms
13,488 KB
testcase_05 AC 234 ms
13,496 KB
testcase_06 AC 219 ms
13,500 KB
testcase_07 AC 282 ms
13,476 KB
testcase_08 AC 285 ms
13,556 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 68 ms
10,028 KB
testcase_13 AC 121 ms
13,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0