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 pb push_back
#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 2048;
struct node{
int nxt[26];
node(){
for(int i = 0; i < 26; i++){
nxt[i] = -1;
}
}
};
struct Trie{
vector<node> trie;
void start(){
trie.pb(node());
}
void add(int ind, string s){
for(int i = 0; i < s.size(); i++){
if(trie[ind].nxt[s[i] - 'a'] == -1){
trie[ind].nxt[s[i] - 'a'] = trie.size();
trie.pb(node());
}
ind = trie[ind].nxt[s[i] - 'a'];
}
}
};
Trie tr1, tr2;
int dp(int ind1, int ind2, int turn){
if(turn){
bool win = 0;
for(int i = 0; i < 26; i++){
if(tr1.trie[ind1].nxt[i] == -1) continue;
if(tr1.trie[ind1].nxt[i] != -1 && tr2.trie[ind2].nxt[i] == -1) win = 1;
else win |= (!dp(tr1.trie[ind1].nxt[i], tr2.trie[ind2].nxt[i], (turn^1)));
}
return win;
}
else{
bool win = 0;
for(int i = 0; i < 26; i++){
if(tr2.trie[ind2].nxt[i] == -1) continue;
if(tr2.trie[ind2].nxt[i] != -1 && tr1.trie[ind1].nxt[i] == -1) win = 1;
else win |= (!dp(tr1.trie[ind1].nxt[i], tr2.trie[ind2].nxt[i], (turn^1)));
}
return win;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin>>n;
tr1.start();
for(int i = 0; i < n; i++){
string s;
cin>>s;
tr1.add(0, s);
}
int m;
cin>>m;
tr2.start();
for(int i = 0; i < m; i++){
string s;
cin>>s;
tr2.add(0, s);
}
int ans = dp(0, 0, 1);
if(ans) cout<<"Nina"<<endl;
else cout<<"Emilija"<<endl;
return 0;
}
Compilation message (stderr)
Main.cpp: In member function 'void Trie::add(long long int, std::string)':
Main.cpp:27:22: 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]
27 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
# | 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... |