#include "game.h"
#include <bits/stdc++.h>
constexpr int N = 3e5 + 7, B = 8, inf = 1e9 + 7;
int fromMe[N], toMe[N], Mid[N], save[N][2], n, k; //smallest from me, biggest to me
std::vector<int> adj[N], rev[N];
bool found = false;
void relax(int v) {
if (v >= k && fromMe[v] <= toMe[v]) {
found = true;
}
Mid[v] = (fromMe[v] + toMe[v]) >> 1;
}
void init(int n, int k) {
::n = n, ::k = k;
for (int i = 0; i < n; ++i) {
if (i >= k) {
fromMe[i] = k, toMe[i] = -1;
} else {
fromMe[i] = toMe[i] = i;
}
save[i][0] = inf, save[i][1] = -inf;
relax(i);
}
}
void dfs2(int v, int x);
void dfs1(int v, int x) {
if (found || v < k || fromMe[v] <= x) {
return;
}
int init = Mid[v];
fromMe[v] = x;
relax(v);
if (init < x) {
save[v][0] = std::min(save[v][0], x);
return;
}
for (int to : rev[v]) {
dfs1(to, x);
}
dfs2(v, save[v][1]);
}
void dfs2(int v, int x) {
if (found || v < k || toMe[v] >= x) {
return;
}
int init = Mid[v];
toMe[v] = x;
relax(v);
if (init > x) {
save[v][1] = std::max(save[v][1], x);
return;
}
for (int to : adj[v]) {
dfs2(to, x);
}
dfs1(v, save[v][0]);
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 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 |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
9 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
9 ms |
14436 KB |
Output is correct |
14 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 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 |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
9 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
9 ms |
14436 KB |
Output is correct |
14 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 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 |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
9 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
9 ms |
14436 KB |
Output is correct |
14 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 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 |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
9 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
9 ms |
14436 KB |
Output is correct |
14 |
Incorrect |
8 ms |
14416 KB |
Wrong Answer[1] |
15 |
Halted |
0 ms |
0 KB |
- |