이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK "task"
#define all(x) x.begin(), x.end()
const int N = 2e5 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const long long INFLL = 1e18 + 7;
using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
struct Node {
Node *child[26];
Node() {
for (int i = 0; i < 26; i ++)
child[i] = nullptr;
}
};
Node *root[2];
bool dfs(Node *Nina, Node *Emi, bool t) {
for (int c = 0; c < 26; c ++) {
if (t) {
if (Emi->child[c] == nullptr)
continue;
if (Nina->child[c] == nullptr)
return false;
if (!dfs(Nina->child[c], Emi->child[c], t ^ 1))
return false;
} else {
if (Nina->child[c] == nullptr)
continue;
if (Emi->child[c] == nullptr)
return true;
if (dfs(Nina->child[c], Emi->child[c], t ^ 1))
return true;
}
}
return t;
}
void solve(void) {
auto add = [&](string s, bool t) {
Node *p = root[t];
for (int i = 0; i < (int) s.size(); i ++) {
int c = s[i] - 'a';
if (p->child[c] == nullptr) p->child[c] = new Node();
p = p->child[c];
}
};
for (int i = 0; i < 2; i ++) root[i] = new Node();
int n; cin >> n;
for (int i = 1; i <= n; i ++) {
string s; cin >> s;
add(s, 0);
}
int m; cin >> m;
for (int i = 1; i <= m; i ++) {
string s; cin >> s;
add(s, 1);
}
cout << (dfs(root[0], root[1], 0) ? "Nina" : "Emilija");
}
signed main(void) {
cin.tie(0)->sync_with_stdio(0);
int test = 1;
// cin >> test;
while (test --) {
solve();
}
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... |