Submission #900649

#TimeUsernameProblemLanguageResultExecution timeMemory
900649vaneaVlak (COCI20_vlak)C++14
70 / 70
11 ms10336 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mxN = 2e5+10;

int trie[mxN][26];
int node_cnt = 0;
bool stop[mxN][2];
int dp[mxN];
string alpha = "abcdefghijklmnopqrstuvwxyz";

void insert(string word, int flag) {
    int node = 0;
    for(auto c : word) {
        if(trie[node][c-'a'] == 0) trie[node][c-'a'] = ++node_cnt;
        node = trie[node][c-'a'];
    }
    stop[node][flag] = true;
}

void dfs(int node, int lvl = 0) {
    if(lvl & 1) {
        dp[node] = 1;
    }
    else {
        dp[node] = 2;
    }
    bool has = false;
    for(char c : alpha) {
        int k = trie[node][c-'a'];
        if(k) {
            has = true;
            dfs(k, lvl+1);
            if(lvl & 1) dp[node] = max(dp[node], dp[k]);
            else dp[node] = min(dp[node], dp[k]);
        }
    }
    if(!has) {
        if(stop[node][0] && stop[node][1]) {
            if(lvl & 1) dp[node] = 1;
            else dp[node] = 2;
        }
        else if(stop[node][0]) {
            dp[node] = 1;
        }
        else dp[node] = 2;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string word;
        cin >> word;
        insert(word, 0);
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++) {
        string word;
        cin >> word;
        insert(word, 1);
    }
    dfs(0, 0);
    cout << (dp[0] == 1 ? "Nina" : "Emilija");
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...