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;
#define nline "\n"
using uint = unsigned int;
using ull = unsigned long long;
using ll = long long;
const ll M = 1e9 + 7;
const ll M2 = 998244353;
const ll INF = 2e18;
const ll N = 3e5 + 10;
const double Degree = 57.2958;
/***************************************Debug***********************************************************/
/***************************************Debug***********************************************************/
/***************************************Debug***********************************************************/
#ifndef ONLINE_JUDGE
#define debug(x) cerr<< #x << " ";_print(x);cerr<<nline;
#else
#define debug(x)
#endif
void _print(int x) {cerr << x;}
void _print(bool x) {cerr << x;}
void _print(char x) {cerr << x;}
void _print(string x) {cerr << x;}
void _print(ll x) {cerr << x;}
void _print(ull x) {cerr << x;}
void _print(float x) {cerr << x;}
void _print(double x) {cerr << x;}
template<class T>void _print(set<T> v);
template<class T>void _print(vector<T> v);
template<class T>void _print(multiset<T> v);
template<class T>void _print(unordered_set<T> v);
template<class T, class V>void _print(map<T, V> v);
template<class T, class V>void _print(unordered_map<T, V> v);
template<class T>void _print(vector<vector<T>> v);
template<class T>void _print(stack<T> v);
template<class T>void _print(queue<T> v);
template<class T, class V>void _print(pair<T, V> p);
template<class T>void _print(queue<T> v) {cerr << "[ "; while (!v.empty()) {_print(v.front()); cerr << " "; v.pop();} cerr << " ]";}
template<class T>void _print(stack<T> v) {cerr << "[ "; while (!v.empty()) {_print(v.top()); cerr << " "; v.pop();} cerr << " ]";}
template<class T, class V>void _print(pair<T, V> p) {_print(p.first); cerr << " "; _print(p.second); cerr << nline;}
template<class T>void _print(set<T> v) {cerr << "[ "; for (auto &i : v) {_print(i); cerr << " ";} cerr << "]";}
template<class T>void _print(vector<T> v) {cerr << "[ "; for (auto &i : v) {_print(i); cerr << " ";} cerr << "]";}
template<class T>void _print(multiset<T> v) {cerr << "[ "; for (auto &i : v) {_print(i); cerr << " ";} cerr << "]";}
template<class T>void _print(unordered_set<T> v) {cerr << "[ "; for (auto &i : v) {_print(i); cerr << " ";} cerr << "]";}
template<class T, class V>void _print(map<T, V> v) {cerr << "[ "; for (auto &i : v) {_print(i.first); cerr << " "; _print(i.second); cerr << "\n";} cerr << "]";}
template<class T, class V>void _print(unordered_map<T, V> v) {cerr << "[ "; for (auto &i : v) {_print(i.first); cerr << " "; _print(i.second); cerr << "\n";} cerr << "]";}
template<class T>void _print(vector<vector<T>> v) {cerr << "[ "; for (auto &i : v) {_print(i); cerr << nline;} cerr << "]";}
/************************************************************************************************************/
/************************************************************************************************************/
/************************************************************************************************************/
class Node{
public:
vector<Node*> links;
Node(){
links.resize(26, nullptr);
}
};
class Trie{
public:
Node *root;
Trie(){
root = new Node();
}
void insert(string &s){
Node *node = root;
for(auto &val: s){
if(!node->links[val - 'a']){
node->links[val - 'a'] = new Node();
}
node = node->links[val - 'a'];
}
}
};
map<Node *, Node *> mp;
void dfs(Node *n, Node *e){
mp[n] = e;
for(int i=0;i<26;i++){
if(n->links[i]){
dfs(n->links[i], (e?e->links[i]:nullptr));
}
}
}
map<pair<Node *, bool>, bool> dp;
bool func(Node *n, bool ok){
if(!n)
return false;
Node *e = mp[n];
if(!e)
return true;
if(dp.find({n, ok}) != dp.end())return dp[{n, ok}];
if(ok){
bool ans = false;
for(int i=0;i<26;i++){
if(n->links[i]){
ans |= func(n->links[i], !ok);
}
}
return ans;
}
bool ans = true;
for(int i=0;i<26;i++){
if(e->links[i]){
ans &= func(n->links[i], !ok);
}
}
return dp[{n, ok}] = ans;
}
void solve()
{
int n;cin>>n;
Trie Nina, Emilija;
for(int i=0;i<n;i++){
string s;cin>>s;
Nina.insert(s);
}
int m;cin>>m;
for(int i=0;i<m;i++){
string s;cin>>s;
Emilija.insert(s);
}
dfs(Nina.root, Emilija.root);
cout<<(func(Nina.root, true)?"Nina":"Emilija")<<nline;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("debug.txt", "w", stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
// prec();
for (int i = 1; i <= t; i++)
{
// cout<<"Case "<<i<<": ";
solve();
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:135:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
135 | freopen("debug.txt", "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |