This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Node {
bool word[2]{};
Node * child[26]{};
};
Node * root = new Node();
void addWord(string s, int type) {
Node * cur = root;
for (char c : s) {
if (!cur->child[c-'a']) cur->child[c-'a'] = new Node();
cur = cur->child[c-'a'];
cur->word[type] = true;
}
}
bool winner(Node * cur, int turn = 0, string s = "") {
for (int i = 0; i < 26; ++i) {
string t = s;
t.push_back('a'+i);
if (cur->child[i] && cur->child[i]->word[turn] && winner(cur->child[i], 1-turn, t) == turn) return turn;
}
return 1 - turn;
}
int main() {
int n; cin >> n;
while (n--) {
string s; cin >> s;
addWord(s, 0);
}
int m; cin >> m;
while (m--) {
string s; cin >> s;
addWord(s, 1);
}
cout << (winner(root) ? "Emilija" : "Nina") << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |