結果

問題 No.233 めぐるはめぐる (3)
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-10 18:06:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 68,188 KB
実行使用メモリ 7,504 KB
最終ジャッジ日時 2024-04-21 12:03:33
合計ジャッジ時間 7,100 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int N;
vector<string> names;

char vowel[6] = {'i', 'a' ,'a', 'e', 'u', 'u'},
     consonant[5] = {'n', 'b', 'm', 'g', 'r'};

bool v_used[6], c_used[5];

string answer;

void DFS(int v_num, int c_num, bool prev_is_consonants, string accum) {
    if (answer != "") return;

    if (v_num == 6 && c_num == 5) {
        if (find(names.begin(), names.end(), accum) == names.end()) {
            answer = accum;
        }
        return;
    }

    for (int i = 0; i < 6; i++) {
        if (!v_used[i]) {
            v_used[i] = true;
            accum.push_back(vowel[i]);
            DFS(v_num + 1, c_num, false, accum);
            v_used[i] = false;
            accum.pop_back();
        }
    }

    if (prev_is_consonants) return;

    for (int i = 0; i < 5; i++) {
        if (!c_used[i]) {
            c_used[i] = true;
            accum.push_back(consonant[i]);
            DFS(v_num, c_num + 1, true, accum);
            c_used[i] = false;
            accum.pop_back();
        }
    }
}

void Solve() {
    answer = "";
    DFS(0, 0, false, "");
    if (answer == "") cout << "NO" << endl;
    else cout << answer << endl;
}

int main() {
    cin >> N;

    for (int i = 0; i < N; i++) {
        string name;
        cin >> name;
        names.push_back(name);
    }

    Solve();

    return 0;
}
0