# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
597043 |
2022-07-15T12:18:13 Z |
KoD |
Game (APIO22_game) |
C++17 |
|
1350 ms |
262144 KB |
#include "game.h"
#include <bits/stdc++.h>
using std::pair;
using std::queue;
using std::set;
using std::vector;
bool contains(set<int>& set, const int x) {
return set.find(x) != set.end();
}
struct Interval {
int mid, lch, rch;
set<int> from, to;
explicit Interval(const int m) : mid(m), lch(-1), rch(-1), from(), to() {}
};
int N, K;
vector<vector<int>> graph, revgraph;
vector<Interval> segtree;
int build(int l, int r) {
const int u = (int)segtree.size();
const int m = (l + r) / 2;
segtree.emplace_back(m);
if (l < m)
segtree[u].lch = build(l, m);
if (m + 1 < r)
segtree[u].rch = build(m + 1, r);
for (int i = l; i < m; ++i)
segtree[u].from.insert(i);
for (int i = m + 1; i < r; ++i)
segtree[u].to.insert(i);
return u;
}
void init(int n, int k) {
N = n;
K = k;
graph.resize(n);
revgraph.resize(n);
build(0, k);
}
bool insert_recursive(int x, int u) {
auto& data = segtree[x];
if (data.mid == u)
return true;
if (data.to.insert(u).second) {
if (contains(data.from, u))
return true;
for (const int v : graph[u])
if (insert_recursive(x, v))
return true;
}
return false;
}
bool insert_recursive_rev(int x, int u) {
auto& data = segtree[x];
if (data.mid == u)
return true;
if (data.from.insert(u).second) {
if (contains(data.to, u))
return true;
for (const int v : revgraph[u])
if (insert_recursive_rev(x, v))
return true;
}
return false;
}
bool add_recursive(int x, int u, int v) {
auto& data = segtree[x];
if (contains(data.from, v) or v == data.mid) {
if (insert_recursive_rev(x, u))
return true;
}
if (contains(data.to, u) or u == data.mid) {
if (insert_recursive(x, v))
return true;
}
if (contains(data.from, u) and contains(data.from, v)) {
if (data.lch != -1 and add_recursive(data.lch, u, v))
return true;
} else {
if (data.rch != -1 and add_recursive(data.rch, u, v))
return true;
}
return false;
}
int add_teleporter(int u, int v) {
graph[u].push_back(v);
revgraph[v].push_back(u);
return add_recursive(0, u, v);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
25 ms |
8260 KB |
Output is correct |
25 |
Correct |
25 ms |
4600 KB |
Output is correct |
26 |
Correct |
10 ms |
720 KB |
Output is correct |
27 |
Correct |
11 ms |
848 KB |
Output is correct |
28 |
Correct |
6 ms |
848 KB |
Output is correct |
29 |
Correct |
13 ms |
1172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
25 ms |
8260 KB |
Output is correct |
25 |
Correct |
25 ms |
4600 KB |
Output is correct |
26 |
Correct |
10 ms |
720 KB |
Output is correct |
27 |
Correct |
11 ms |
848 KB |
Output is correct |
28 |
Correct |
6 ms |
848 KB |
Output is correct |
29 |
Correct |
13 ms |
1172 KB |
Output is correct |
30 |
Correct |
42 ms |
3068 KB |
Output is correct |
31 |
Correct |
12 ms |
2708 KB |
Output is correct |
32 |
Correct |
36 ms |
6848 KB |
Output is correct |
33 |
Correct |
20 ms |
4280 KB |
Output is correct |
34 |
Runtime error |
1350 ms |
262144 KB |
Execution killed with signal 9 |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
25 ms |
8260 KB |
Output is correct |
25 |
Correct |
25 ms |
4600 KB |
Output is correct |
26 |
Correct |
10 ms |
720 KB |
Output is correct |
27 |
Correct |
11 ms |
848 KB |
Output is correct |
28 |
Correct |
6 ms |
848 KB |
Output is correct |
29 |
Correct |
13 ms |
1172 KB |
Output is correct |
30 |
Correct |
42 ms |
3068 KB |
Output is correct |
31 |
Correct |
12 ms |
2708 KB |
Output is correct |
32 |
Correct |
36 ms |
6848 KB |
Output is correct |
33 |
Correct |
20 ms |
4280 KB |
Output is correct |
34 |
Runtime error |
1350 ms |
262144 KB |
Execution killed with signal 9 |
35 |
Halted |
0 ms |
0 KB |
- |