#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi st
#define se nd
#define INF INT_MAX/2
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int N = 2e5; //Number of nodes
const int ALPHA = 26; // Number of characters
int trie[N][ALPHA];
map<int,int> type;
int last_n = 0;
void insert(string &s, int from){
int curr_node = 0;
for(char it: s){
if(trie[curr_node][it-'a'] == 0){
trie[curr_node][it-'a'] = ++last_n;
if(type.count(last_n)) type[last_n] = 2;
else type[last_n] = from;
}
curr_node = trie[curr_node][it-'a'];
}
return;
}
bool wins(int node, int turn){
int cnt = 0, winner = 0;
for(int i=0; i <26; i++){
if(trie[node][i] && type[trie[node][i]] != (!(turn%2))){
cnt++;
if(wins(trie[node][i], turn+1)) winner++;
}
}
//cout << "from node " << node << " turn " << turn << " cnt: " << cnt<< " winner: " << winner << endl;
if(!cnt || cnt == winner) return false;
else return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n ;
while(n--){
string word;
cin >> word;
insert(word,0);
}
cin >> m;
while(m--){
string word;
cin >> word;
insert(word,1);
}
if(wins(0,0)) cout << "Nina\n";
else cout << "Emilija\n";
return 0;
}
# | 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... |