# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
439452 | anmolagarwal | Vlak (COCI20_vlak) | C++17 | 28 ms | 21428 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.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors //GO FOR EVEN FOR 4 moves
#define fastinput \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
vector<string> s[2];
//2 tries
struct node
{
int arr[2][26];
int id;
};
vector<node *> v;
node *get_node()
{
node *a = new node;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 26; j++)
{
a->arr[i][j] = -1;
}
}
a->id = v.size();
return a;
}
void insert(string s, int person)
{
int i, j, k;
// cout << "inserting " << s << " for " << person << endl;
node *curr_node = v[0];
// cout << "v[0] is " << endl;
// for (i = 0; i < 3; i++)
// {
// cout << v[0]->arr[person][i] << endl;
// }
// cout << "\n";
for (auto &x : s)
{
int char_id = x - 'a';
// cout << "curr node id is " << curr_node->id << endl;
// cout << ((curr_node == v[0]) ? 1:0) << endl;
if (curr_node->arr[person][char_id] == -1)
{
//make new node
if (curr_node->arr[1 - person][char_id] == -1)
{
// cout << "did not find " << x << endl;
curr_node->arr[person][char_id] = v.size();
v.pb(get_node());
}
else
{
curr_node->arr[person][char_id] = curr_node->arr[1 - person][char_id];
}
}
else
{
// cout << "found " << x << endl;
}
// debug(curr_node->arr[person][char_id]);
// debug(v.size());
assert(curr_node->arr[person][char_id] < v.size());
curr_node = (v[curr_node->arr[person][char_id]]);
}
// cout << "AGAIN v[0] is " << endl;
// for (i = 0; i < 3; i++)
// {
// cout << v[0]->arr[person][i] << endl;
// }
// cout << "\n";
// part;
}
bool is_winning(int person_turn, node *curr_node)
{
//must be losing for other person
// bool curr_stat = false;
// debug(person_turn);
for (int i = 0; i < 26; i++)
{
if (curr_node->arr[person_turn][i] != -1)
{
// debug(i);
bool stat = is_winning(person_turn ^ 1, v[curr_node->arr[person_turn][i]]);
// cout << "node at " << (char)(i + 'a') << " returned " << stat << endl;
if (stat == false)
{
return true;
}
}
}
return false;
}
struct node *root = get_node();
int main()
{
fastinput;
LL n, i, j, k, temp, tc;
int num1, num2;
cin >> num1;
v.pb(root);
for (i = 0; i < num1; i++)
{
string t;
cin >> t;
s[0].pb(t);
insert(t, 0);
}
// return 0;
cin >> num2;
for (i = 0; i < num2; i++)
{
string t;
cin >> t;
s[1].pb(t);
insert(t, 1);
}
//////////////////////////////////
// debug(v.size());
bool final = is_winning(0, v[0]);
if (final)
{
cout << "Nina" << endl;
}
else
{
cout << "Emilija" << endl;
}
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... |