Submission #691813

# Submission time Handle Problem Language Result Execution time Memory
691813 2023-01-31T15:38:59 Z sunshine19 Vlak (COCI20_vlak) C++14
70 / 70
17 ms 13128 KB
#include<iostream>
#include<vector>
#include<map>

using namespace std;

struct Node {
    int num = 0;
    map<char, Node*> next;

};

void add(Node* root, string s) {
    for(char c : s) {
        if(root->next.find(c) == root->next.end()) 
            root->next[c] = new Node();
        root = root->next[c];
    }
}

bool traverse(Node* ni, Node* em, bool move, int d) {
    Node* ts[] = {em, ni};
    if(ts[move]->next.empty())
        return !move;

    for(auto p : ts[move]->next) {
        if(ts[!move]->next.find(p.first) == ts[!move]->next.end())
            return move;
        if(traverse(ni->next[p.first], em->next[p.first], !move, d+1) == move)
            return move; 
    }

    return !move; 
    
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    Node* nina = new Node();
    Node* ema = new Node();

    int n, m;
    string s;

    cin>>n;
    while(n--) {
        cin>>s;
        add(nina, s);
    }

    cin>>m;
    while(m--) {
        cin>>s;
        add(ema, s);
    }

    cout<<(traverse(nina, ema, true, 0) ? "Nina" : "Emilija")<<endl;

return 0;
}
# 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 444 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12244 KB Output is correct
2 Correct 13 ms 11540 KB Output is correct
3 Correct 14 ms 10964 KB Output is correct
4 Correct 17 ms 11960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12492 KB Output is correct
2 Correct 15 ms 13128 KB Output is correct
3 Correct 12 ms 12024 KB Output is correct
4 Correct 12 ms 12220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 11832 KB Output is correct
2 Correct 14 ms 11552 KB Output is correct
3 Correct 17 ms 11804 KB Output is correct
4 Correct 14 ms 12600 KB Output is correct