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;
using ll = long long;
vector<vector<ll>> trie(200040,vector<ll>(26,0));
vector<int> color(200040,0);
vector<int> res(200040,0);
vector<ll> depth(200040,0);
ll node_c=0;
void insert(string s,int x){
ll node =0;
ll d=depth[node];
for(auto c:s){
if(trie[node][c-'a']==0){node_c++;trie[node][c-'a']=node_c;}
node=trie[node][c-'a'];
depth[node]=d+1;
d++;
color[node]+=x;
}
}
void dfs(ll u){
//cout<<"*"<<u<<endl;
if(color[u]==1){
res[u]=1;return;
}
if(color[u]==-1){
res[u]=2;return;
}
bool flag=false;
set<int> s;
for(int i=0;i<26;i++){
if(trie[u][i]==0){continue;}
flag=true;
dfs(trie[u][i]);
s.insert(res[trie[u][i]]);
res[u]=res[trie[u][i]];
}
if(!flag){
if(depth[u]%2){res[u]=1;return;}
else{res[u]=2;return;}
}
if(depth[u]%2 && s.find(2)!=s.end()){res[u]=2;return;}
if(depth[u]%2==0 && s.find(1)!=s.end()){res[u]=1;return;}
}
void solve(){
ll a;cin>>a;
for(ll i=0;i<a;i++){
string s;cin>>s;
insert(s,1);
}
ll b;cin>>b;
for(ll i=0;i<b;i++){
string s;cin>>s;
insert(s,-1);
}
dfs(0);
if(res[0]==1){cout<<"Nina"<<endl;}
else{cout<<"Emilija"<<endl;}
}
int main(){
solve();
}
# | 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... |