#include <bits/stdc++.h>
#include "game.h"
const int OO = 0;
const int OOO = 0;
using namespace std;
int n, k;
vector<vector<int>> g, grev;
vector<int> s, e;
// s: maximum that reaches us
// e: minimum that we can reach
// s <= e as long as the answer is 0 (with s < e for all non-special vertices)
void init(int nn, int kk) {
g.clear();
grev.clear();
s.clear();
e.clear();
n = nn;
k = kk;
g.resize(n);
grev.resize(n);
s.resize(n, -1);
e.resize(n, n);
for (int i = 0; i < k; i++) {
s[i] = i;
e[i] = i;
}
}
int forward_bfs(int l, int m, int r, int v) {
if (OO) {
cout << "forward: v=" << v << ", lmr = " << l << " " << m << " " << r << '\n';
}
auto check = [&](int v) {
return l <= e[v] && s[v] < m;
};
if (!check(v)) return 0;
s[v] = m;
queue<int> q;
q.push(v);
while (q.size()) {
int x = q.front();
q.pop();
if (OO) {
cout << "doing vertex " << x << '\n';
}
for (const auto &i : g[x]) {
if (e[i] <= m) return 1;
if (!check(i)) continue;
s[i] = m;
q.push(i);
}
}
return 0;
}
int backward_bfs(int l, int m, int r, int v) {
if (OO) {
cout << "backward: v=" << v << ", lmr = " << l << " " << m << " " << r << '\n';
}
auto check = [&](int v) {
return m < e[v] && l <= s[v] && s[v] <= r;
};
if (!check(v)) return 0;
e[v] = m;
queue<int> q;
q.push(v);
while (q.size()) {
int x = q.front();
q.pop();
if (OO) {
cout << "doing vertex " << x << '\n';
}
for (const auto &i : grev[x]) {
if (!check(i)) continue;
e[i] = m;
q.push(i);
}
}
return 0;
}
int add(int layer, int l, int r, int u, int v) {
if (OO) {
cout << "on layer " << layer << " " << l << " " << r << '\n';
}
if (l > r) return 0;
int m = (l + r) / 2;
if (s[u] >= e[v]) return 1;
if (m <= s[u] && s[u] <= r)
if (forward_bfs(l, m, r, v)) return 1;
if (l <= e[v] && e[v] <= m)
if (backward_bfs(l, m, r, u)) return 1;
if ((m < s[u] && s[u] <= r) || (m < e[v] && e[v] <= r)) {
if (add(layer + 1, m + 1, r, u, v)) return 1;
}
if ((l <= s[u] && s[u] < m) || (l <= e[v] && e[v] < m)) {
if (add(layer + 1, l, m - 1, u, v)) return 1;
}
return 0;
}
void brute_dfs(vector<int> &vis, int v) {
if (vis[v]) return;
vis[v] = 1;
for (const auto &i : g[v])
brute_dfs(vis, i);
}
int brute() {
vector<int> vis(n);
for (int i = 0; i < k; i++) {
for (auto &x : vis) x = 0;
for (const auto &j : g[i])
brute_dfs(vis, j);
for (int j = 0; j <= i; j++)
if (vis[j]) return 1;
}
return 0;
}
int add_teleporter(int u, int v) {
if (OO) {
cout << "current s: ";
for (const auto &i : s) cout << i << " "; cout << '\n';
cout << "current e: ";
for (const auto &i : e) cout << i << " "; cout << '\n';
}
if (u < k && v < k) {
return u >= v;
}
g[u].push_back(v);
grev[v].push_back(u);
int x = add(0, 0, k - 1, u, v);
if (OOO) {
int y = brute();
if (x != y) {
cout << "difference! " << x << " " << y << '\n';
return 2;
}
}
return x;
}
Compilation message
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:130:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
130 | for (const auto &i : s) cout << i << " "; cout << '\n';
| ^~~
game.cpp:130:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
130 | for (const auto &i : s) cout << i << " "; cout << '\n';
| ^~~~
game.cpp:132:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
132 | for (const auto &i : e) cout << i << " "; cout << '\n';
| ^~~
game.cpp:132:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
132 | for (const auto &i : e) cout << i << " "; cout << '\n';
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
4 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
3 ms |
424 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
4 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
3 ms |
424 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
15 ms |
3016 KB |
Output is correct |
31 |
Correct |
7 ms |
2304 KB |
Output is correct |
32 |
Correct |
25 ms |
3748 KB |
Output is correct |
33 |
Correct |
26 ms |
3756 KB |
Output is correct |
34 |
Correct |
611 ms |
3892 KB |
Output is correct |
35 |
Correct |
218 ms |
3756 KB |
Output is correct |
36 |
Correct |
44 ms |
3800 KB |
Output is correct |
37 |
Correct |
50 ms |
3680 KB |
Output is correct |
38 |
Correct |
42 ms |
3568 KB |
Output is correct |
39 |
Correct |
52 ms |
3528 KB |
Output is correct |
40 |
Correct |
489 ms |
4096 KB |
Output is correct |
41 |
Correct |
132 ms |
3572 KB |
Output is correct |
42 |
Correct |
111 ms |
3528 KB |
Output is correct |
43 |
Correct |
44 ms |
3940 KB |
Output is correct |
44 |
Correct |
359 ms |
3784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
4 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
3 ms |
424 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
15 ms |
3016 KB |
Output is correct |
31 |
Correct |
7 ms |
2304 KB |
Output is correct |
32 |
Correct |
25 ms |
3748 KB |
Output is correct |
33 |
Correct |
26 ms |
3756 KB |
Output is correct |
34 |
Correct |
611 ms |
3892 KB |
Output is correct |
35 |
Correct |
218 ms |
3756 KB |
Output is correct |
36 |
Correct |
44 ms |
3800 KB |
Output is correct |
37 |
Correct |
50 ms |
3680 KB |
Output is correct |
38 |
Correct |
42 ms |
3568 KB |
Output is correct |
39 |
Correct |
52 ms |
3528 KB |
Output is correct |
40 |
Correct |
489 ms |
4096 KB |
Output is correct |
41 |
Correct |
132 ms |
3572 KB |
Output is correct |
42 |
Correct |
111 ms |
3528 KB |
Output is correct |
43 |
Correct |
44 ms |
3940 KB |
Output is correct |
44 |
Correct |
359 ms |
3784 KB |
Output is correct |
45 |
Correct |
236 ms |
28116 KB |
Output is correct |
46 |
Correct |
13 ms |
17104 KB |
Output is correct |
47 |
Correct |
13 ms |
17104 KB |
Output is correct |
48 |
Correct |
492 ms |
35400 KB |
Output is correct |
49 |
Correct |
259 ms |
35600 KB |
Output is correct |
50 |
Execution timed out |
4027 ms |
26128 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |