#include <bits/stdc++.h>
using namespace std;
struct TrieNode {
TrieNode() {
memset(canWin, -1, sizeof canWin);
memset(nextNode, -1, sizeof nextNode);
memset(subtreeSum, 0, sizeof subtreeSum);
}
int canWin[2];
int subtreeSum[2];
int nextNode[26];
};
struct Trie {
Trie() {
root = fetchNode();
}
void insertWord(const string& s, int color) {
int current = root;
for (char letter : s) {
if (nodes[current].nextNode[letter - 'a'] == -1) {
nodes[current].nextNode[letter - 'a'] = fetchNode();
}
current = nodes[current].nextNode[letter - 'a'];
++nodes[current].subtreeSum[color];
}
}
int canWin(int node = 0, int turn = 0) {
if (nodes[node].canWin[turn] != -1) {
return nodes[node].canWin[turn];
}
for (int edge = 0; edge < 26; ++edge) {
int child = nodes[node].nextNode[edge];
if (child != -1 && nodes[child].subtreeSum[turn] > 0 && canWin(child, turn ^ 1) == 0) {
return nodes[node].canWin[turn] = 1;
}
}
return nodes[node].canWin[turn] = 0;
}
int fetchNode() {
TrieNode node;
nodes.push_back(node);
return (int)nodes.size() - 1;
}
int root;
vector<TrieNode> nodes;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Trie trie;
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
trie.insertWord(s, 0);
}
int m;
cin >> m;
while (m--) {
string s;
cin >> s;
trie.insertWord(s, 1);
}
cout << (trie.canWin() == 1 ? "Nina" : "Emilija");
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
864 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
864 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |