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;
struct Trie{
struct Trie *child[26];
bool b[2]; //nina-0 emilija-1
};
struct Trie *createNode(){
struct Trie *nodo = new Trie;
for(int i=0; i<26; i++){
nodo->child[i] = NULL;
}
nodo->b[0] = false; nodo->b[1] = false;
return nodo;
}
void insert(struct Trie *root, string key, int turno){
struct Trie *curr = root;
for(int i=0; i<(int)key.size(); i++){
int index = key[i] - 'a';
if(!curr->child[index]){
curr->child[index] = createNode();
}
curr = curr->child[index];
curr->b[turno] = true;
}
}
bool gana(struct Trie *root,int turno){
struct Trie *curr = root;
bool noContinua = true;
for(int i=0; i<26; i++){
if(curr->child[i]){
struct Trie *sig = curr->child[i];
if(sig->b[1-turno]){
noContinua = false;
if(!gana(sig,1-turno)){
return true;
}
}
}
}
return noContinua;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
struct Trie *root = createNode();
for(int t=0; t<2; t++){
cin >> n;
for(int i=0; i<n; i++){
string s;
cin >> s;
insert(root,s,t);
}
}
bool win = false;
for(int i=0; i<26; i++){
if(root->child[i]){
struct Trie *sig = root->child[i];
if(sig->b[0]){
win = max(win,gana(sig,0));
}
}
}
if(win) cout << "Nina\n";
else cout << "Emilija\n";
}
# | 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... |