# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1108924 | themaver1cks | Vlak (COCI20_vlak) | C++14 | 24 ms | 24648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
。∠(*・ω・)っ ⌒ 由 ~ (( ,,・з・,, ))
_Π_____。
/______/~\
| 田田|門|
> love miku so muchhhh <3
**/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define el "\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
// var dec
int n, m;
// ds dec
//
struct Trie
{
struct Node
{
Node* child[26];
vector <int> color;
Node()
{
for (int i=0; i<26; ++i) child[i] = NULL;
color.resize(2, 0);
}
};
Node* root;
int cur;
Trie(): cur(0)
{
root = new Node();
}
//
void add_string(string s, bool is_blue)
{
Node* p = root;
for (auto x: s)
{
int c = x-'a';
if (p->child[c] == NULL) p->child[c] = new Node();
p = p->child[c];
p->color[is_blue]++;
}
}
//
bool calc(Node* p, bool is_blue)
{
bool no_child = 1, win = 0;
for (int c=0; c<26; ++c)
{
if (p->child[c] != NULL) no_child = 0;
if (p->child[c] != NULL && p->child[c]->color[is_blue] != 0)
{
// cout << c << el;
if (is_blue) win |= calc(p->child[c], is_blue^1);
else win |= !(calc(p->child[c], is_blue^1));
// win |= !(calc(p->child[c], is_blue^1));
}
}
// cout << no_child << " " << win << " " << is_blue << el;
if (no_child && p->color[is_blue]) return !is_blue;
if (win) return is_blue;
else return !is_blue;
}
//
bool call_func()
{
Node* p = root;
bool win = 0;
for (int c=0; c<26; ++c)
{
if (p->child[c] != NULL && p->child[c]->color[1] > 0)
{
bool temp = calc(p->child[c], 0);
// cout << c << " " << temp << el << el;
win |= temp;
}
}
return win;
}
} trie;
//
void solve()
{
cin >> n;
for (int i=1; i<=n; ++i)
{
string s; cin >> s;
trie.add_string(s, 1);
}
cin >> m;
for (int i=1; i<=m; ++i)
{
string s; cin >> s;
trie.add_string(s, 0);
}
cout << (trie.call_func() ? "Nina" : "Emilija") << el;
}
//
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("lmao.inp", "r"))
{
freopen("lmao.inp", "r", stdin);
freopen("lmao.out", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |