Submission #531321

# Submission time Handle Problem Language Result Execution time Memory
531321 2022-02-28T12:03:05 Z speedyArda Vlak (COCI20_vlak) C++14
0 / 70
35 ms 19772 KB
#include "bits/stdc++.h"

using namespace std;

const int MAXN = 2e5;

struct trie_node 
{
    int next_node[26];
    bool leaf;
    vector<char> owner;
    trie_node() 
    {
        fill(next_node, next_node + 26, -1);
    }
};
/*trie_node trie_nina[MAXN + 5];

trie_node trie_emilija[MAXN + 5];
*/

vector<trie_node> trie;



void add_string_nina(string input) 
{
    int v = 0;
    for(char ch : input) 
    {
        int 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];
        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) 
{
    int v = 0;
    for(char ch : input) 
    {
        int 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];
        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(int v, int depth) 
{
    bool nina_has = false, emilija_has = false;
    bool valid = false;
    bool children = false;
    for(int i = 0; i < 26; i++) 
    {
        if(trie[v].next_node[i] == -1)
            continue;
        children = true;
        if(trie[trie[v].next_node[i]].owner.size() == 1 && trie[trie[v].next_node[i]].owner[0] == 'N' && depth % 2 == 0) {
            return true;
        }
        else if((trie[trie[v].next_node[i]].owner.size() == 1 && trie[trie[v].next_node[i]].owner[0] == 'E' && depth % 2 == 1))
        {    return false; 
        }
        else 
        {
            if(trie[trie[v].next_node[i]].owner.size() == 2) {
                bool temp =  dfs_nina(trie[v].next_node[i], depth + 1);
                if(temp)
                    valid = true;
                nina_has = emilija_has = true;
            }
        }
    }
    if(!children && depth % 2 == 1)
        valid = true;
    else 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();
    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 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Incorrect 1 ms 716 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Incorrect 1 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 19760 KB Output is correct
2 Incorrect 35 ms 19764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 19756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 19772 KB Output isn't correct
2 Halted 0 ms 0 KB -