답안 #965333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965333 2024-04-18T10:45:11 Z noyancanturk Vlak (COCI20_vlak) C++17
70 / 70
17 ms 19804 KB
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back
    
const int lim=1e6+100;
const int mod=1e9+7;
 
using pii=pair<int,int>;

int sum(int i,int j){
    if(i+j<mod)return i+j;
    return i+j-mod;
}

struct trie{
    struct node{
        int c[26];
        bool dude[2];
    };
    
    node nds[lim];
    int nextunused=2;

    void insert(const string&s,bool curdude){
        int cur=1;
        int i=0;
        while(i<s.size()){
            if(nds[cur].c[s[i]-'a']==0){
                nds[cur].c[s[i]-'a']=nextunused++;
            }
            cur=nds[cur].c[s[i++]-'a'];
        }
        nds[cur].dude[curdude]=1;
    }

    struct iterator{
        trie*par;
        int cur;
        iterator(trie*par,int b):par(par),cur(b){}
        node* operator()(){
            return par->nds+cur;
        }
        void operator+=(char cc){
            cur=par->nds[cur].c[cc-'a'];
        }
        bool operator==(const iterator&it){
            return par==it.par&&cur==it.cur;
        }
    };

    const iterator begin() {
        return iterator(this,1);
    };

    const iterator end(){
        return iterator(this,0);
    }

    bool retwin(node*p,bool turn){
        bool have=0;
        int children=0;
        for(int i=0;i<26;i++){
            if(p->c[i]){
                children++;
                if(retwin(nds+p->c[i],!turn)==turn){
                    have=1;
                }
                p->dude[0]|=nds[p->c[i]].dude[0];
                p->dude[1]|=nds[p->c[i]].dude[1];
            }
        }
        if(p->dude[turn]&&have)return turn;
        return !turn;
    }

    bool retwin(){
        return retwin(nds+1,0);
    }

}tr;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin); freopen(".out","w",stdout);
#endif
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        tr.insert(s,0);
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        string s;
        cin>>s;
        tr.insert(s,1);
    }
    bool res=tr.retwin();
    if(res)cout<<"Emilija\n";
    else cout<<"Nina\n";
}

Compilation message

Main.cpp: In member function 'void trie::insert(const string&, bool)':
Main.cpp:29:16: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         while(i<s.size()){
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 18776 KB Output is correct
2 Correct 16 ms 17244 KB Output is correct
3 Correct 14 ms 16476 KB Output is correct
4 Correct 15 ms 19292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19292 KB Output is correct
2 Correct 15 ms 19804 KB Output is correct
3 Correct 14 ms 18268 KB Output is correct
4 Correct 16 ms 18524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 17916 KB Output is correct
2 Correct 14 ms 17496 KB Output is correct
3 Correct 15 ms 19292 KB Output is correct
4 Correct 15 ms 19036 KB Output is correct