답안 #798971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798971 2023-07-31T08:14:39 Z yeediot Vlak (COCI20_vlak) C++14
0 / 70
19 ms 20264 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
const int mxn=2e5+5;
int trie[2][mxn][26];
int nxt=1;
vector<string>s,ss;
int n,m;
void add(string s,int type){
    int i=0,v=0;
    while(i<sz(s)){
        //cout<<v<<' ';
        if(trie[type][v][s[i]-'a']){
            v=trie[type][v][s[i++]-'a'];
        }
        else{
            v=trie[type][v][s[i++]-'a']=nxt++;
        }
    }//cout<<v<<'\n';
}
bool calc(int now,int turn,int v1,int v2){
    //cout<<v1<<' '<<v2<<'\n';
    bool ok=1;
    bool valid=0;
    if(now!=-1){
        if(turn==0){
            if(trie[turn][v1][now]){
                v1=trie[turn][v1][now];
            }
            else{
                return 1-turn;
            }
        }
        else{
            if(trie[turn][v2][now]){
                v2=trie[turn][v2][now];
            }
            else{
                return 1-turn;
            }
        }
    }
    for(int i=0;i<26;i++){
        if(turn==0){
            if(trie[turn][v1][i]){
                valid=1;
                //cout<<(char)(i+'a');
                if(calc(i,1-turn,trie[turn][v1][i],v2)==0){
                    ok=0;
                }
            }
        }
        else{
            if(trie[turn][v2][i]){
                valid=1;
                if(calc(i,1-turn,v1,trie[turn][v2][i])==0){
                    ok=0;
                }
            }
        }
    }//cout<<valid<<' ';
    if(valid){
        return ok;
    }
    return 1-turn;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        string temp;
        cin>>temp;
        s.pb(temp);
        add(temp,0);
    }
    cin>>m;
    nxt=1;
    for(int i=0;i<m;i++){
        string temp;
        cin>>temp;
        ss.pb(temp);
        add(temp,1);
    }
    cout<<(calc(-1,0,0,0)==0?"Nina":"Emilija")<<'\n';
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Incorrect 1 ms 596 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Incorrect 1 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Incorrect 1 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 20176 KB Output is correct
2 Incorrect 15 ms 19008 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 20264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 19284 KB Output isn't correct
2 Halted 0 ms 0 KB -