#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int N = 1000000, F = 1e9;
struct Node{
int child[26];
short value, color;
Node(){
for(int i = 0; i < 26; i++) child[i] = -1;
value = color = 0;
}
};
int n, m, cur = 1;
Node trie[N];
string s[N], t[N];
bool dfs(int v, int d){
if(v == 0){
int ans = 0;
for(int i = 0; i < 26; i++) if(trie[v].child[i] != -1) ans |= dfs(trie[v].child[i], d+1);
return ans;
}
if(d & 1){
if(trie[v].color == 1){
return 1;
}else if(trie[v].color == 3){
return 1;
}else if(trie[v].value == 1){
return 1;
}else if(!(trie[v].value & 1)){
return 0;
}else{
bool ans = 1;
for(int i = 0; i < 26; i++){
if(trie[v].child[i] != -1) ans &= dfs(trie[v].child[i], d+1);
}
return ans;
}
}
if(trie[v].color == 2){
return 0;
}else if(trie[v].color == 3){
return 0;
}
else if(trie[v].value == 2){
return 0;
}else if(!(trie[v].value & 2)){
return 1;
}else{
bool ans = 0;
for(int i = 0; i < 26; i++){
if(trie[v].child[i] != -1) ans |= dfs(trie[v].child[i], d+1);
}
return ans;
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
cin >> n;
for(int i = 0; i < n; i++){
cin >> s[i];
int v = 0;
for(int j = 0; j < s[i].length(); j++){
if(trie[v].child[s[i][j] - 'a'] == -1){
trie[v].child[s[i][j] - 'a'] = cur++;
}
v = trie[v].child[s[i][j] - 'a'];
trie[v].value += 1;
}
trie[v].color += 1;
}
cin >> m;
for(int i = 0; i < m; i++){
cin >> t[i];
int v = 0;
for(int j = 0; j < t[i].length(); j++){
if(trie[v].child[t[i][j] - 'a'] == -1){
trie[v].child[t[i][j] - 'a'] = cur++;
}
v = trie[v].child[t[i][j] - 'a'];
trie[v].value += 2;
}
trie[v].color += 2;
}
bool ans = dfs(0, 0);
if(ans == 0) cout << "Emilija";
else cout << "Nina";
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int j = 0; j < s[i].length(); j++){
| ~~^~~~~~~~~~~~~~~
Main.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int j = 0; j < t[i].length(); j++){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
168536 KB |
Output is correct |
2 |
Correct |
77 ms |
168552 KB |
Output is correct |
3 |
Correct |
82 ms |
168576 KB |
Output is correct |
4 |
Correct |
82 ms |
168584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
168516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
168552 KB |
Output is correct |
2 |
Incorrect |
84 ms |
168592 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
168520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
90 ms |
168844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
168756 KB |
Output is correct |
2 |
Correct |
86 ms |
168772 KB |
Output is correct |
3 |
Correct |
90 ms |
168756 KB |
Output is correct |
4 |
Correct |
83 ms |
168772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
168900 KB |
Output is correct |
2 |
Correct |
86 ms |
168848 KB |
Output is correct |
3 |
Incorrect |
84 ms |
168844 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |