#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e6;
const int ALPHABET = 28;
struct trie_node
{
int next_node[ALPHABET];
bool leaf;
vector<char> owner;
trie_node()
{
fill(next_node, next_node + ALPHABET, -1);
}
};
/*trie_node trie_nina[MAXN + 5];
trie_node trie_emilija[MAXN + 5];
*/
vector<trie_node> trie;
void add_string_nina(string input)
{
int v = 0;
for(char ch : input)
{
int c = ch - 'a';
if(trie[v].next_node[c] == -1)
{
trie[v].next_node[c] = trie.size();
trie.emplace_back();
}
v = trie[v].next_node[c];
if(trie[v].owner.size() == 0 || (trie[v].owner.size() == 1 && trie[v].owner[0] == 'E'))
trie[v].owner.push_back('N');
}
trie[v].leaf = true;
}
void add_string_emilija(string input)
{
int v = 0;
for(char ch : input)
{
int c = ch - 'a';
if(trie[v].next_node[c] == -1)
{
trie[v].next_node[c] = trie.size();
trie.emplace_back();
}
v = trie[v].next_node[c];
if(trie[v].owner.size() == 0 || (trie[v].owner.size() == 1 && trie[v].owner[0] == 'N'))
trie[v].owner.push_back('E');
}
trie[v].leaf = true;
}
bool dfs_nina(int v, int depth)
{
bool nina_has = false, emilija_has = false;
bool valid = false;
for(int i = 0; i < ALPHABET; i++)
{
if(trie[v].next_node[i] == -1)
continue;
if(trie[trie[v].next_node[i]].owner.size() == 1 && trie[trie[v].next_node[i]].owner[0] == 'N' && depth % 2 == 0) {
return true;
}
else if((trie[trie[v].next_node[i]].owner.size() == 1 && trie[trie[v].next_node[i]].owner[0] == 'E' && depth % 2 == 1))
{ return false;
}
else
{
if(trie[trie[v].next_node[i]].owner.size() == 2) {
bool temp = dfs_nina(trie[v].next_node[i], depth + 1);
if(temp)
valid = true;
nina_has = true;
emilija_has = true;
}
}
}
if(!emilija_has && depth % 2 == 1)
valid = true;
else if(!nina_has && depth % 2 == 0)
valid = false;
return valid;
}
int main()
{
trie_node root = trie_node();
trie.push_back(root);
int n, m;
cin >> n;
for(int i = 1; i <= n; i++)
{
string input;
cin >> input;
add_string_nina(input);
}
cin >> m;
for(int i = 1; i <= m; i++)
{
string input;
cin >> input;
add_string_emilija(input);
}
if(dfs_nina(0, 0))
cout << "Nina\n";
else
cout << "Emilija\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
20740 KB |
Output is correct |
2 |
Incorrect |
28 ms |
20744 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
20804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
20816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |