結果

問題 No.233 めぐるはめぐる (3)
ユーザー motimoti
提出日時 2015-06-27 02:29:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 1,185 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 72,292 KB
実行使用メモリ 13,584 KB
最終ジャッジ日時 2023-09-22 03:04:25
合計ジャッジ時間 3,931 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
13,108 KB
testcase_01 AC 69 ms
9,656 KB
testcase_02 AC 33 ms
6,564 KB
testcase_03 AC 77 ms
10,524 KB
testcase_04 AC 139 ms
13,512 KB
testcase_05 AC 161 ms
13,584 KB
testcase_06 AC 156 ms
13,520 KB
testcase_07 AC 190 ms
13,480 KB
testcase_08 AC 190 ms
13,536 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 71 ms
9,796 KB
testcase_13 AC 116 ms
13,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <deque>
#include <cstdlib>

using namespace std;

set<string> st;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

string s;
string v1 = "bgmnr";
string v2 = "aiue";
int numv1[5] = {1,1,1,1,1}, numv2[4] = {2,1,2,1};

void dfs(bool isshi) {
  if(isshi) {
    rep(i, 4) {
      if(numv2[i] > 0) {
        s.push_back(v2[i]);
        numv2[i]--;
        dfs(false);
        s.pop_back();
        numv2[i]++;
      }
    }
  }
  else {
    bool check = true;
    rep(i, 4) {
      if(numv2[i] > 0) {
        check = false;
        s.push_back(v2[i]);
        numv2[i]--;
        dfs(false);
        s.pop_back();
        numv2[i]++;
      }
    }
    rep(i, 5) {
      if(numv1[i] > 0) {
        check = false;
        s.push_back(v1[i]);
        numv1[i]--;
        dfs(true);
        s.pop_back();
        numv1[i]++;
      }
    }
    if(check) {
      if(!st.count(s)) {
        cout << s << endl;
        exit(0);
      }
    }
  }
}

int main() {

  int N; cin >> N;
  rep(i, N) {
    string s; cin >> s;
    st.insert(s);
  }
  dfs(false);

  cout << "NO\n";

  return 0;
}
0