Submission #1096668

# Submission time Handle Problem Language Result Execution time Memory
1096668 2024-10-05T00:39:45 Z lenron Vlak (COCI20_vlak) C++17
40 / 70
36 ms 52316 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<vector<ll>> trie(200040,vector<ll>(26,0));
vector<int> color(200040,0);
vector<int> res(200040,0);
vector<ll> depth(200040,0);
ll node_c=0;
void insert(string s,int x){
       ll node =0;
       ll d=depth[node];
       for(auto c:s){
         if(trie[node][c-'a']==0){node_c++;trie[node][c-'a']=node_c;}
         node=trie[node][c-'a'];
         depth[node]=d+1;
         d++;
         color[node]+=x;
       }

}

void dfs(ll u){
    //cout<<"*"<<u<<endl;
    if(color[u]==1){
        res[u]=1;return;
    }
    if(color[u]==-1){
        res[u]=2;return;
    }
    bool flag=false;
    set<int> s;
    for(int i=0;i<26;i++){
        if(trie[u][i]==0){continue;}
        flag=true;
        dfs(trie[u][i]);
       s.insert(res[trie[u][i]]);
       res[u]=res[trie[u][i]];
    }

    if(!flag){
        if(depth[u]%2){res[u]=1;return;}
        else{res[u]=2;return;}
    }

   if(depth[u]%2 && s.find(2)!=s.end()){res[u]=2;return;}
   if(depth[u]%2==0 && s.find(1)!=s.end()){res[u]=1;return;}



}

void solve(){
    ll a;cin>>a;
    for(ll i=0;i<a;i++){
        string s;cin>>s;
        insert(s,1);
    }
    ll b;cin>>b;
    for(ll i=0;i<b;i++){
        string s;cin>>s;
        insert(s,-1);
    }
    dfs(0);
    if(res[0]==1){cout<<"Nina"<<endl;}
    else{cout<<"Emilija"<<endl;}
}

int main(){
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 52048 KB Output is correct
2 Correct 22 ms 52048 KB Output is correct
3 Correct 21 ms 52132 KB Output is correct
4 Correct 22 ms 52104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 52060 KB Output is correct
2 Correct 22 ms 52060 KB Output is correct
3 Correct 22 ms 51972 KB Output is correct
4 Incorrect 22 ms 52060 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 52056 KB Output is correct
2 Correct 25 ms 52056 KB Output is correct
3 Incorrect 25 ms 52060 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 52056 KB Output is correct
2 Correct 24 ms 52048 KB Output is correct
3 Correct 25 ms 52060 KB Output is correct
4 Correct 24 ms 52016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 52312 KB Output is correct
2 Correct 34 ms 52316 KB Output is correct
3 Correct 33 ms 52260 KB Output is correct
4 Correct 30 ms 52316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 52316 KB Output is correct
2 Correct 32 ms 52308 KB Output is correct
3 Correct 31 ms 52136 KB Output is correct
4 Correct 34 ms 52304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 52312 KB Output is correct
2 Correct 31 ms 52308 KB Output is correct
3 Incorrect 31 ms 52308 KB Output isn't correct
4 Halted 0 ms 0 KB -