#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 20;
int block;
int max_in[maxN];
int min_out[maxN];
vector<int> adj1[maxN];
vector<int> adj2[maxN];
bool done = false;
int n, k;
void init(int _n, int _k) {
done = false;
n = _n;
k = _k;
block = sqrt(k);
for (int i = 0; i < k; i++) {
max_in[i] = i - 1;
min_out[i] = i;
}
for (int i = k; i < n; i++) {
max_in[i] = -1;
min_out[i] = k;
}
}
void update_in(int u, int val, bool same = false) {
if (done) {
return;
}
if (val <= max_in[u]) {
return;
}
bool f1 = (max_in[u] / block) < (val / block);
bool f2 = (max_in[u] / block) == (min_out[u] / block);
if (same) {
assert(f2);
}
max_in[u] = val;
if (max_in[u] >= min_out[u]) {
done = true;
return;
}
if (f1 || f2) {
for (auto v: adj1[u]) {
update_in(v, val, f2);
}
}
}
void update_out(int u, int val, bool same = false) {
if (done) {
return;
}
if (val >= min_out[u]) {
return;
}
bool f1 = (min_out[u] / block) > (val / block);
bool f2 = (max_in[u] / block) == (min_out[u] / block);
if (same) {
assert(f2);
}
min_out[u] = val;
if (max_in[u] >= min_out[u]) {
done = true;
return;
}
if (f1 || f2) {
for (auto v: adj2[u]) {
update_out(v, val, f2);
}
}
}
int add_teleporter(int u, int v) {
update_in(v, max(max_in[u], (u < k ? u : -1)));
update_out(u, min_out[v]);
adj1[u].push_back(v);
adj2[v].push_back(u);
return done;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14340 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14384 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
10 ms |
14408 KB |
Output is correct |
6 |
Correct |
10 ms |
14288 KB |
Output is correct |
7 |
Correct |
10 ms |
14400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14340 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14384 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
10 ms |
14408 KB |
Output is correct |
6 |
Correct |
10 ms |
14288 KB |
Output is correct |
7 |
Correct |
10 ms |
14400 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14328 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14288 KB |
Output is correct |
12 |
Correct |
7 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
8 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14332 KB |
Output is correct |
17 |
Correct |
8 ms |
14364 KB |
Output is correct |
18 |
Incorrect |
8 ms |
14312 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14340 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14384 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
10 ms |
14408 KB |
Output is correct |
6 |
Correct |
10 ms |
14288 KB |
Output is correct |
7 |
Correct |
10 ms |
14400 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14328 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14288 KB |
Output is correct |
12 |
Correct |
7 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
8 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14332 KB |
Output is correct |
17 |
Correct |
8 ms |
14364 KB |
Output is correct |
18 |
Incorrect |
8 ms |
14312 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14340 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14384 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
10 ms |
14408 KB |
Output is correct |
6 |
Correct |
10 ms |
14288 KB |
Output is correct |
7 |
Correct |
10 ms |
14400 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14328 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14288 KB |
Output is correct |
12 |
Correct |
7 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
8 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14332 KB |
Output is correct |
17 |
Correct |
8 ms |
14364 KB |
Output is correct |
18 |
Incorrect |
8 ms |
14312 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14340 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14384 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
10 ms |
14408 KB |
Output is correct |
6 |
Correct |
10 ms |
14288 KB |
Output is correct |
7 |
Correct |
10 ms |
14400 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14328 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
7 ms |
14288 KB |
Output is correct |
12 |
Correct |
7 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
8 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14332 KB |
Output is correct |
17 |
Correct |
8 ms |
14364 KB |
Output is correct |
18 |
Incorrect |
8 ms |
14312 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |