#include "game.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
const int MAXN = 300005;
vector<int> G[MAXN], rG[MAXN];
pii itv[MAXN];
int done, K;
void dfs(int u, int nw) {
itv[u].Y = max(itv[u].Y, nw);
if (itv[u].X <= itv[u].Y)
done = 1;
for (int i : G[u])
if (itv[i].Y < nw)
dfs(i, nw);
}
void rdfs(int u, int nw) {
itv[u].X = min(itv[u].X, nw);
if (itv[u].X <= itv[u].Y)
done = 1;
for (int i : rG[u])
if (itv[i].X > nw)
rdfs(i, nw);
}
void init(int n, int k) {
K = k;
for (int i = 0; i < n; ++i)
G[i].clear(), rG[i].clear();
for (int i = 0; i < k; ++i)
itv[i] = pii(i, i);
for (int i = k; i < n; ++i)
itv[i] = pii(n, -1);
done = 0;
}
int add_teleporter(int u, int v) {
if (done) return 1;
if (u < K && v < K) {
if (u >= v)
return done = 1;
return 0;
}
if (u < K) {
if (u <= itv[v].Y) return 0;
dfs(v, u);
}
else if (v < K) {
if (v >= itv[u].X) return 0;
rdfs(u, v);
}
else {
G[u].pb(v);
rG[v].pb(u);
if (itv[u].Y > itv[v].Y)
dfs(v, itv[u].Y);
if (itv[v].X < itv[u].X)
rdfs(u, itv[v].X);
}
return done;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14288 KB |
Output is correct |
7 |
Correct |
8 ms |
14288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14288 KB |
Output is correct |
7 |
Correct |
8 ms |
14288 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
10 ms |
14288 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
10 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
7 ms |
14288 KB |
Output is correct |
19 |
Correct |
10 ms |
14288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14288 KB |
Output is correct |
7 |
Correct |
8 ms |
14288 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
10 ms |
14288 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
10 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
7 ms |
14288 KB |
Output is correct |
19 |
Correct |
10 ms |
14288 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14288 KB |
Output is correct |
22 |
Correct |
8 ms |
14424 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
12 ms |
14400 KB |
Output is correct |
25 |
Correct |
11 ms |
14392 KB |
Output is correct |
26 |
Correct |
12 ms |
14504 KB |
Output is correct |
27 |
Correct |
11 ms |
14416 KB |
Output is correct |
28 |
Correct |
8 ms |
14404 KB |
Output is correct |
29 |
Correct |
9 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14288 KB |
Output is correct |
7 |
Correct |
8 ms |
14288 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
10 ms |
14288 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
10 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
7 ms |
14288 KB |
Output is correct |
19 |
Correct |
10 ms |
14288 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14288 KB |
Output is correct |
22 |
Correct |
8 ms |
14424 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
12 ms |
14400 KB |
Output is correct |
25 |
Correct |
11 ms |
14392 KB |
Output is correct |
26 |
Correct |
12 ms |
14504 KB |
Output is correct |
27 |
Correct |
11 ms |
14416 KB |
Output is correct |
28 |
Correct |
8 ms |
14404 KB |
Output is correct |
29 |
Correct |
9 ms |
14416 KB |
Output is correct |
30 |
Correct |
22 ms |
15636 KB |
Output is correct |
31 |
Correct |
12 ms |
14928 KB |
Output is correct |
32 |
Correct |
37 ms |
17096 KB |
Output is correct |
33 |
Correct |
28 ms |
16500 KB |
Output is correct |
34 |
Correct |
1080 ms |
17716 KB |
Output is correct |
35 |
Correct |
375 ms |
16772 KB |
Output is correct |
36 |
Correct |
53 ms |
16448 KB |
Output is correct |
37 |
Correct |
44 ms |
16464 KB |
Output is correct |
38 |
Correct |
28 ms |
16072 KB |
Output is correct |
39 |
Correct |
30 ms |
15960 KB |
Output is correct |
40 |
Correct |
848 ms |
17588 KB |
Output is correct |
41 |
Correct |
171 ms |
16448 KB |
Output is correct |
42 |
Correct |
131 ms |
16388 KB |
Output is correct |
43 |
Correct |
48 ms |
17736 KB |
Output is correct |
44 |
Correct |
793 ms |
17708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14288 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
7 ms |
14288 KB |
Output is correct |
6 |
Correct |
7 ms |
14288 KB |
Output is correct |
7 |
Correct |
8 ms |
14288 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
10 ms |
14288 KB |
Output is correct |
12 |
Correct |
9 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14288 KB |
Output is correct |
14 |
Correct |
10 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14288 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
7 ms |
14288 KB |
Output is correct |
19 |
Correct |
10 ms |
14288 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
7 ms |
14288 KB |
Output is correct |
22 |
Correct |
8 ms |
14424 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
12 ms |
14400 KB |
Output is correct |
25 |
Correct |
11 ms |
14392 KB |
Output is correct |
26 |
Correct |
12 ms |
14504 KB |
Output is correct |
27 |
Correct |
11 ms |
14416 KB |
Output is correct |
28 |
Correct |
8 ms |
14404 KB |
Output is correct |
29 |
Correct |
9 ms |
14416 KB |
Output is correct |
30 |
Correct |
22 ms |
15636 KB |
Output is correct |
31 |
Correct |
12 ms |
14928 KB |
Output is correct |
32 |
Correct |
37 ms |
17096 KB |
Output is correct |
33 |
Correct |
28 ms |
16500 KB |
Output is correct |
34 |
Correct |
1080 ms |
17716 KB |
Output is correct |
35 |
Correct |
375 ms |
16772 KB |
Output is correct |
36 |
Correct |
53 ms |
16448 KB |
Output is correct |
37 |
Correct |
44 ms |
16464 KB |
Output is correct |
38 |
Correct |
28 ms |
16072 KB |
Output is correct |
39 |
Correct |
30 ms |
15960 KB |
Output is correct |
40 |
Correct |
848 ms |
17588 KB |
Output is correct |
41 |
Correct |
171 ms |
16448 KB |
Output is correct |
42 |
Correct |
131 ms |
16388 KB |
Output is correct |
43 |
Correct |
48 ms |
17736 KB |
Output is correct |
44 |
Correct |
793 ms |
17708 KB |
Output is correct |
45 |
Correct |
251 ms |
28060 KB |
Output is correct |
46 |
Correct |
18 ms |
17084 KB |
Output is correct |
47 |
Correct |
12 ms |
17104 KB |
Output is correct |
48 |
Correct |
357 ms |
42644 KB |
Output is correct |
49 |
Correct |
278 ms |
35400 KB |
Output is correct |
50 |
Execution timed out |
4067 ms |
33044 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |