#include <bits/stdc++.h>
using namespace std;
const int A = 26;
const int LEN = 300'000;
const int NODES = LEN * A;
struct TrieNode
{
array<bool, 2> players;
array<int, A> next_nodes;
TrieNode()
{
players.fill(false);
next_nodes.fill(-1);
}
};
int N, M;
int current_trie_node = 0;
array<TrieNode, NODES + 1> trie;
int fetchNode()
{
trie[current_trie_node] = TrieNode();
return current_trie_node++;
}
const int ROOT = fetchNode();
void addString(const string &S, int player)
{
int current_node = ROOT;
for (int i = 0; i < (int)S.size(); ++i)
{
int letter = (S[i] - 'a');
if (trie[current_node].next_nodes[letter] == -1)
{
trie[current_node].next_nodes[letter] = fetchNode();
}
current_node = trie[current_node].next_nodes[letter];
trie[current_node].players[player] = true;
}
}
bool getWinner(int node, int player)
{
bool won = false;
for (int letter = 0; letter < A; ++letter)
{
if (trie[node].next_nodes[letter] != -1 &&
trie[trie[node].next_nodes[letter]].players[player])
{
won |= !getWinner(trie[node].next_nodes[letter], player ^ 1);
}
}
return won;
}
int main()
{
cin >> N;
for (int i = 0; i < N; ++i)
{
string S;
cin >> S;
addString(S, 0);
}
cin >> M;
for (int i = 0; i < M; ++i)
{
string S;
cin >> S;
addString(S, 1);
}
cout << (getWinner(ROOT, 0) ? "Nina" : "Emilija") << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
209 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
197 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
195 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
208 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
194 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
216 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
220 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |