# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
531332 |
2022-02-28T12:35:46 Z |
speedyArda |
Vlak (COCI20_vlak) |
C++17 |
|
37 ms |
34248 KB |
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e6;
const int ALPHABET = 28;
struct trie_node
{
long long next_node[ALPHABET];
bool leaf;
vector<char> owner;
int state = 0;
trie_node()
{
fill(next_node, next_node + ALPHABET, -1);
}
};
/*trie_node trie_nina[MAXN + 5];
trie_node trie_emilija[MAXN + 5];
*/
vector<trie_node> trie;
void add_string_nina(string input)
{
long long v = 0;
for(char ch : input)
{
long long c = ch - 'a';
if(trie[v].next_node[c] == -1)
{
trie[v].next_node[c] = trie.size();
trie.emplace_back();
}
v = trie[v].next_node[c];
trie[v].state |= 2;
//if(trie[v].owner.size() == 0 || (trie[v].owner.size() == 1 && trie[v].owner[0] == 'E'))
//trie[v].owner.push_back('N');
}
trie[v].leaf = true;
}
void add_string_emilija(string input)
{
long long v = 0;
for(char ch : input)
{
long long c = ch - 'a';
if(trie[v].next_node[c] == -1)
{
trie[v].next_node[c] = trie.size();
trie.emplace_back();
}
v = trie[v].next_node[c];
trie[v].state |= 1;
//if(trie[v].owner.size() == 0 || (trie[v].owner.size() == 1 && trie[v].owner[0] == 'N'))
//trie[v].owner.push_back('E');
}
trie[v].leaf = true;
}
bool dfs_nina(long long v, long long depth)
{
bool nina_has = false, emilija_has = false;
bool valid = false;
for(int i = 0; i < ALPHABET; i++)
{
if(trie[v].next_node[i] == -1)
continue;
if(trie[trie[v].next_node[i]].state == 2 && depth % 2 == 0) {
return true;
}
else if((trie[trie[v].next_node[i]].state == 1 && depth % 2 == 1))
{ return false;
}
else
{
if(trie[trie[v].next_node[i]].state == 3) {
bool temp = dfs_nina(trie[v].next_node[i], depth ^ 1);
if(temp)
valid = true;
nina_has = true;
emilija_has = true;
}
}
}
if(!emilija_has && depth % 2 == 1)
valid = true;
else if(!nina_has && depth % 2 == 0)
valid = false;
return valid;
}
int main()
{
trie_node root = trie_node();
root.state = 3;
trie.push_back(root);
int n, m;
cin >> n;
for(int i = 1; i <= n; i++)
{
string input;
cin >> input;
add_string_nina(input);
}
cin >> m;
for(int i = 1; i <= m; i++)
{
string input;
cin >> input;
add_string_emilija(input);
}
if(dfs_nina(0, 0))
cout << "Nina\n";
else
cout << "Emilija\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
960 KB |
Output is correct |
2 |
Correct |
1 ms |
960 KB |
Output is correct |
3 |
Correct |
1 ms |
960 KB |
Output is correct |
4 |
Incorrect |
1 ms |
932 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
584 KB |
Output is correct |
2 |
Correct |
1 ms |
960 KB |
Output is correct |
3 |
Incorrect |
1 ms |
584 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
584 KB |
Output is correct |
2 |
Correct |
1 ms |
960 KB |
Output is correct |
3 |
Correct |
1 ms |
960 KB |
Output is correct |
4 |
Incorrect |
1 ms |
584 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
34248 KB |
Output is correct |
2 |
Incorrect |
37 ms |
34220 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
34216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
34224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |