Submission #544410

#TimeUsernameProblemLanguageResultExecution timeMemory
544410DragosC1Vlak (COCI20_vlak)C++17
70 / 70
21 ms13184 KiB
#include <iostream>
#include <map>
using namespace std;

struct trie {
    map<int, trie*> lit;
    trie() {
        lit.clear();
    }
};

trie *root1, *root2;
string s;

void add(int ind, trie *node) {
    if (ind == s.size())
        return;
    int l = s[ind] - 'a';
    if (node->lit[l] == 0)
        node->lit[l] = new trie();
    add(ind + 1, node->lit[l]);
}

bool sch(trie *node1, trie *node2, int ind) {
    if (ind % 2 == 0) {
        bool rez = 0;
        for (auto it = node1->lit.begin(); it != node1->lit.end(); it++)
            if (node2->lit[it->first] == 0) {
                rez = 1;
                break;
            }
            else {
                bool x = sch(node1->lit[it->first], node2->lit[it->first], ind + 1);
                rez |= (1 - x);
            }
        return rez;
    }
    else {
        bool rez = 0;
        for (auto it = node2->lit.begin(); it != node2->lit.end(); it++)
            if (node1->lit[it->first] == 0) {
                rez = 1;
                break;
            }
            else {
                bool x = sch(node1->lit[it->first], node2->lit[it->first], ind + 1);
                rez |= (1 - x);
            }
        return rez;
    }
}

int main() {
    int i, n, m;
    root1 = new trie();
    root2 = new trie();
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> s;
        add(0, root1);
    }
    cin >> m;
    for (i = 1; i <= m; i++) {
        cin >> s;
        add(0, root2);
    }
    if (sch(root1, root2, 0))
        cout << "Nina";
    else cout << "Emilija";
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void add(int, trie*)':
Main.cpp:16:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     if (ind == s.size())
      |         ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...