#include <bits/stdc++.h>
#define Pc_champs ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
#define ll long long
//#define int long long
int const N = 1e5 + 2, LOG = 17, N2 = 2 * N + 1, M = 1e9 + 7, SQ = 400;
int n, m;
struct Node {
Node *link[26];
int idx{};
bool n{}, e{};
};
Node *root;
void init() {
root = new Node();
}
void insert(string &s, bool isn) {
Node *node = root;
int j = 1;
for (char &i: s) {
if (node->link[i - 'a'] == NULL) node->link[i - 'a'] = new Node();
node = node->link[i - 'a'];
node->idx = j++;
if (isn) node->n = true;
else node->e = true;
}
}
bool win(Node *node) {
if (node->idx & 1) {//emilija play
for (int i = 0; i < 26; ++i) {
if (node->link[i] != NULL) {
if (!node->link[i]->n) return false;
}
}
for (int i = 0; i < 26; ++i) {
if (node->link[i] != NULL) {
if (!win(node->link[i])) return false;
}
}
return true;
} else {//nina play
for (int i = 0; i < 26; ++i) {
if (node->link[i] != NULL) {
if (!node->link[i]->e) return true;
}
}
for (int i = 0; i < 26; ++i) {
if (node->link[i] != NULL) {
if (win(node->link[i])) return true;
}
}
return false;
}
}
void dowork() {
cin >> n;
init();
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
insert(s, 1);
}
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> s;
insert(s, 0);
}
cout << (win(root) ? "Nina" : "Emilija");
}
signed main() {
Pc_champs
int t = 1;
//cin >> t;
while (t--) {
dowork();
cout << "\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... |