Submission #688333

# Submission time Handle Problem Language Result Execution time Memory
688333 2023-01-27T10:32:03 Z danikoynov Vlak (COCI20_vlak) C++14
70 / 70
25 ms 23208 KB
#include<bits/stdc++.h>
#define endl "\n"

using namespace std;

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

const int alphabet = 26;

const int maxn = 2e5 + 10;
struct trie
{
    int nxt[alphabet], state[2];
    bool leaf, is_word[2];

    trie()
    {
        memset(nxt, -1, sizeof(nxt));
        leaf = true;
        is_word[0] = is_word[1] = false;
        state[0] = state[1] = 0;
    }
}tree[maxn];

int last_used;
void add(int root, string &word, int pos, int player)
{
    if (pos == word.size())
    {
        tree[root].is_word[player] = 1;
        return;
    }

    int &neib = tree[root].nxt[word[pos] - 'a'];
    if (neib == -1)
        neib = ++ last_used;
    tree[root].leaf = false;

    add(neib, word, pos + 1, player);
    tree[root].is_word[0] |= tree[neib].is_word[0];
    tree[root].is_word[1] |= tree[neib].is_word[1];
}

void dfs(int root)
{
    if (tree[root].leaf)
    {
        tree[root].state[0] = tree[root].state[1] = 0;
        return;
    }

    if (tree[root].is_word[0] == false)
    {
        ///cout << "GOOD " << root << endl;
        tree[root].state[0] = 0;
        tree[root].state[1] = 1;
        return;
    }

    if (tree[root].is_word[1] == false)
    {
        ///cout << "BAD " << root << endl;
        tree[root].state[0] = 1;
        tree[root].state[1] = 0;
        return;
    }

    int neib;
    for (int i = 0; i < alphabet; i ++)
    {
        neib = tree[root].nxt[i];

        if (neib == -1)
            continue;

        dfs(neib);
        /**cout << root << " : " << neib << endl;
        cout << tree[neib].is_word[1] << endl;
        cout << tree[neib].state[0] << endl;*/
        if (!tree[neib].state[0] && tree[neib].is_word[1])
            tree[root].state[1] = true;
        if (!tree[neib].state[1] && tree[neib].is_word[0])
            tree[root].state[0] = true;
    }
    ///cout << "back " << root << " " << tree[root].state[0] << " : " << tree[root].state[1] << endl;
}
int n, m;

void solve()
{
    string word;
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        cin >> word;
        add(0, word, 0, 0);
    }
    cin >> m;
    for (int i = 1; i <= m; i ++)
    {
        cin >> word;
        add(0, word, 0, 1);
    }

    dfs(0);

    if (tree[0].state[0])
        cout << "Nina" << endl;
    else
        cout << "Emilija" << endl;

}
int main()
{
    solve();
	return 0;
}

Compilation message

Main.cpp: In function 'void add(int, std::string&, int, int)':
Main.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if (pos == word.size())
      |         ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23004 KB Output is correct
2 Correct 11 ms 22972 KB Output is correct
3 Correct 10 ms 22932 KB Output is correct
4 Correct 10 ms 23008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22996 KB Output is correct
2 Correct 10 ms 22988 KB Output is correct
3 Correct 11 ms 22936 KB Output is correct
4 Correct 10 ms 22996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22972 KB Output is correct
2 Correct 10 ms 22996 KB Output is correct
3 Correct 10 ms 22904 KB Output is correct
4 Correct 11 ms 23076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 22996 KB Output is correct
2 Correct 10 ms 23012 KB Output is correct
3 Correct 9 ms 23000 KB Output is correct
4 Correct 10 ms 23004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23204 KB Output is correct
2 Correct 24 ms 23092 KB Output is correct
3 Correct 25 ms 23100 KB Output is correct
4 Correct 21 ms 23124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23144 KB Output is correct
2 Correct 17 ms 23124 KB Output is correct
3 Correct 18 ms 23184 KB Output is correct
4 Correct 18 ms 23144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23208 KB Output is correct
2 Correct 18 ms 23116 KB Output is correct
3 Correct 19 ms 23204 KB Output is correct
4 Correct 19 ms 23124 KB Output is correct