#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, k);
for (int i = 0; i < k; i++) {
s[i] = i;
e[i] = i;
}
}
int add(int u, int v) {
if (OO) {
cout << "add " << u << " " << v << '\n';
}
if (s[u] >= e[v]) return 1;
if (s[u] > s[v]) {
if (s[u] - s[v] >= e[v] - s[u]) {
if (OO) {
cout << "add " << u << " " << v << " updates forward\n";
}
s[v] = s[u];
for (const auto &i : g[v])
if (add(v, i)) return 1;
}
}
if (e[u] > e[v]) {
if (e[u] - e[v] >= e[v] - s[u]) {
if (OO) {
cout << "add " << u << " " << v << " updates backward\n";
}
e[u] = e[v];
for (const auto &i : grev[u])
if (add(i, u)) 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(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:83:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
83 | for (const auto &i : s) cout << i << " "; cout << '\n';
| ^~~
game.cpp:83:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
83 | for (const auto &i : s) cout << i << " "; cout << '\n';
| ^~~~
game.cpp:85:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
85 | for (const auto &i : e) cout << i << " "; cout << '\n';
| ^~~
game.cpp:85:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
85 | 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 |
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 |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer[1] |
19 |
Halted |
0 ms |
0 KB |
- |