#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 shift = 9;
const int maxN = 3e5 + 20;
int L[maxN];
int R[maxN];
vector<int> adj1[maxN];
vector<int> adj2[maxN];
bool done = false;
int n, k;
void init(int _n, int _k) {
n = _n;
k = _k;
for (int i = 0; i < k; i++) {
L[i] = i;
R[i] = i + 1;
}
for (int i = k; i < n; i++) {
L[i] = 0;
R[i] = k + 1;
}
}
void update_L(int u, int val);
void update_R(int u, int val);
void update_L(int u, int val) {
if (done) {
return;
}
bool diff = (L[u] >> shift) != (val >> shift);
bool same = (L[u] >> shift) == (R[u] >> shift);
L[u] = val;
if (L[u] >= R[u]) {
done = true;
return;
}
if (diff) {
for (auto v: adj1[u]) {
if (L[u] > L[v]) {
update_L(v, L[u]);
}
}
}
else if (same) {
for (auto v: adj1[u]) {
if (L[u] > L[v]) {
update_L(v, L[u]);
}
}
for (auto v: adj2[u]) {
if (R[u] < R[v]) {
update_R(v, R[u]);
}
}
}
}
void update_R(int u, int val) {
if (done) {
return;
}
bool diff = (R[u] >> shift) != (val >> shift);
bool same = (L[u] >> shift) == (R[u] >> shift);
R[u] = val;
if (L[u] >= R[u]) {
done = true;
return;
}
if (diff) {
for (auto v: adj2[u]) {
if (R[u] < R[v]) {
update_R(v, R[u]);
}
}
}
else if (same) {
for (auto v: adj1[u]) {
if (L[u] > L[v]) {
update_L(v, L[u]);
}
}
for (auto v: adj2[u]) {
if (R[u] < R[v]) {
update_R(v, R[u]);
}
}
}
}
int add_teleporter(int u, int v) {
int val = max(L[u], (u < k ? u + 1 : 0));
if (val > L[v]) {
update_L(v, val);
}
if (R[v] < R[u]) {
update_R(u, R[v]);
}
adj1[u].push_back(v);
adj2[v].push_back(u);
return done;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
9 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14408 KB |
Output is correct |
6 |
Correct |
8 ms |
14288 KB |
Output is correct |
7 |
Correct |
9 ms |
14292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
9 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14408 KB |
Output is correct |
6 |
Correct |
8 ms |
14288 KB |
Output is correct |
7 |
Correct |
9 ms |
14292 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
11 ms |
14352 KB |
Output is correct |
11 |
Correct |
11 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14408 KB |
Output is correct |
13 |
Correct |
10 ms |
14288 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 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 |
14400 KB |
Output is correct |
19 |
Correct |
9 ms |
14344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
9 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14408 KB |
Output is correct |
6 |
Correct |
8 ms |
14288 KB |
Output is correct |
7 |
Correct |
9 ms |
14292 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
11 ms |
14352 KB |
Output is correct |
11 |
Correct |
11 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14408 KB |
Output is correct |
13 |
Correct |
10 ms |
14288 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 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 |
14400 KB |
Output is correct |
19 |
Correct |
9 ms |
14344 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
9 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
10 ms |
14408 KB |
Output is correct |
24 |
Correct |
13 ms |
14496 KB |
Output is correct |
25 |
Correct |
13 ms |
14460 KB |
Output is correct |
26 |
Correct |
10 ms |
14412 KB |
Output is correct |
27 |
Correct |
11 ms |
14416 KB |
Output is correct |
28 |
Correct |
10 ms |
14340 KB |
Output is correct |
29 |
Correct |
11 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
9 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14408 KB |
Output is correct |
6 |
Correct |
8 ms |
14288 KB |
Output is correct |
7 |
Correct |
9 ms |
14292 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
11 ms |
14352 KB |
Output is correct |
11 |
Correct |
11 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14408 KB |
Output is correct |
13 |
Correct |
10 ms |
14288 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 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 |
14400 KB |
Output is correct |
19 |
Correct |
9 ms |
14344 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
9 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
10 ms |
14408 KB |
Output is correct |
24 |
Correct |
13 ms |
14496 KB |
Output is correct |
25 |
Correct |
13 ms |
14460 KB |
Output is correct |
26 |
Correct |
10 ms |
14412 KB |
Output is correct |
27 |
Correct |
11 ms |
14416 KB |
Output is correct |
28 |
Correct |
10 ms |
14340 KB |
Output is correct |
29 |
Correct |
11 ms |
14416 KB |
Output is correct |
30 |
Correct |
26 ms |
15696 KB |
Output is correct |
31 |
Correct |
12 ms |
15024 KB |
Output is correct |
32 |
Correct |
31 ms |
16840 KB |
Output is correct |
33 |
Correct |
26 ms |
16488 KB |
Output is correct |
34 |
Correct |
42 ms |
18640 KB |
Output is correct |
35 |
Correct |
53 ms |
17196 KB |
Output is correct |
36 |
Correct |
43 ms |
16464 KB |
Output is correct |
37 |
Correct |
35 ms |
16432 KB |
Output is correct |
38 |
Correct |
34 ms |
16184 KB |
Output is correct |
39 |
Correct |
57 ms |
16260 KB |
Output is correct |
40 |
Correct |
62 ms |
18660 KB |
Output is correct |
41 |
Correct |
48 ms |
17552 KB |
Output is correct |
42 |
Correct |
47 ms |
16936 KB |
Output is correct |
43 |
Correct |
60 ms |
17872 KB |
Output is correct |
44 |
Correct |
205 ms |
17996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
9 ms |
14288 KB |
Output is correct |
5 |
Correct |
9 ms |
14408 KB |
Output is correct |
6 |
Correct |
8 ms |
14288 KB |
Output is correct |
7 |
Correct |
9 ms |
14292 KB |
Output is correct |
8 |
Correct |
9 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14288 KB |
Output is correct |
10 |
Correct |
11 ms |
14352 KB |
Output is correct |
11 |
Correct |
11 ms |
14288 KB |
Output is correct |
12 |
Correct |
10 ms |
14408 KB |
Output is correct |
13 |
Correct |
10 ms |
14288 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 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 |
14400 KB |
Output is correct |
19 |
Correct |
9 ms |
14344 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
9 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
10 ms |
14408 KB |
Output is correct |
24 |
Correct |
13 ms |
14496 KB |
Output is correct |
25 |
Correct |
13 ms |
14460 KB |
Output is correct |
26 |
Correct |
10 ms |
14412 KB |
Output is correct |
27 |
Correct |
11 ms |
14416 KB |
Output is correct |
28 |
Correct |
10 ms |
14340 KB |
Output is correct |
29 |
Correct |
11 ms |
14416 KB |
Output is correct |
30 |
Correct |
26 ms |
15696 KB |
Output is correct |
31 |
Correct |
12 ms |
15024 KB |
Output is correct |
32 |
Correct |
31 ms |
16840 KB |
Output is correct |
33 |
Correct |
26 ms |
16488 KB |
Output is correct |
34 |
Correct |
42 ms |
18640 KB |
Output is correct |
35 |
Correct |
53 ms |
17196 KB |
Output is correct |
36 |
Correct |
43 ms |
16464 KB |
Output is correct |
37 |
Correct |
35 ms |
16432 KB |
Output is correct |
38 |
Correct |
34 ms |
16184 KB |
Output is correct |
39 |
Correct |
57 ms |
16260 KB |
Output is correct |
40 |
Correct |
62 ms |
18660 KB |
Output is correct |
41 |
Correct |
48 ms |
17552 KB |
Output is correct |
42 |
Correct |
47 ms |
16936 KB |
Output is correct |
43 |
Correct |
60 ms |
17872 KB |
Output is correct |
44 |
Correct |
205 ms |
17996 KB |
Output is correct |
45 |
Correct |
261 ms |
28064 KB |
Output is correct |
46 |
Correct |
15 ms |
17104 KB |
Output is correct |
47 |
Correct |
15 ms |
17056 KB |
Output is correct |
48 |
Correct |
383 ms |
45496 KB |
Output is correct |
49 |
Correct |
300 ms |
35412 KB |
Output is correct |
50 |
Execution timed out |
4064 ms |
40384 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |