#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <vector>
using namespace std;
typedef long long int ll;
const int maxn = 1e6;
ll n, m; // Nina = 0, Emi = 1
struct Vertex{
ll next[26];
ll mask = 0;
ll output = 0;
Vertex()
{
fill(begin(next), end(next), -1);
}
};
Vertex trie[maxn];
ll cnt = 1;
void add_trie(string s, int bit)
{
int u = 0;
for(auto c : s)
{
trie[u].mask |= (1 << bit);
if(trie[u].next[c - 'a'] == -1)
{
trie[u].next[c - 'a'] = cnt++;
}
u = trie[u].next[c - 'a'];
}
trie[u].mask |= (1 << bit);
trie[u].output++;
}
int dfs_trie(int u, int bit)
{
for(int i = 0; i <= 25; i++)
{
int chi = trie[u].next[i];
if(trie[u].next[i] == -1)
continue;
if((trie[chi].mask&(1LL << (bit^1))) && dfs_trie(chi, bit^1))
return 0;
}
return 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++)
{
string s;
cin >> s;
add_trie(s, 0); // Nina
}
cin >> m;
for(int i = 1; i <= m; i++)
{
string s;
cin >> s;
add_trie(s, 1); // Emi
}
trie[0].mask |= (1 << 1);
if(!dfs_trie(0, 1))
cout << "Nina";
else
cout << "Emilija";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
219400 KB |
Output is correct |
2 |
Correct |
77 ms |
219488 KB |
Output is correct |
3 |
Correct |
76 ms |
219456 KB |
Output is correct |
4 |
Correct |
80 ms |
219408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
219356 KB |
Output is correct |
2 |
Correct |
77 ms |
219396 KB |
Output is correct |
3 |
Correct |
138 ms |
219548 KB |
Output is correct |
4 |
Correct |
89 ms |
219368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
219432 KB |
Output is correct |
2 |
Correct |
78 ms |
219388 KB |
Output is correct |
3 |
Correct |
77 ms |
219396 KB |
Output is correct |
4 |
Correct |
77 ms |
219404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
219440 KB |
Output is correct |
2 |
Correct |
78 ms |
219468 KB |
Output is correct |
3 |
Correct |
77 ms |
219464 KB |
Output is correct |
4 |
Correct |
77 ms |
219468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
219468 KB |
Output is correct |
2 |
Correct |
92 ms |
219368 KB |
Output is correct |
3 |
Correct |
81 ms |
219584 KB |
Output is correct |
4 |
Correct |
82 ms |
219656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
219456 KB |
Output is correct |
2 |
Correct |
80 ms |
219476 KB |
Output is correct |
3 |
Correct |
82 ms |
219724 KB |
Output is correct |
4 |
Correct |
80 ms |
219616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
219468 KB |
Output is correct |
2 |
Correct |
81 ms |
219452 KB |
Output is correct |
3 |
Correct |
81 ms |
219596 KB |
Output is correct |
4 |
Correct |
84 ms |
219596 KB |
Output is correct |