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>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5+5;
int tr[N][26], win[N], p[N][2], cnt = 0;
void insert(string &s, int player){
int now = 0;
for(auto c : s){
p[now][player] = 1;
if(!tr[now][c-'a']) now = tr[now][c-'a'] = ++cnt;
else now = tr[now][c-'a'];
}
p[now][player] = 1;
}
void dfs(int now, int turn = 1){
bool has = 0, ok = 0;
for(int i = 0;i < 26;i++){
if(!tr[now][i]) continue;
dfs(tr[now][i],turn^1);
ok = 1;
if(win[tr[now][i]]) has = 1;
}
if(!ok){
if(p[now][turn]) win[now] = 1;
}else if(!has) win[now] = 1;
}
signed main(){
fastio
int n;
cin >> n;
for(int i = 0;i < n;i++){
string s;
cin >> s;
insert(s,0);
}
int m;
cin >> m;
for(int i = 0;i < m;i++){
string s;
cin >> s;
insert(s,1);
}
dfs(0);
bool ww = 0;
for(int i = 0;i < 26;i++){
if(tr[0][i]){
ww |= win[tr[0][i]];
}
}
cout << (ww ? "Nina" : "Emilija") << "\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... |