#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5+1;
vector<vector<array<int,3>>> nxt(mxN, vector<array<int,3>>(26));
//vector<bool> Nina winning(mxN);
bool dfs(int node, int depth)
{
int par = (depth & 1);
//cout << "I am " <<(par ? "Nina" : "Emilija") << " at starting depth " << depth << "\n";
bool res = !par;
bool noMove = true;
for (int i = 0; i < 26; ++i)
{
array<int,3>& p = nxt[node][i];
noMove &= (p[0] == 0 || p[2 - par] == 0);
if (p[0] != 0 & p[2-par])
{
//cout << "I am " << (par ? "Nina" : "Emilija") << " at following depth " << depth << ", char: [" << (char)('a' + i) << " " << p[0] << " " << p[1] << " " << p[2] << "]\n";
bool neigRes = dfs(p[0], depth+1);
//cout << "I am " << (par ? "Nina" : "Emilija") << " at returning depth " << depth << ", char: [" << (char)('a' + i) << " " << p[0] << " " << p[1] << " " << p[2] << "] Nina winning: " << neigRes << "\n";
if (par)
res |= neigRes;
else
res &= neigRes;
}
}
if (noMove)
{
res = !par;
//cout << "I am " << (par ? "Nina" : "Emilija") << " at noMove depth " << depth << ", Nina winning: " << res << "\n";
}
//cout << "I am " << (par ? "Nina" : "Emilija") << " at terminating depth " << depth << ", Nina winning: " << res << "\n";
return res;
}
int main()
{
int n; cin >> n;
string s;
int MAXID = 0;
while(n--)
{
cin >> s;
int node = 0;
for (char c : s)
{
array<int,3>& p = nxt[node][c-'a'];
if (p[0] == 0)
p[0] = ++MAXID;
p[1] = 1;
node = p[0];
}
}
int m; cin >> m;
while(m--)
{
cin >> s;
int node = 0;
for (char c : s)
{
array<int,3>& p = nxt[node][c-'a'];
if (p[0] == 0)
p[0] = ++MAXID;
p[2] = 1;
node = p[0];
}
}
cout << (dfs(0, 1) ? "Nina" : "Emilija") << "\n";
}
Compilation message
Main.cpp: In function 'bool dfs(int, int)':
Main.cpp:19:18: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
19 | if (p[0] != 0 & p[2-par])
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
67488 KB |
Output is correct |
2 |
Correct |
85 ms |
67608 KB |
Output is correct |
3 |
Correct |
86 ms |
67592 KB |
Output is correct |
4 |
Correct |
84 ms |
67540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
67588 KB |
Output is correct |
2 |
Correct |
85 ms |
67600 KB |
Output is correct |
3 |
Correct |
89 ms |
67548 KB |
Output is correct |
4 |
Correct |
88 ms |
67624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
67524 KB |
Output is correct |
2 |
Correct |
86 ms |
67516 KB |
Output is correct |
3 |
Correct |
86 ms |
67604 KB |
Output is correct |
4 |
Correct |
85 ms |
67500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
67540 KB |
Output is correct |
2 |
Correct |
86 ms |
67516 KB |
Output is correct |
3 |
Correct |
87 ms |
67612 KB |
Output is correct |
4 |
Correct |
86 ms |
67600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
67560 KB |
Output is correct |
2 |
Correct |
98 ms |
67788 KB |
Output is correct |
3 |
Correct |
95 ms |
67772 KB |
Output is correct |
4 |
Correct |
96 ms |
67692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
67532 KB |
Output is correct |
2 |
Correct |
96 ms |
67720 KB |
Output is correct |
3 |
Correct |
94 ms |
67704 KB |
Output is correct |
4 |
Correct |
92 ms |
67784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
67544 KB |
Output is correct |
2 |
Correct |
95 ms |
67720 KB |
Output is correct |
3 |
Correct |
100 ms |
67720 KB |
Output is correct |
4 |
Correct |
98 ms |
67796 KB |
Output is correct |