답안 #544410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544410 2022-04-01T21:24:23 Z DragosC1 Vlak (COCI20_vlak) C++17
70 / 70
21 ms 13184 KB
#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

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())
      |         ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 424 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 12120 KB Output is correct
2 Correct 20 ms 11380 KB Output is correct
3 Correct 19 ms 10908 KB Output is correct
4 Correct 20 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 12332 KB Output is correct
2 Correct 19 ms 13184 KB Output is correct
3 Correct 17 ms 12124 KB Output is correct
4 Correct 17 ms 12204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 11688 KB Output is correct
2 Correct 20 ms 11536 KB Output is correct
3 Correct 21 ms 11876 KB Output is correct
4 Correct 20 ms 12700 KB Output is correct