# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
880738 | Ahmed_Solyman | Vlak (COCI20_vlak) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
struct node{
node *a[26];
int stop[3];
};
node *New(){
node *ret=new node;
for(int i=0;i<26;i++){
ret->a[i]=NULL;
}
ret->stop[0]=1;
return ret;
}
void insert(node *root,string s,int typ){
node *temp=root;
for(int i=0;i<(int)s.size();i++){
if(temp->a[s[i]-'a']==NULL){
temp->a[s[i]-'a']=New();
}
temp=temp->a[s[i]-'a'];
}
temp->stop[typ]=1;
}
void build(node *node){
for(int i=0;i<26;i++){
if(node->a[i]==NULL){
continue;
}
build(node->a[i]);
for(int j=1;j<=2;j++){
node->stop[j] |= node->a[i]->stop[j];
}
}
}
int dp[200005];
int solve(node *node,int i){
int &ret=dp[i];
if(~ret)return ret;
if(i%2==0){
ret=0;
for(int j=0;j<26;j++){
if(node->a[j]==NULL){
continue;
}
if(node->a[j]->is[1]){
ret|=solve(node->a[j],i+1);
}
}
return ret;
}
else{
ret=0;
for(int j=0;j<26;j++){
if(node->a[j]==NULL){
continue;
}
if(node->a[j]->is[2]){
ret|=!solve(node->a[j],i+1);
}
}
ret ^= 1;
return ret;
}
}
int main()
{
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
fast
node *root=New();
int n,m;
cin>>n;
for(int i=0;i<n;i++){
string s;cin>>s;
insert(root,s,1);
}
cin>>m;
for(int i=0;i<m;i++){
string s;cin>>s;
insert(root,s,2);
}
build(root);
fil(dp,-1);
cout<<(solve(root,0)?"Nina":"Emilija")<<endl;
return 0;
}