#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxN = 2e5+10;
int trie[mxN][26];
int node_cnt = 0;
bool stop[mxN][2];
int dp[mxN];
string alpha = "abcdefghijklmnopqrstuvwxyz";
void insert(string word, int flag) {
int node = 0;
for(auto c : word) {
if(trie[node][c-'a'] == 0) trie[node][c-'a'] = ++node_cnt;
node = trie[node][c-'a'];
}
stop[node][flag] = true;
}
void dfs(int node, int lvl = 0) {
if(lvl & 1) {
dp[node] = 1;
}
else {
dp[node] = 2;
}
bool has = false;
for(char c : alpha) {
int k = trie[node][c-'a'];
if(k) {
has = true;
dfs(k, lvl+1);
if(lvl & 1) dp[node] = max(dp[node], dp[k]);
else dp[node] = min(dp[node], dp[k]);
}
}
if(!has) {
if(stop[node][0] && stop[node][1]) {
if(lvl & 1) dp[node] = 1;
else dp[node] = 2;
}
else if(stop[node][0]) {
dp[node] = 1;
}
else dp[node] = 2;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; i++) {
string word;
cin >> word;
insert(word, 0);
}
int m;
cin >> m;
for(int i = 0; i < m; i++) {
string word;
cin >> word;
insert(word, 1);
}
dfs(0, 0);
cout << (dp[0] == 1 ? "Nina" : "Emilija");
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
9828 KB |
Output is correct |
2 |
Correct |
11 ms |
9060 KB |
Output is correct |
3 |
Correct |
10 ms |
8548 KB |
Output is correct |
4 |
Correct |
11 ms |
9572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9828 KB |
Output is correct |
2 |
Correct |
10 ms |
10336 KB |
Output is correct |
3 |
Correct |
9 ms |
9572 KB |
Output is correct |
4 |
Correct |
11 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
9308 KB |
Output is correct |
2 |
Correct |
11 ms |
9128 KB |
Output is correct |
3 |
Correct |
10 ms |
9560 KB |
Output is correct |
4 |
Correct |
11 ms |
9984 KB |
Output is correct |