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<bits/stdc++.h>
#define endl "\n"
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const int alphabet = 26;
const int maxn = 2e5 + 10;
struct trie
{
int nxt[alphabet], state[2];
bool leaf, is_word[2];
trie()
{
memset(nxt, -1, sizeof(nxt));
leaf = true;
is_word[0] = is_word[1] = false;
state[0] = state[1] = 0;
}
}tree[maxn];
int last_used;
void add(int root, string &word, int pos, int player)
{
if (pos == word.size())
{
tree[root].is_word[player] = 1;
return;
}
int &neib = tree[root].nxt[word[pos] - 'a'];
if (neib == -1)
neib = ++ last_used;
tree[root].leaf = false;
add(neib, word, pos + 1, player);
tree[root].is_word[0] |= tree[neib].is_word[0];
tree[root].is_word[1] |= tree[neib].is_word[1];
}
void dfs(int root)
{
if (tree[root].leaf)
{
tree[root].state[0] = tree[root].state[1] = 0;
return;
}
if (tree[root].is_word[0] == false)
{
///cout << "GOOD " << root << endl;
tree[root].state[0] = 0;
tree[root].state[1] = 1;
return;
}
if (tree[root].is_word[1] == false)
{
///cout << "BAD " << root << endl;
tree[root].state[0] = 1;
tree[root].state[1] = 0;
return;
}
int neib;
for (int i = 0; i < alphabet; i ++)
{
neib = tree[root].nxt[i];
if (neib == -1)
continue;
dfs(neib);
/**cout << root << " : " << neib << endl;
cout << tree[neib].is_word[1] << endl;
cout << tree[neib].state[0] << endl;*/
if (!tree[neib].state[0] && tree[neib].is_word[1])
tree[root].state[1] = true;
if (!tree[neib].state[1] && tree[neib].is_word[0])
tree[root].state[0] = true;
}
///cout << "back " << root << " " << tree[root].state[0] << " : " << tree[root].state[1] << endl;
}
int n, m;
void solve()
{
string word;
cin >> n;
for (int i = 1; i <= n; i ++)
{
cin >> word;
add(0, word, 0, 0);
}
cin >> m;
for (int i = 1; i <= m; i ++)
{
cin >> word;
add(0, word, 0, 1);
}
dfs(0);
if (tree[0].state[0])
cout << "Nina" << endl;
else
cout << "Emilija" << endl;
}
int main()
{
solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void add(int, std::string&, int, int)':
Main.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if (pos == word.size())
| ~~~~^~~~~~~~~~~~~~
# | 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... |