#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
const int N = 2e5+5;
int idx = 0, idx2 = 0, n, m;
string x;
int dp[N];
struct node {
node *adj[26];
int id;
};
node *newNd() {
node *ret = new node;
for (int i = 0; i < 26; i++) {
ret->adj[i] = NULL;
}
ret->id = idx++;
return ret;
}
node *newNd2() {
node *ret = new node;
for (int i = 0; i < 26; i++) {
ret->adj[i] = NULL;
}
ret->id = idx2++;
return ret;
}
node *rt = newNd();
node *rt2 = newNd2();
void insert() {
node *cur = rt;
for (auto &c : x) {
if (cur->adj[c-'a'] == NULL)cur->adj[c-'a'] = newNd();
cur = cur->adj[c-'a'];
}
}
void insert2() {
node *cur = rt2;
for (auto &c : x) {
if (cur->adj[c-'a'] == NULL)cur->adj[c-'a'] = newNd2();
cur = cur->adj[c-'a'];
}
}
int sol(node *cur, node *cur2, int turn) {
int &ret = dp[cur->id];
if (~ret)return ret;
ret = 0;
for (int i = 0; i < 26; i++) {
if (!turn) {
if (cur->adj[i] != NULL) {
if (cur2->adj[i] == NULL)return ret = 1;
ret |= !sol(cur->adj[i], cur2->adj[i], (turn ^ 1));
}
} else {
if (cur2->adj[i] != NULL) {
if (cur->adj[i] == NULL)return ret = 1;
ret |= !sol(cur->adj[i], cur2->adj[i], (turn ^ 1));
}
}
}
return ret;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(dp, -1, sizeof dp);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
insert();
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> x;
insert2();
}
cout << (sol(rt, rt2, 0) ? "Nina" : "Emilija") << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1368 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1368 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1500 KB |
Output is correct |
4 |
Correct |
1 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
22108 KB |
Output is correct |
2 |
Correct |
13 ms |
20580 KB |
Output is correct |
3 |
Correct |
12 ms |
19548 KB |
Output is correct |
4 |
Correct |
14 ms |
21384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22364 KB |
Output is correct |
2 |
Correct |
13 ms |
23388 KB |
Output is correct |
3 |
Correct |
12 ms |
21848 KB |
Output is correct |
4 |
Correct |
11 ms |
22012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21084 KB |
Output is correct |
2 |
Correct |
13 ms |
20824 KB |
Output is correct |
3 |
Correct |
13 ms |
21084 KB |
Output is correct |
4 |
Correct |
13 ms |
22620 KB |
Output is correct |