This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;
struct Trie{
struct Node{
Node *child[26];
bool Ninawin;
bool Ninas, Emilijas;
Node(){
for(int i=0; i<26; ++i) child[i] = NULL;
Ninawin = true;
Ninas = Emilijas = false;
}
} ;
Node *root;
Trie() {root = new Node(); }
void add(string s, int who){
Node *p = root;
for(char c : s){
int pos = c - 'a';
if (p -> child[pos] == NULL) p -> child[pos] = new Node();
p = p -> child[pos];
if (who == 0) p -> Ninas = true;
else p -> Emilijas = true;
}
}
bool dfs(Node *p, int turn){
bool ok = false;
// In Nina's turn, she just need to make one way to win
// In Emlija's turn, Nina must make all way winning
p -> Ninawin = (turn == 1);
for(int pos = 0; pos < 26; pos++) {
if (p -> child[pos] == NULL) continue;
if (turn == 0 && p -> child[pos] -> Ninas)
ok = true, p -> Ninawin |= dfs(p -> child[pos], turn ^ 1);
else if (turn == 1 && p -> child[pos] -> Emilijas)
ok = true, p -> Ninawin &= dfs(p -> child[pos], turn ^ 1);
}
if (ok == false) p -> Ninawin = (turn == 1);
return (p -> Ninawin);
}
} trie;
int main(){
// freopen("icebearat.inp", "r", stdin);
// freopen("icebearat.out", "w", stdout);
int n, m; string s;
cin >> n;
while(n--){
cin >> s;
trie.add(s, 0);
}
cin >> m;
while(m--){
cin >> s;
trie.add(s, 1);
}
trie.dfs(trie.root, 0);
cout << (trie.root -> Ninawin ? "Nina" : "Emilija");
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... |