Submission #488335

# Submission time Handle Problem Language Result Execution time Memory
488335 2021-11-18T15:31:44 Z Malheiros Vlak (COCI20_vlak) C++17
70 / 70
26 ms 10928 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long
//#define int ll
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(),cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define FOR(i, j) for(int i=0;i<j;i++)
#define RFOR(i, j) for (int i=j;i>=0;i--)
#define GO cin.tie(NULL);
#define FAST ios_base::sync_with_stdio(false);
#define prec(x) cout << fixed << setprecision(x)
#define sz(x) (int)x.size()

typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<pii> VPII;
typedef vector<VI> VVI;
typedef priority_queue<int> max_heap;
typedef priority_queue<pii> max_heapii;
typedef priority_queue<int,VI,greater<int>> min_heap;
typedef priority_queue<pii,VPII,greater<pii>> min_heapii;

const long double PI = 3.14159265359;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b){return uniform_int_distribution<ll>(a, b)(rng);}

#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cout << vars << " = ";
    string delim = "";
    (..., (cout << delim << values, delim = ", "));
    cout<<endl;
}

void print(vector<int>v){
	cout<<"[";
	FOR(i,v.size()){
		cout<<v[i];
		if(i+1!=v.size())cout<<", ";
	}
	cout<<"]"<<endl;
}

void print(pii p){
	cout<<"{"<<p.first<<", "<<p.second<<"}"<<endl;
}
 
//You will have to augment this in most of the problems
struct Node{
    map<char,pair<int,int>> nxt;
};

struct Trie{
    vector<Node> nodes;
    Trie(){
        nodes.push_back(Node());
    }

    void add(string &s,int i,int ind,int p){
        if (i==s.length()) return;
        if (nodes[ind].nxt.find(s[i])==nodes[ind].nxt.end()){
            nodes[ind].nxt[s[i]]={nodes.size(),0};
            nodes.push_back(Node());
        }
        nodes[ind].nxt[s[i]]={nodes[ind].nxt[s[i]].first,nodes[ind].nxt[s[i]].second | (1<<p)};
        add(s,i+1,nodes[ind].nxt[s[i]].first,p);
    }

    void add(string &s,int quem){
        s+='$';
        add(s,0,0,quem);
    }

    
};

Trie T;
bool pode(int u,int p){
    if (T.nodes[u].nxt.size()==0)return 1;
    bool ans=0;
    for(auto k:T.nodes[u].nxt){
        if ((k.second.second>>p) & 1){
            ans|= !pode(k.second.first,!p);
        }
    }
    return ans;

}

signed main(){
   int n;cin>>n;
    FOR(i,n){
        string s;cin>>s;
        T.add(s,0);
    }
    int k;cin>>k;
    FOR(i,k){
        string s;cin>>s;
        T.add(s,1);
    }

    if(pode(0,0)){
        cout<<"Nina\n";
    }
    else cout<<"Emilija\n";
   
}

Compilation message

Main.cpp: In function 'void print(std::vector<int>)':
Main.cpp:16:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 | #define FOR(i, j) for(int i=0;i<j;i++)
......
   47 |  FOR(i,v.size()){
      |      ~~~~~~~~~~                 
Main.cpp:47:2: note: in expansion of macro 'FOR'
   47 |  FOR(i,v.size()){
      |  ^~~
Main.cpp:49:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   if(i+1!=v.size())cout<<", ";
      |      ~~~^~~~~~~~~~
Main.cpp: In member function 'void Trie::add(std::string&, int, int, int)':
Main.cpp:70:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         if (i==s.length()) return;
      |             ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 480 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 10928 KB Output is correct
2 Correct 25 ms 10540 KB Output is correct
3 Correct 24 ms 10748 KB Output is correct
4 Correct 26 ms 10748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10748 KB Output is correct
2 Correct 22 ms 10792 KB Output is correct
3 Correct 20 ms 10744 KB Output is correct
4 Correct 20 ms 10680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 10748 KB Output is correct
2 Correct 23 ms 10664 KB Output is correct
3 Correct 23 ms 10740 KB Output is correct
4 Correct 24 ms 10764 KB Output is correct