답안 #1091174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091174 2024-09-20T02:51:12 Z Rafat Vlak (COCI20_vlak) C++17
0 / 70
17 ms 30812 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>

using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and 
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod =  1e9+7, MOD = 998244353;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(int i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(int i = s; i >= e; i--)
#define coutAll(A) for(auto asdafas : A) cout <<  asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout <<  asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >>  asdafas;
#define finAll(A) for(auto &asdafas : A) fin >>  asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll> 
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
// #define MAXN 1000001

const int MAXN = 1e6+1;
int Trie[MAXN][26];
int node_count;
bool stop[MAXN], win[MAXN];
vv32 adj(MAXN);
// 0->root
void insert(string s){
    int node = 0;
    int n = s.size();
    for(auto x : s){
        if(Trie[node][x-'a'] == 0){Trie[node][x-'a'] = ++node_count;}
        adj[node].pb(Trie[node][x-'a']);
        node = Trie[node][x-'a'];
    }
    stop[node] = true;
}
void insert2(string s){
    int node = 0;
    int cnt = 0;
    int n = s.size();
    for(auto x : s){
        if(Trie[node][x-'a'] == 0){
            win[node] = cnt % 2;
            return; 
        }
        ++cnt;
        node = Trie[node][x-'a'];
    }
    --cnt;
    win[node] = cnt % 2;
}
bool dfs(int u){
    if(win[u]) return false;
    if(adj[u].size() == 0) return !win[u];
    for(auto v : adj[u]){
        if(dfs(v)) return true;
    }
    return false;
}

void solve(int it)
{
    int n, m;
    cin >> n;
    FOR(0, n -1, i){
        string s;
        cin >> s;
        insert(s);
    }
    
    cin >> m;
    FOR(0, m -1, i){
        string s;
        cin >> s;
        insert2(s);
    }
    // FOR(0, node_count, i) {coutAll(adj[i]);}
    // FOR(0, node_count, i) cout << win[i] << " "; cout << "\n";

    cout << (dfs(0) ? "Nina" : "Emilija");
    
}


int main()
{
    fast_cin();    
    ll t = 1;
    // cin >> t;
    for(int it=1; it<=t; it++)
    {
        //cout << "Case " << it << ": ";
        solve(it);
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void insert(std::string)':
Main.cpp:88:9: warning: unused variable 'n' [-Wunused-variable]
   88 |     int n = s.size();
      |         ^
Main.cpp: In function 'void insert2(std::string)':
Main.cpp:99:9: warning: unused variable 'n' [-Wunused-variable]
   99 |     int n = s.size();
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 23896 KB Output is correct
2 Correct 11 ms 23900 KB Output is correct
3 Correct 9 ms 23900 KB Output is correct
4 Incorrect 9 ms 23900 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 23900 KB Output is correct
2 Correct 12 ms 23900 KB Output is correct
3 Incorrect 9 ms 23900 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23964 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23900 KB Output is correct
4 Incorrect 10 ms 23900 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 30552 KB Output is correct
2 Incorrect 16 ms 30044 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 30812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 30296 KB Output isn't correct
2 Halted 0 ms 0 KB -