#include "game.h"
#include <string>
#include <algorithm>
#define N 300000
std::basic_string<int> g[N], gt[N];
int n, k, from[N], to[N], cyclic, lvl[N];
void init(int n_, int k_) {
n = n_, k = k_;
for (int i = 0; i < k; ++i)
to[i] = i, from[i] = i + 1;
for (int i = k; i < n; ++i)
from[i] = k, to[i] = -1;
for (int i = 0; i < n; ++i)
lvl[i] = __builtin_clz(from[i] ^ to[i]);
}
void check(int u) {
if (to[u] >= from[u] || cyclic) {
cyclic = 86;
return;
}
int d = __builtin_clz(from[u] ^ to[u]);
if (d > lvl[u]) {
lvl[u] = d;
for (auto v : g[u]) {
to[v] = std::max(to[v], to[u]);
check(v);
}
for (auto v : gt[u]) {
from[v] = std::min(from[v], from[u]);
check(v);
}
}
}
int add_teleporter(int u, int v) {
if (cyclic)
return 1;
g[u].push_back(v);
gt[v].push_back(u);
to[v] = std::max(to[v], to[u]);
from[u] = std::min(from[u], from[v]);
if (u < k) to[v] = std::max(to[v], u);
if (v < k) from[u] = std::min(from[u], v);
check(u);
check(v);
return !!cyclic;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19032 KB |
Output is correct |
3 |
Correct |
9 ms |
19032 KB |
Output is correct |
4 |
Correct |
9 ms |
19032 KB |
Output is correct |
5 |
Correct |
9 ms |
19032 KB |
Output is correct |
6 |
Correct |
9 ms |
19220 KB |
Output is correct |
7 |
Correct |
9 ms |
19032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19032 KB |
Output is correct |
3 |
Correct |
9 ms |
19032 KB |
Output is correct |
4 |
Correct |
9 ms |
19032 KB |
Output is correct |
5 |
Correct |
9 ms |
19032 KB |
Output is correct |
6 |
Correct |
9 ms |
19220 KB |
Output is correct |
7 |
Correct |
9 ms |
19032 KB |
Output is correct |
8 |
Correct |
9 ms |
19032 KB |
Output is correct |
9 |
Correct |
9 ms |
19032 KB |
Output is correct |
10 |
Correct |
9 ms |
19032 KB |
Output is correct |
11 |
Correct |
10 ms |
19032 KB |
Output is correct |
12 |
Correct |
9 ms |
19032 KB |
Output is correct |
13 |
Correct |
9 ms |
19032 KB |
Output is correct |
14 |
Correct |
9 ms |
19032 KB |
Output is correct |
15 |
Correct |
9 ms |
19032 KB |
Output is correct |
16 |
Correct |
9 ms |
19032 KB |
Output is correct |
17 |
Correct |
9 ms |
19040 KB |
Output is correct |
18 |
Correct |
10 ms |
19032 KB |
Output is correct |
19 |
Correct |
9 ms |
19032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19032 KB |
Output is correct |
3 |
Correct |
9 ms |
19032 KB |
Output is correct |
4 |
Correct |
9 ms |
19032 KB |
Output is correct |
5 |
Correct |
9 ms |
19032 KB |
Output is correct |
6 |
Correct |
9 ms |
19220 KB |
Output is correct |
7 |
Correct |
9 ms |
19032 KB |
Output is correct |
8 |
Correct |
9 ms |
19032 KB |
Output is correct |
9 |
Correct |
9 ms |
19032 KB |
Output is correct |
10 |
Correct |
9 ms |
19032 KB |
Output is correct |
11 |
Correct |
10 ms |
19032 KB |
Output is correct |
12 |
Correct |
9 ms |
19032 KB |
Output is correct |
13 |
Correct |
9 ms |
19032 KB |
Output is correct |
14 |
Correct |
9 ms |
19032 KB |
Output is correct |
15 |
Correct |
9 ms |
19032 KB |
Output is correct |
16 |
Correct |
9 ms |
19032 KB |
Output is correct |
17 |
Correct |
9 ms |
19040 KB |
Output is correct |
18 |
Correct |
10 ms |
19032 KB |
Output is correct |
19 |
Correct |
9 ms |
19032 KB |
Output is correct |
20 |
Correct |
9 ms |
19032 KB |
Output is correct |
21 |
Correct |
9 ms |
19032 KB |
Output is correct |
22 |
Correct |
10 ms |
19288 KB |
Output is correct |
23 |
Correct |
9 ms |
19032 KB |
Output is correct |
24 |
Correct |
9 ms |
19288 KB |
Output is correct |
25 |
Correct |
10 ms |
19288 KB |
Output is correct |
26 |
Correct |
11 ms |
19288 KB |
Output is correct |
27 |
Correct |
10 ms |
19288 KB |
Output is correct |
28 |
Correct |
10 ms |
19288 KB |
Output is correct |
29 |
Correct |
10 ms |
19288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19032 KB |
Output is correct |
3 |
Correct |
9 ms |
19032 KB |
Output is correct |
4 |
Correct |
9 ms |
19032 KB |
Output is correct |
5 |
Correct |
9 ms |
19032 KB |
Output is correct |
6 |
Correct |
9 ms |
19220 KB |
Output is correct |
7 |
Correct |
9 ms |
19032 KB |
Output is correct |
8 |
Correct |
9 ms |
19032 KB |
Output is correct |
9 |
Correct |
9 ms |
19032 KB |
Output is correct |
10 |
Correct |
9 ms |
19032 KB |
Output is correct |
11 |
Correct |
10 ms |
19032 KB |
Output is correct |
12 |
Correct |
9 ms |
19032 KB |
Output is correct |
13 |
Correct |
9 ms |
19032 KB |
Output is correct |
14 |
Correct |
9 ms |
19032 KB |
Output is correct |
15 |
Correct |
9 ms |
19032 KB |
Output is correct |
16 |
Correct |
9 ms |
19032 KB |
Output is correct |
17 |
Correct |
9 ms |
19040 KB |
Output is correct |
18 |
Correct |
10 ms |
19032 KB |
Output is correct |
19 |
Correct |
9 ms |
19032 KB |
Output is correct |
20 |
Correct |
9 ms |
19032 KB |
Output is correct |
21 |
Correct |
9 ms |
19032 KB |
Output is correct |
22 |
Correct |
10 ms |
19288 KB |
Output is correct |
23 |
Correct |
9 ms |
19032 KB |
Output is correct |
24 |
Correct |
9 ms |
19288 KB |
Output is correct |
25 |
Correct |
10 ms |
19288 KB |
Output is correct |
26 |
Correct |
11 ms |
19288 KB |
Output is correct |
27 |
Correct |
10 ms |
19288 KB |
Output is correct |
28 |
Correct |
10 ms |
19288 KB |
Output is correct |
29 |
Correct |
10 ms |
19288 KB |
Output is correct |
30 |
Correct |
17 ms |
19800 KB |
Output is correct |
31 |
Correct |
12 ms |
19544 KB |
Output is correct |
32 |
Correct |
20 ms |
19648 KB |
Output is correct |
33 |
Correct |
20 ms |
19544 KB |
Output is correct |
34 |
Correct |
27 ms |
22116 KB |
Output is correct |
35 |
Correct |
27 ms |
21080 KB |
Output is correct |
36 |
Correct |
32 ms |
20084 KB |
Output is correct |
37 |
Correct |
27 ms |
20824 KB |
Output is correct |
38 |
Correct |
28 ms |
20608 KB |
Output is correct |
39 |
Correct |
27 ms |
20304 KB |
Output is correct |
40 |
Correct |
32 ms |
22380 KB |
Output is correct |
41 |
Correct |
31 ms |
20908 KB |
Output is correct |
42 |
Correct |
27 ms |
20568 KB |
Output is correct |
43 |
Correct |
35 ms |
20848 KB |
Output is correct |
44 |
Correct |
33 ms |
21068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19032 KB |
Output is correct |
3 |
Correct |
9 ms |
19032 KB |
Output is correct |
4 |
Correct |
9 ms |
19032 KB |
Output is correct |
5 |
Correct |
9 ms |
19032 KB |
Output is correct |
6 |
Correct |
9 ms |
19220 KB |
Output is correct |
7 |
Correct |
9 ms |
19032 KB |
Output is correct |
8 |
Correct |
9 ms |
19032 KB |
Output is correct |
9 |
Correct |
9 ms |
19032 KB |
Output is correct |
10 |
Correct |
9 ms |
19032 KB |
Output is correct |
11 |
Correct |
10 ms |
19032 KB |
Output is correct |
12 |
Correct |
9 ms |
19032 KB |
Output is correct |
13 |
Correct |
9 ms |
19032 KB |
Output is correct |
14 |
Correct |
9 ms |
19032 KB |
Output is correct |
15 |
Correct |
9 ms |
19032 KB |
Output is correct |
16 |
Correct |
9 ms |
19032 KB |
Output is correct |
17 |
Correct |
9 ms |
19040 KB |
Output is correct |
18 |
Correct |
10 ms |
19032 KB |
Output is correct |
19 |
Correct |
9 ms |
19032 KB |
Output is correct |
20 |
Correct |
9 ms |
19032 KB |
Output is correct |
21 |
Correct |
9 ms |
19032 KB |
Output is correct |
22 |
Correct |
10 ms |
19288 KB |
Output is correct |
23 |
Correct |
9 ms |
19032 KB |
Output is correct |
24 |
Correct |
9 ms |
19288 KB |
Output is correct |
25 |
Correct |
10 ms |
19288 KB |
Output is correct |
26 |
Correct |
11 ms |
19288 KB |
Output is correct |
27 |
Correct |
10 ms |
19288 KB |
Output is correct |
28 |
Correct |
10 ms |
19288 KB |
Output is correct |
29 |
Correct |
10 ms |
19288 KB |
Output is correct |
30 |
Correct |
17 ms |
19800 KB |
Output is correct |
31 |
Correct |
12 ms |
19544 KB |
Output is correct |
32 |
Correct |
20 ms |
19648 KB |
Output is correct |
33 |
Correct |
20 ms |
19544 KB |
Output is correct |
34 |
Correct |
27 ms |
22116 KB |
Output is correct |
35 |
Correct |
27 ms |
21080 KB |
Output is correct |
36 |
Correct |
32 ms |
20084 KB |
Output is correct |
37 |
Correct |
27 ms |
20824 KB |
Output is correct |
38 |
Correct |
28 ms |
20608 KB |
Output is correct |
39 |
Correct |
27 ms |
20304 KB |
Output is correct |
40 |
Correct |
32 ms |
22380 KB |
Output is correct |
41 |
Correct |
31 ms |
20908 KB |
Output is correct |
42 |
Correct |
27 ms |
20568 KB |
Output is correct |
43 |
Correct |
35 ms |
20848 KB |
Output is correct |
44 |
Correct |
33 ms |
21068 KB |
Output is correct |
45 |
Correct |
130 ms |
23780 KB |
Output is correct |
46 |
Correct |
15 ms |
22616 KB |
Output is correct |
47 |
Correct |
13 ms |
22616 KB |
Output is correct |
48 |
Correct |
184 ms |
28692 KB |
Output is correct |
49 |
Correct |
152 ms |
22708 KB |
Output is correct |
50 |
Correct |
311 ms |
37700 KB |
Output is correct |
51 |
Correct |
383 ms |
31564 KB |
Output is correct |
52 |
Correct |
293 ms |
23632 KB |
Output is correct |
53 |
Correct |
361 ms |
23928 KB |
Output is correct |
54 |
Correct |
408 ms |
24508 KB |
Output is correct |
55 |
Correct |
565 ms |
24296 KB |
Output is correct |
56 |
Correct |
525 ms |
24280 KB |
Output is correct |
57 |
Correct |
254 ms |
25720 KB |
Output is correct |
58 |
Correct |
277 ms |
25824 KB |
Output is correct |
59 |
Correct |
280 ms |
25712 KB |
Output is correct |
60 |
Correct |
293 ms |
25912 KB |
Output is correct |
61 |
Correct |
328 ms |
25332 KB |
Output is correct |
62 |
Correct |
282 ms |
31260 KB |
Output is correct |
63 |
Correct |
302 ms |
30324 KB |
Output is correct |
64 |
Correct |
600 ms |
46048 KB |
Output is correct |
65 |
Correct |
214 ms |
27252 KB |
Output is correct |
66 |
Correct |
202 ms |
27084 KB |
Output is correct |
67 |
Correct |
341 ms |
29484 KB |
Output is correct |
68 |
Correct |
103 ms |
23496 KB |
Output is correct |
69 |
Correct |
38 ms |
22732 KB |
Output is correct |
70 |
Correct |
347 ms |
32624 KB |
Output is correct |
71 |
Correct |
179 ms |
24744 KB |
Output is correct |
72 |
Correct |
139 ms |
25452 KB |
Output is correct |
73 |
Correct |
299 ms |
29656 KB |
Output is correct |
74 |
Correct |
625 ms |
25128 KB |
Output is correct |
75 |
Correct |
550 ms |
31496 KB |
Output is correct |
76 |
Correct |
596 ms |
37540 KB |
Output is correct |