Submission #688585

#TimeUsernameProblemLanguageResultExecution timeMemory
688585rieyuwVlak (COCI20_vlak)C++17
70 / 70
16 ms14244 KiB
#include <bits/stdc++.h>

using namespace std;

const int mxN = 1e5+10;
vector<vector<int>> nxt(mxN, vector<int>(26));
vector<int> color(mxN);

bool dfs(int node, int depth)
{
    int par = (depth & 1);
    bool res = !par;
    for (int i = 0; i < 26 && res != par; ++i)
    {
        int neig = nxt[node][i];
        if (neig != 0 && ((color[neig] >> par) & 1))
        {
            bool neigRes = dfs(neig, depth+1);
            if (par)
                res |= neigRes;
            else
                res &= neigRes;
        }
    }
    return res;
}

int main() 
{
    ios::sync_with_stdio(0), cin.tie(0);
    int n; cin >> n;
    string s;
    int MAXID = 0;
    color[0] = 3;
    while(n--)
    {
        cin >> s;
        int node = 0;
        for (char c : s)
        {
            if (nxt[node][c-'a'] == 0)
                nxt[node][c-'a'] = ++MAXID;
            node = nxt[node][c-'a'];
            color[node] |= 2;
        }        
    }
 
    int m; cin >> m;
    while(m--)
    {
        cin >> s;
        int node = 0;
        for (char c : s)
        {
            if (nxt[node][c-'a'] == 0)
                nxt[node][c-'a'] = ++MAXID;
            node = nxt[node][c-'a'];
            color[node] |= 1;
        }        
    }
    cout << (dfs(0, 1) ? "Nina" : "Emilija") << "\n";
}
#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...