Submission #839488

# Submission time Handle Problem Language Result Execution time Memory
839488 2023-08-30T07:05:35 Z Lilinta Vlak (COCI20_vlak) C++14
30 / 70
13 ms 20436 KB
// COCI 2020/2021 Contest#3 Problem 2 - Vlak
#include <bits/stdc++.h>
using namespace std;

struct Trie {
    struct Node {
        Node* child[26];
        int allow;

        Node() {
            for (int i = 0; i < 26; ++i) {
                child[i] = nullptr;
            }
            allow = 0;
        }
    };

    Node* root;

    Trie() {
        root = new Node();
    }

    void addString(string &s, int player) {
        Node* p = root;
        for (char f : s) {
            int c = f - 'a';
            if (p -> child[c] == nullptr) {
                p -> child[c] = new Node();
            }
            p = p -> child[c];
            p -> allow += player;
        }
    }
};

int n, m;
Trie T;

bool isWin(Trie::Node* p, bool player) {
    if (player) { // Nina
        for (char c = 0; c <= 25; ++c) {
            if (p -> child[c] != nullptr && p -> child[c] -> allow != 2 && !isWin(p -> child[c], false)) {
                return true;
            }
        }
        return false;
    } else {
        for (char c = 0; c <= 25; ++c) {
            if (p -> child[c] != nullptr && p -> child[c] -> allow != 1 && !isWin(p -> child[c], true)) {
                return true;
            }
        }
        return false;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        T.addString(s, 1);
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        T.addString(s, 2);
    }
    if (isWin(T.root, true)) {
        cout << "Nina";
    } else {
        cout << "Emilija";
    }
    return 0;
}

Compilation message

Main.cpp: In function 'bool isWin(Trie::Node*, bool)':
Main.cpp:43:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   43 |             if (p -> child[c] != nullptr && p -> child[c] -> allow != 2 && !isWin(p -> child[c], false)) {
      |                            ^
Main.cpp:43:56: warning: array subscript has type 'char' [-Wchar-subscripts]
   43 |             if (p -> child[c] != nullptr && p -> child[c] -> allow != 2 && !isWin(p -> child[c], false)) {
      |                                                        ^
Main.cpp:43:94: warning: array subscript has type 'char' [-Wchar-subscripts]
   43 |             if (p -> child[c] != nullptr && p -> child[c] -> allow != 2 && !isWin(p -> child[c], false)) {
      |                                                                                              ^
Main.cpp:50:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   50 |             if (p -> child[c] != nullptr && p -> child[c] -> allow != 1 && !isWin(p -> child[c], true)) {
      |                            ^
Main.cpp:50:56: warning: array subscript has type 'char' [-Wchar-subscripts]
   50 |             if (p -> child[c] != nullptr && p -> child[c] -> allow != 1 && !isWin(p -> child[c], true)) {
      |                                                        ^
Main.cpp:50:94: warning: array subscript has type 'char' [-Wchar-subscripts]
   50 |             if (p -> child[c] != nullptr && p -> child[c] -> allow != 1 && !isWin(p -> child[c], true)) {
      |                                                                                              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 644 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19156 KB Output is correct
2 Correct 12 ms 17876 KB Output is correct
3 Correct 11 ms 16852 KB Output is correct
4 Correct 12 ms 18644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19540 KB Output is correct
2 Correct 11 ms 20436 KB Output is correct
3 Correct 11 ms 18772 KB Output is correct
4 Incorrect 11 ms 19028 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 18516 KB Output is correct
2 Correct 13 ms 18008 KB Output is correct
3 Incorrect 12 ms 18516 KB Output isn't correct
4 Halted 0 ms 0 KB -