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;
typedef long long ll;
struct Node{
int state, cnt[2];
Node *child[26];
Node(){
state = 0;
cnt[0] = cnt[1] = 0;
for(int i = 0; i < 26; i++)
child[i] = nullptr;
}
};
struct Trie{
Node *root = new Node;
void add(const string &s, int type){
Node *cur = root;
for(char ch : s){
int nxt = ch - 'a';
if (cur->child[nxt] == nullptr)
cur->child[nxt] = new Node;
cur = cur->child[nxt];
cur->cnt[type]++;
}
}
bool solve(Node *cur, int turn){
cur->state = 0;
for(int i = 0; i < 26; i++){
if (cur->child[i] == nullptr)
continue;
if (cur->child[i]->cnt[turn] && !solve(cur->child[i], turn ^ 1))
cur->state = 1;
}
return cur->state;
}
bool solve(){
return solve(root, 0);
}
};
int m, n;
Trie trie;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> m;
for(int i = 1; i <= m; i++){
string s;
cin >> s;
trie.add(s, 0);
}
cin >> n;
for(int i = 1; i <= n; i++){
string s;
cin >> s;
trie.add(s, 1);
}
cout << (trie.solve()? "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... |