Submission #847764

# Submission time Handle Problem Language Result Execution time Memory
847764 2023-09-10T10:54:45 Z borisAngelov Vlak (COCI20_vlak) C++17
70 / 70
17 ms 20572 KB
#include <bits/stdc++.h>

using namespace std;

const int alphabet_size = 26;

int n, m;

struct trie_node
{
    trie_node *children[alphabet_size];
    bool contains[2];

    trie_node()
    {
        for (int i = 0; i < alphabet_size; ++i)
        {
            children[i] = NULL;
        }

        contains[0] = false;
        contains[1] = false;
    }
};

trie_node *root = new trie_node;

void insert_word(trie_node *&curr, const string& s, int pos, bool which_player)
{
    if (curr == NULL)
    {
        curr = new trie_node;
    }

    if (pos == s.size())
    {
        curr->contains[which_player] = true;
        curr->contains[1 - which_player] = false;
        return;
    }

    int child = (s[pos] - 'a');

    insert_word(curr->children[child], s, pos + 1, which_player);

    curr->contains[which_player] |= curr->children[child]->contains[which_player];
    curr->contains[1 - which_player] |= curr->children[child]->contains[1 - which_player];
}

bool dfs(trie_node *&curr, bool which_player)
{
    if (curr->contains[which_player] == false)
    {
        return false;
    }

    for (int child = 0; child < alphabet_size; ++child)
    {
        if (curr->children[child] != NULL && dfs(curr->children[child], 1 - which_player) == false)
        {
            return true;
        }
    }

    return false;
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        string s;
        cin >> s;
        insert_word(root, s, 0, 0);
    }

    cin >> m;

    for (int i = 1; i <= m; ++i)
    {
        string s;
        cin >> s;
        insert_word(root, s, 0, 1);
    }

    if (dfs(root, 0) == true)
    {
        cout << "Nina" << endl;
    }
    else
    {
        cout << "Emilija" << endl;
    }

    return 0;
}

Compilation message

Main.cpp: In function 'void insert_word(trie_node*&, const string&, int, bool)':
Main.cpp:35:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (pos == s.size())
      |         ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 456 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19292 KB Output is correct
2 Correct 12 ms 18012 KB Output is correct
3 Correct 11 ms 16880 KB Output is correct
4 Correct 13 ms 18728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19548 KB Output is correct
2 Correct 14 ms 20572 KB Output is correct
3 Correct 12 ms 18780 KB Output is correct
4 Correct 13 ms 19544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 18524 KB Output is correct
2 Correct 17 ms 17988 KB Output is correct
3 Correct 12 ms 18520 KB Output is correct
4 Correct 13 ms 19804 KB Output is correct