# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
745584 |
2023-05-20T13:42:05 Z |
Perl32 |
Vlak (COCI20_vlak) |
C++14 |
|
42 ms |
20584 KB |
/**
* author: Perl32
* created: 19.05.2023 17:00:04
**/
#ifdef LOCAL
# define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define szof(x) (int) x.size()
#define all(x) x.begin(), x.end()
#ifndef LOCAL
# define cerr __get_ce
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef complex<double> cmpl;
typedef unsigned long long ull;
using namespace __gnu_pbds;
template<typename K, typename V> using normal_unordered_map = gp_hash_table<K, V>;
template<typename T> using normal_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = (int) 1e9 + 1e3;
const ll INFL = (ll) 1e18 + 1e6;
#ifdef LOCAL
mt19937 tw(9450189);
#else
mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }
struct Trie {
struct Node {
unordered_map<char, int> next;
bool terminal = false;
};
vector<Node> tree;
Trie() {
tree.emplace_back();
}
bool contain(int x, char ch) {
return tree[x].next.find(ch) != tree[x].next.end();
}
int add(int x, char ch, bool terminal) {
if (!contain(x, ch)) {
tree[x].next[ch] = szof(tree);
tree.emplace_back();
}
tree[tree[x].next[ch]].terminal = terminal;
return tree[x].next[ch];
}
int go(int x, char ch) {
if (!contain(x, ch)) {
return -1;
}
return tree[x].next[ch];
}
void debug() {
vector<char> path;
function<void(int)> dfs = [&](int u) {
if (tree[u].terminal) {
for (auto x : path) {
cout << x;
}
cout << '\n';
}
for (auto [ch, to] : tree[u].next) {
path.push_back(ch);
dfs(to);
path.pop_back();
}
};
dfs(0);
}
};
signed main() {
#ifdef LOCAL
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("err.txt", "w", stderr);
auto start_time = clock();
cerr << setprecision(3) << fixed;
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
Trie fir;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
int v = 0;
for (int j = 0; j < szof(s); ++j) {
v = fir.add(v, s[j], j == (szof(s) - 1));
}
}
int m;
cin >> m;
Trie sec;
for (int i = 0; i < m; ++i) {
string s;
cin >> s;
int v = 0;
for (int j = 0; j < szof(s); ++j) {
v = sec.add(v, s[j], j == (szof(s) - 1));
}
}
function<int(bool, int, int)> build = [&](bool flag, int v1, int v2) {
if (flag && v1 == -1) {
return -1;
} else if (!flag && v2 == -1) {
return 1;
}
int ret = (flag? -1 : 1);
if (flag) {
for (auto [ch, to] : fir.tree[v1].next) {
ret = max(ret, build(!flag, fir.go(v1, ch), sec.go(v2, ch)));
}
} else {
for (auto [ch, to] : sec.tree[v2].next) {
ret = min(ret, build(!flag, fir.go(v1, ch), sec.go(v2, ch)));
}
}
return ret;
};
if (build(true, 0, 0) == 1) {
cout << "Nina";
} else {
cout << "Emilija";
}
#ifdef LOCAL
auto end_time = clock();
cerr << "Execution time: " << (end_time - start_time) * (ll) 1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}
Compilation message
Main.cpp: In lambda function:
Main.cpp:84:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
84 | for (auto [ch, to] : tree[u].next) {
| ^
Main.cpp: In lambda function:
Main.cpp:135:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
135 | for (auto [ch, to] : fir.tree[v1].next) {
| ^
Main.cpp:139:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
139 | for (auto [ch, to] : sec.tree[v2].next) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
584 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
580 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
18696 KB |
Output is correct |
2 |
Correct |
33 ms |
18020 KB |
Output is correct |
3 |
Correct |
42 ms |
17356 KB |
Output is correct |
4 |
Correct |
39 ms |
18424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
19696 KB |
Output is correct |
2 |
Correct |
32 ms |
20584 KB |
Output is correct |
3 |
Correct |
31 ms |
19240 KB |
Output is correct |
4 |
Correct |
35 ms |
19340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
18744 KB |
Output is correct |
2 |
Correct |
33 ms |
18400 KB |
Output is correct |
3 |
Correct |
32 ms |
18556 KB |
Output is correct |
4 |
Correct |
32 ms |
19412 KB |
Output is correct |