#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 20;
int max_in[maxN];
int min_out[maxN];
vector<int> adj1[maxN];
vector<int> adj2[maxN];
bool done = false;
int n, k;
int cnt;
void init(int _n, int _k) {
n = _n;
k = _k;
if (1LL * n * k > 1e9) {
assert(k != 150000);
}
for (int i = 0; i < k; i++) {
max_in[i] = i;
min_out[i] = i + 1;
}
for (int i = k; i < n; i++) {
max_in[i] = 0;
min_out[i] = k + 1;
}
}
void update_in(int u, int val);
void update_out(int u, int val);
void update_in(int u, int val) {
if (done) {
return;
}
if (val <= max_in[u]) {
return;
}
cnt++;
bool update = ((max_in[u] >> 9) < (val >> 9) || (max_in[u] >> 9) == (min_out[u] >> 9));
max_in[u] = val;
if (max_in[u] >= min_out[u]) {
done = true;
return;
}
if (update) {
for (auto v: adj1[u]) {
update_in(v, max_in[u]);
}
for (auto v: adj2[u]) {
update_out(v, min_out[u]);
}
}
}
void update_out(int u, int val) {
if (done) {
return;
}
if (val >= min_out[u]) {
return;
}
cnt++;
bool update = ((min_out[u] >> 9) > (val >> 9) || (max_in[u] >> 9) == (min_out[u] >> 9));
min_out[u] = val;
if (max_in[u] >= min_out[u]) {
done = true;
return;
}
if (update) {
for (auto v: adj1[u]) {
update_in(v, max_in[u]);
}
for (auto v: adj2[u]) {
update_out(v, min_out[u]);
}
}
}
int add_teleporter(int u, int v) {
update_in(v, max(max_in[u], (u < k ? u + 1 : 0)));
update_out(u, min_out[v]);
adj1[u].push_back(v);
adj2[v].push_back(u);
return done;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
9 ms |
14288 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14288 KB |
Output is correct |
6 |
Correct |
11 ms |
14292 KB |
Output is correct |
7 |
Correct |
9 ms |
14288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
9 ms |
14288 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14288 KB |
Output is correct |
6 |
Correct |
11 ms |
14292 KB |
Output is correct |
7 |
Correct |
9 ms |
14288 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
9 ms |
14292 KB |
Output is correct |
11 |
Correct |
8 ms |
14396 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14312 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14404 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
9 ms |
14288 KB |
Output is correct |
18 |
Correct |
9 ms |
14288 KB |
Output is correct |
19 |
Correct |
11 ms |
14288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
9 ms |
14288 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14288 KB |
Output is correct |
6 |
Correct |
11 ms |
14292 KB |
Output is correct |
7 |
Correct |
9 ms |
14288 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
9 ms |
14292 KB |
Output is correct |
11 |
Correct |
8 ms |
14396 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14312 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14404 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
9 ms |
14288 KB |
Output is correct |
18 |
Correct |
9 ms |
14288 KB |
Output is correct |
19 |
Correct |
11 ms |
14288 KB |
Output is correct |
20 |
Correct |
10 ms |
14416 KB |
Output is correct |
21 |
Correct |
11 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
9 ms |
14416 KB |
Output is correct |
24 |
Correct |
13 ms |
14416 KB |
Output is correct |
25 |
Correct |
13 ms |
14472 KB |
Output is correct |
26 |
Correct |
11 ms |
14460 KB |
Output is correct |
27 |
Correct |
11 ms |
14444 KB |
Output is correct |
28 |
Correct |
11 ms |
14324 KB |
Output is correct |
29 |
Correct |
11 ms |
14364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
9 ms |
14288 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14288 KB |
Output is correct |
6 |
Correct |
11 ms |
14292 KB |
Output is correct |
7 |
Correct |
9 ms |
14288 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
9 ms |
14292 KB |
Output is correct |
11 |
Correct |
8 ms |
14396 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14312 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14404 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
9 ms |
14288 KB |
Output is correct |
18 |
Correct |
9 ms |
14288 KB |
Output is correct |
19 |
Correct |
11 ms |
14288 KB |
Output is correct |
20 |
Correct |
10 ms |
14416 KB |
Output is correct |
21 |
Correct |
11 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
9 ms |
14416 KB |
Output is correct |
24 |
Correct |
13 ms |
14416 KB |
Output is correct |
25 |
Correct |
13 ms |
14472 KB |
Output is correct |
26 |
Correct |
11 ms |
14460 KB |
Output is correct |
27 |
Correct |
11 ms |
14444 KB |
Output is correct |
28 |
Correct |
11 ms |
14324 KB |
Output is correct |
29 |
Correct |
11 ms |
14364 KB |
Output is correct |
30 |
Correct |
27 ms |
15656 KB |
Output is correct |
31 |
Correct |
15 ms |
14916 KB |
Output is correct |
32 |
Correct |
31 ms |
16788 KB |
Output is correct |
33 |
Correct |
26 ms |
16512 KB |
Output is correct |
34 |
Correct |
42 ms |
20040 KB |
Output is correct |
35 |
Correct |
54 ms |
17708 KB |
Output is correct |
36 |
Correct |
49 ms |
16504 KB |
Output is correct |
37 |
Correct |
43 ms |
16548 KB |
Output is correct |
38 |
Correct |
32 ms |
16240 KB |
Output is correct |
39 |
Correct |
36 ms |
16216 KB |
Output is correct |
40 |
Correct |
69 ms |
19876 KB |
Output is correct |
41 |
Correct |
49 ms |
17128 KB |
Output is correct |
42 |
Correct |
44 ms |
16828 KB |
Output is correct |
43 |
Correct |
53 ms |
17496 KB |
Output is correct |
44 |
Correct |
196 ms |
17492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
9 ms |
14288 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14288 KB |
Output is correct |
6 |
Correct |
11 ms |
14292 KB |
Output is correct |
7 |
Correct |
9 ms |
14288 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
9 ms |
14292 KB |
Output is correct |
11 |
Correct |
8 ms |
14396 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14312 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14404 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
9 ms |
14288 KB |
Output is correct |
18 |
Correct |
9 ms |
14288 KB |
Output is correct |
19 |
Correct |
11 ms |
14288 KB |
Output is correct |
20 |
Correct |
10 ms |
14416 KB |
Output is correct |
21 |
Correct |
11 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
9 ms |
14416 KB |
Output is correct |
24 |
Correct |
13 ms |
14416 KB |
Output is correct |
25 |
Correct |
13 ms |
14472 KB |
Output is correct |
26 |
Correct |
11 ms |
14460 KB |
Output is correct |
27 |
Correct |
11 ms |
14444 KB |
Output is correct |
28 |
Correct |
11 ms |
14324 KB |
Output is correct |
29 |
Correct |
11 ms |
14364 KB |
Output is correct |
30 |
Correct |
27 ms |
15656 KB |
Output is correct |
31 |
Correct |
15 ms |
14916 KB |
Output is correct |
32 |
Correct |
31 ms |
16788 KB |
Output is correct |
33 |
Correct |
26 ms |
16512 KB |
Output is correct |
34 |
Correct |
42 ms |
20040 KB |
Output is correct |
35 |
Correct |
54 ms |
17708 KB |
Output is correct |
36 |
Correct |
49 ms |
16504 KB |
Output is correct |
37 |
Correct |
43 ms |
16548 KB |
Output is correct |
38 |
Correct |
32 ms |
16240 KB |
Output is correct |
39 |
Correct |
36 ms |
16216 KB |
Output is correct |
40 |
Correct |
69 ms |
19876 KB |
Output is correct |
41 |
Correct |
49 ms |
17128 KB |
Output is correct |
42 |
Correct |
44 ms |
16828 KB |
Output is correct |
43 |
Correct |
53 ms |
17496 KB |
Output is correct |
44 |
Correct |
196 ms |
17492 KB |
Output is correct |
45 |
Correct |
265 ms |
28036 KB |
Output is correct |
46 |
Correct |
14 ms |
17104 KB |
Output is correct |
47 |
Correct |
13 ms |
17116 KB |
Output is correct |
48 |
Correct |
337 ms |
43452 KB |
Output is correct |
49 |
Correct |
267 ms |
35484 KB |
Output is correct |
50 |
Runtime error |
23 ms |
28964 KB |
Execution killed with signal 6 |
51 |
Halted |
0 ms |
0 KB |
- |