#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define vvb vector<vb>
#define pb push_back
#define ppb pop_back
#define read(a) for(auto &x:a) cin >> x;
#define print(a) for(auto x:a) cout << x << " "; cout << "\n";
#define vc vector<char>
#define vvc vector<vc>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define double ld
#define int long long
const int INF = 4e18;
const int N = (int)2e5+10, A = 26;
struct Trie{
vvi trie;
int top = 1;
Trie(){
trie = vvi(N, vi(A, -1));
}
void insert(string s){
int c = 0;
for(int i=0; i<s.size(); i++){
if(trie[c][s[i]-'a'] == -1) trie[c][s[i]-'a'] = top++;
c = trie[c][s[i]-'a'];
}
}
};
Trie a, b;
bool win(int nda, int ndb, int player){
for(int i=0; i<A; i++){
if(player == 0){
if((a.trie[nda][i] != -1 && b.trie[ndb][i] == -1)
|| (a.trie[nda][i] != -1 && b.trie[ndb][i] != -1 &&
!win(a.trie[nda][i], b.trie[ndb][i], (player^1)))) return true;
} else {
if((a.trie[nda][i] == -1 && b.trie[ndb][i] != -1)
|| (a.trie[nda][i] != -1 && b.trie[ndb][i] != -1 &&
!win(a.trie[nda][i], b.trie[ndb][i], (player^1)))) return true;
}
}
return false;
}
void solve(){
int n, m;
cin >> n;
for(int i=0; i<n; i++){
string s; cin >> s;
a.insert(s);
}
cin >> m;
for(int i=0; i<m; i++){
string s; cin >> s;
b.insert(s);
}
cout << (win(0, 0, 0) ? "Nina\n" : "Emilija\n");
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
// cin >> tt;
while(tt--)
solve();
return 0;
}
Compilation message
Main.cpp: In member function 'void Trie::insert(std::string)':
Main.cpp:38:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
97288 KB |
Output is correct |
2 |
Correct |
52 ms |
97336 KB |
Output is correct |
3 |
Correct |
53 ms |
97384 KB |
Output is correct |
4 |
Correct |
52 ms |
97308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
97356 KB |
Output is correct |
2 |
Correct |
52 ms |
97300 KB |
Output is correct |
3 |
Correct |
54 ms |
97384 KB |
Output is correct |
4 |
Correct |
52 ms |
97276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
97288 KB |
Output is correct |
2 |
Correct |
53 ms |
97336 KB |
Output is correct |
3 |
Correct |
52 ms |
97276 KB |
Output is correct |
4 |
Correct |
53 ms |
97360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
97392 KB |
Output is correct |
2 |
Correct |
52 ms |
97304 KB |
Output is correct |
3 |
Correct |
52 ms |
97264 KB |
Output is correct |
4 |
Correct |
51 ms |
97332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
97544 KB |
Output is correct |
2 |
Correct |
62 ms |
97572 KB |
Output is correct |
3 |
Correct |
62 ms |
97480 KB |
Output is correct |
4 |
Correct |
62 ms |
97508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
97532 KB |
Output is correct |
2 |
Correct |
62 ms |
97576 KB |
Output is correct |
3 |
Correct |
63 ms |
97484 KB |
Output is correct |
4 |
Correct |
68 ms |
97484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
97476 KB |
Output is correct |
2 |
Correct |
62 ms |
97584 KB |
Output is correct |
3 |
Correct |
62 ms |
97592 KB |
Output is correct |
4 |
Correct |
63 ms |
97524 KB |
Output is correct |