# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
577388 |
2022-06-14T17:15:38 Z |
Noam527 |
Game (APIO22_game) |
C++17 |
|
4000 ms |
43576 KB |
#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
// e <= s, except for initial state
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;
}
}
void forward_dfs(int l, int m, int r, int v, int reach) {
if (OO) {
cout << "forward: v, e, s = " << v << " " << e[v] << " " << s[v] << '\n';
}
if (!(l <= e[v] && s[v] < m)) return;
s[v] = reach;
for (const auto &i : g[v]) {
forward_dfs(l, m, r, i, reach);
}
}
void backward_dfs(int l, int m, int r, int v, int reach) {
if (OO) {
cout << "backward: v, e, s = " << v << " " << e[v] << " " << s[v] << '\n';
}
if (!(m < e[v] && s[v] <= r)) return;
e[v] = reach;
for (const auto &i : grev[v]) {
backward_dfs(l, m, r, i, reach);
}
}
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] >= m && e[v] <= m) return 1;
if (s[u] >= m)
forward_dfs(l, m, r, v, m);
if (e[v] <= m)
backward_dfs(l, m, r, u, m);
if (s[u] > m || e[v] > m) {
if (add(layer + 1, m + 1, r, u, v)) return 1;
}
if (s[u] < m || 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:98:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
98 | for (const auto &i : s) cout << i << " "; cout << '\n';
| ^~~
game.cpp:98:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
98 | for (const auto &i : s) cout << i << " "; cout << '\n';
| ^~~~
game.cpp:100:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
100 | for (const auto &i : e) cout << i << " "; cout << '\n';
| ^~~
game.cpp:100:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
100 | for (const auto &i : e) cout << i << " "; cout << '\n';
| ^~~~
# |
Verdict |
Execution time |
Memory |
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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
7 ms |
424 KB |
Output is correct |
25 |
Correct |
6 ms |
380 KB |
Output is correct |
26 |
Correct |
4 ms |
432 KB |
Output is correct |
27 |
Correct |
8 ms |
336 KB |
Output is correct |
28 |
Correct |
4 ms |
364 KB |
Output is correct |
29 |
Correct |
9 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
7 ms |
424 KB |
Output is correct |
25 |
Correct |
6 ms |
380 KB |
Output is correct |
26 |
Correct |
4 ms |
432 KB |
Output is correct |
27 |
Correct |
8 ms |
336 KB |
Output is correct |
28 |
Correct |
4 ms |
364 KB |
Output is correct |
29 |
Correct |
9 ms |
428 KB |
Output is correct |
30 |
Correct |
42 ms |
3020 KB |
Output is correct |
31 |
Correct |
42 ms |
2248 KB |
Output is correct |
32 |
Correct |
48 ms |
4676 KB |
Output is correct |
33 |
Correct |
17 ms |
3784 KB |
Output is correct |
34 |
Correct |
1408 ms |
5796 KB |
Output is correct |
35 |
Correct |
531 ms |
4480 KB |
Output is correct |
36 |
Correct |
75 ms |
3836 KB |
Output is correct |
37 |
Correct |
182 ms |
3796 KB |
Output is correct |
38 |
Correct |
172 ms |
3672 KB |
Output is correct |
39 |
Correct |
255 ms |
3628 KB |
Output is correct |
40 |
Correct |
1254 ms |
5704 KB |
Output is correct |
41 |
Correct |
359 ms |
4024 KB |
Output is correct |
42 |
Correct |
349 ms |
3892 KB |
Output is correct |
43 |
Correct |
186 ms |
4844 KB |
Output is correct |
44 |
Correct |
1243 ms |
5620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
360 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
7 ms |
424 KB |
Output is correct |
25 |
Correct |
6 ms |
380 KB |
Output is correct |
26 |
Correct |
4 ms |
432 KB |
Output is correct |
27 |
Correct |
8 ms |
336 KB |
Output is correct |
28 |
Correct |
4 ms |
364 KB |
Output is correct |
29 |
Correct |
9 ms |
428 KB |
Output is correct |
30 |
Correct |
42 ms |
3020 KB |
Output is correct |
31 |
Correct |
42 ms |
2248 KB |
Output is correct |
32 |
Correct |
48 ms |
4676 KB |
Output is correct |
33 |
Correct |
17 ms |
3784 KB |
Output is correct |
34 |
Correct |
1408 ms |
5796 KB |
Output is correct |
35 |
Correct |
531 ms |
4480 KB |
Output is correct |
36 |
Correct |
75 ms |
3836 KB |
Output is correct |
37 |
Correct |
182 ms |
3796 KB |
Output is correct |
38 |
Correct |
172 ms |
3672 KB |
Output is correct |
39 |
Correct |
255 ms |
3628 KB |
Output is correct |
40 |
Correct |
1254 ms |
5704 KB |
Output is correct |
41 |
Correct |
359 ms |
4024 KB |
Output is correct |
42 |
Correct |
349 ms |
3892 KB |
Output is correct |
43 |
Correct |
186 ms |
4844 KB |
Output is correct |
44 |
Correct |
1243 ms |
5620 KB |
Output is correct |
45 |
Correct |
392 ms |
28052 KB |
Output is correct |
46 |
Correct |
49 ms |
17296 KB |
Output is correct |
47 |
Correct |
76 ms |
17084 KB |
Output is correct |
48 |
Correct |
658 ms |
43576 KB |
Output is correct |
49 |
Correct |
425 ms |
35536 KB |
Output is correct |
50 |
Execution timed out |
4067 ms |
17116 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |