Submission #635247

# Submission time Handle Problem Language Result Execution time Memory
635247 2022-08-25T17:52:29 Z ojoConmigo Vlak (COCI20_vlak) C++17
0 / 70
21 ms 19580 KB
#include <bits/stdc++.h>
using namespace std;

struct Trie{
    struct Trie *child[26];
    bool b[2]; //nina-0 emilija-1
};

struct Trie *createNode(){
    struct Trie *nodo = new Trie;
    for(int i=0; i<26; i++){
        nodo->child[i] = NULL;
    }
    nodo->b[0] = false; nodo->b[1] = false;
    return nodo;
}

void insert(struct Trie *root, string key, int turno){
    struct Trie *curr = root;
    for(int i=0; i<(int)key.size(); i++){
        int index = key[i] - 'a';
        if(!curr->child[index]){
            curr->child[index] = createNode();
        }
        curr = curr->child[index];
        curr->b[turno] = true;
    }
}

bool gana(struct Trie *root,int turno){
    struct Trie *curr = root;
    bool noContinua = true;
    for(int i=0; i<26; i++){
        if(curr->child[i]){
            struct Trie *sig = curr->child[i];
            if(sig->b[1-turno]){
                noContinua = false;
                if(!gana(sig,1-turno)){
                    return true;
                }
            }
        }
    }
    return noContinua;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    struct Trie *root = createNode();
    for(int t=0; t<2; t++){
        cin >> n;
            for(int i=0; i<n; i++){
            string s;
            cin >> s;
            insert(root,s,t);
        }
    }

    bool win = false;
    for(int i=0; i<26; i++){
        if(root->child[i]){
            struct Trie *sig = root->child[i];
            if(sig->b[0]){
                win = max(win,gana(sig,0));
            }
        }
    }

    if(win) cout << "Nina\n";
    else cout << "Emilija\n";
}
# 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 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 480 KB Output is correct
4 Incorrect 1 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Incorrect 1 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 20 ms 19156 KB Output is correct
2 Incorrect 15 ms 17832 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 19580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 18516 KB Output is correct
2 Incorrect 17 ms 17944 KB Output isn't correct
3 Halted 0 ms 0 KB -