Submission #588535

# Submission time Handle Problem Language Result Execution time Memory
588535 2022-07-03T13:26:02 Z aris12345678 Vlak (COCI20_vlak) C++14
70 / 70
21 ms 20424 KB
#include <bits/stdc++.h>
using namespace std;

struct node {
    bool word, nina, emilija;
    // int depth;
    node *child[26];
    node() {
        word = nina = emilija = false;
        // depth = 0;
        for(int i = 0; i < 26; i++)
            child[i] = NULL;
    }
};

typedef node *pnode;
pnode root = new node();

void add(string s, bool nin, bool em) {
    int n = int(s.size());
    pnode cur = root;
    for(int i = 0; i < n; i++) {
        if(cur->child[s[i]-'a'] == NULL)
            cur->child[s[i]-'a'] = new node();
        // cur->child[s[i]-'a']->depth = 1+cur->depth;
        cur = cur->child[s[i]-'a'];
        if(!cur->nina)
            cur->nina = nin;
        if(!cur->emilija)
            cur->emilija = em;
    }
    cur->word = true;
}

bool dfs(pnode cur, bool play = true) {
    if(play) {
        for(int i = 0; i < 26; i++) {
            if(cur->child[i] == NULL) continue;
            if(cur->child[i]->nina) {
                if(!cur->child[i]->emilija)
                    return true;
                if(!dfs(cur->child[i], false))
                    return true;
            }
        }
    } else {
        for(int i = 0; i < 26; i++) {
            if(cur->child[i] == NULL) continue;
            if(cur->child[i]->emilija) {
                if(!cur->child[i]->nina)
                    return true;
                if(!dfs(cur->child[i], true))
                    return true;
            }
        }
    }
    return false;
}

int main() {
    int n, m;
    scanf("%d\n", &n);
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        add(s, true, false);
    }
    scanf("%d\n", &m);
    for(int i = 0; i < m; i++) {
        string s;
        cin >> s;
        add(s, false, true);
    }
    if(dfs(root))
        printf("Nina\n");
    else
        printf("Emilija\n");
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d\n", &n);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     scanf("%d\n", &m);
      |     ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 548 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 Correct 1 ms 560 KB Output is correct
2 Correct 1 ms 576 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 Correct 1 ms 468 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 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 432 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19116 KB Output is correct
2 Correct 19 ms 17832 KB Output is correct
3 Correct 19 ms 16912 KB Output is correct
4 Correct 20 ms 18644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 19480 KB Output is correct
2 Correct 20 ms 20424 KB Output is correct
3 Correct 19 ms 18732 KB Output is correct
4 Correct 17 ms 19120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 18420 KB Output is correct
2 Correct 19 ms 17892 KB Output is correct
3 Correct 21 ms 18484 KB Output is correct
4 Correct 19 ms 19640 KB Output is correct