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>
using namespace std;
typedef long long ll;
#define int long long
#define F first
#define S second
#define endl '\n'
int const M = 1e6 + 10 , mod = 1e9 + 7;
ll n , T , Next[M][30] , vis[M][4] , Winner[M] , cnt = 1;
string s;
inline void Dfs(int node , int cur , int index) {
vis[node][cur] = 1;
if(index == s.size()) return;
int Char = s[index] - 'a';
if(!Next[node][Char]) Next[node][Char] = ++cnt;
Dfs(Next[node][Char] , cur , index + 1);
}
inline void Get(int node , int dep) { //cout << "Node = " << node << endl;
int have[4] = {0};
for(int i = 0 ; i < 26 ; ++i) {
if(Next[node][i]) {
Get(Next[node][i] , dep + 1);
have[Winner[Next[node][i]]] = 1;
}
}
if(!have[1] && !have[2]) { //cout << "node = " << node << endl;
if(dep % 2) Winner[node] = 2;
else Winner[node] = 1;
return;
}
if(!vis[node][1] || !vis[node][2]) {
if(!vis[node][1]) Winner[node] = 2;
else Winner[node] = 1;
//cout << node << " " << vis[node][1] << " " << vis[node][2] << " " << Winner[node] << endl;
return;
}
if(dep % 2) {
if(have[1]) Winner[node] = 1;
else Winner[node] = 2;
}
else {
if(have[2]) Winner[node] = 2;
else Winner[node] = 1;
}
}
main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);
cin >> n;
for(int i = 1 ; i <= n ; ++i) {
cin >> s;
Dfs(1 , 1 , 0);
}
cin >> n;
for(int i = 1 ; i <= n ; ++i) {
cin >> s;
Dfs(1 , 2 , 0);
}
Get(1 , 1);
if(Winner[1] == 1) cout << "Nina" << endl;
else cout << "Emilija" << endl;
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void Dfs(long long int, long long int, long long int)':
Main.cpp:15:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | if(index == s.size()) return;
| ~~~~~~^~~~~~~~~~~
Main.cpp: At global scope:
Main.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
56 | main() {
| ^~~~
# | 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... |