# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
712988 |
2023-03-20T18:07:21 Z |
piOOE |
Game (APIO22_game) |
C++17 |
|
4000 ms |
41756 KB |
#include "game.h"
#include <bits/stdc++.h>
constexpr int N = 3e5 + 7, B = 8, inf = 1e9 + 7;
int fromMe[N], toMe[N], save[N][2], n, k; //smallest from me, biggest to me
std::vector<int> adj[N], rev[N];
bool found = false;
void init(int n, int k) {
::n = n, ::k = k;
for (int i = 0; i < n; ++i) {
if (i >= k) {
fromMe[i] = inf, toMe[i] = -inf;
} else {
fromMe[i] = toMe[i] = i;
}
save[i][0] = inf, save[i][1] = -inf;
}
}
void dfs2(int v, int x);
void dfs1(int v, int x) {
if (found || v < k || fromMe[v] <= x) {
return;
}
if ((fromMe[v] >> B != toMe[v] >> B) && (fromMe[v] >> B) <= (x >> B)) {
save[v][0] = std::min(save[v][0], x);
return;
}
fromMe[v] = x;
if (fromMe[v] <= toMe[v]) {
found = true;
return;
}
if ((toMe[v] >> B) == (fromMe[v] >> B)) {
if (save[v][1] >= 0) {
int s = save[v][1];
save[v][1] = -1;
dfs2(v, s);
}
}
for (int to : rev[v]) {
dfs1(to, x);
}
}
void dfs2(int v, int x) {
if (found || v < k || toMe[v] >= x) {
return;
}
if ((fromMe[v] >> B) != (toMe[v] >> B) && (toMe[v] >> B) >= (x >> B)) {
save[v][1] = std::max(save[v][1], x);
return;
}
toMe[v] = x;
if (fromMe[v] <= toMe[v]) {
found = true;
return;
}
if ((toMe[v] >> B) == (fromMe[v] >> B)) {
if (save[v][0] <= k) {
int s = save[v][0];
save[v][0] = k + 1;
dfs1(v, s);
}
}
for (int to : adj[v]) {
dfs2(to, x);
}
}
int add_teleporter(int u, int v) {
if (u < k && v < k && u >= v) {
return 1;
}
adj[u].push_back(v);
rev[v].push_back(u);
dfs1(u, fromMe[v]);
dfs2(v, toMe[u]);
return found;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
7 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
7 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
8 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
8 ms |
14288 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14324 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14324 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
7 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
8 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
8 ms |
14288 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14324 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14324 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14428 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14488 KB |
Output is correct |
25 |
Correct |
10 ms |
14416 KB |
Output is correct |
26 |
Correct |
11 ms |
14452 KB |
Output is correct |
27 |
Correct |
9 ms |
14416 KB |
Output is correct |
28 |
Correct |
11 ms |
14416 KB |
Output is correct |
29 |
Correct |
10 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
7 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
8 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
8 ms |
14288 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14324 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14324 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14428 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14488 KB |
Output is correct |
25 |
Correct |
10 ms |
14416 KB |
Output is correct |
26 |
Correct |
11 ms |
14452 KB |
Output is correct |
27 |
Correct |
9 ms |
14416 KB |
Output is correct |
28 |
Correct |
11 ms |
14416 KB |
Output is correct |
29 |
Correct |
10 ms |
14416 KB |
Output is correct |
30 |
Correct |
26 ms |
15980 KB |
Output is correct |
31 |
Correct |
13 ms |
15184 KB |
Output is correct |
32 |
Correct |
29 ms |
16832 KB |
Output is correct |
33 |
Correct |
25 ms |
16692 KB |
Output is correct |
34 |
Correct |
45 ms |
18484 KB |
Output is correct |
35 |
Correct |
49 ms |
17376 KB |
Output is correct |
36 |
Correct |
47 ms |
16688 KB |
Output is correct |
37 |
Correct |
36 ms |
16592 KB |
Output is correct |
38 |
Correct |
35 ms |
16464 KB |
Output is correct |
39 |
Correct |
36 ms |
16444 KB |
Output is correct |
40 |
Correct |
63 ms |
18488 KB |
Output is correct |
41 |
Correct |
41 ms |
16940 KB |
Output is correct |
42 |
Correct |
37 ms |
16812 KB |
Output is correct |
43 |
Correct |
44 ms |
17312 KB |
Output is correct |
44 |
Correct |
113 ms |
17632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14416 KB |
Output is correct |
3 |
Correct |
7 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
8 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
8 ms |
14288 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14324 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14324 KB |
Output is correct |
17 |
Correct |
7 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14428 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14488 KB |
Output is correct |
25 |
Correct |
10 ms |
14416 KB |
Output is correct |
26 |
Correct |
11 ms |
14452 KB |
Output is correct |
27 |
Correct |
9 ms |
14416 KB |
Output is correct |
28 |
Correct |
11 ms |
14416 KB |
Output is correct |
29 |
Correct |
10 ms |
14416 KB |
Output is correct |
30 |
Correct |
26 ms |
15980 KB |
Output is correct |
31 |
Correct |
13 ms |
15184 KB |
Output is correct |
32 |
Correct |
29 ms |
16832 KB |
Output is correct |
33 |
Correct |
25 ms |
16692 KB |
Output is correct |
34 |
Correct |
45 ms |
18484 KB |
Output is correct |
35 |
Correct |
49 ms |
17376 KB |
Output is correct |
36 |
Correct |
47 ms |
16688 KB |
Output is correct |
37 |
Correct |
36 ms |
16592 KB |
Output is correct |
38 |
Correct |
35 ms |
16464 KB |
Output is correct |
39 |
Correct |
36 ms |
16444 KB |
Output is correct |
40 |
Correct |
63 ms |
18488 KB |
Output is correct |
41 |
Correct |
41 ms |
16940 KB |
Output is correct |
42 |
Correct |
37 ms |
16812 KB |
Output is correct |
43 |
Correct |
44 ms |
17312 KB |
Output is correct |
44 |
Correct |
113 ms |
17632 KB |
Output is correct |
45 |
Correct |
232 ms |
30376 KB |
Output is correct |
46 |
Correct |
16 ms |
19536 KB |
Output is correct |
47 |
Correct |
15 ms |
19440 KB |
Output is correct |
48 |
Correct |
302 ms |
41756 KB |
Output is correct |
49 |
Correct |
292 ms |
37772 KB |
Output is correct |
50 |
Execution timed out |
4091 ms |
34868 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |