#include "game.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const int MAXN = (int)1e6 + 7;
const int LG = 60;
int dp[MAXN], pd[MAXN], flag;
vector<int> adj[MAXN][2];
bool seen[MAXN];
int N, K, X;
bool check(int x) {
if (dp[x] <= pd[x]) return 1;
return 0;
}
void init(int n, int k) {
N = n;
K = k;
for (int i=0; i<N; i++) dp[i] = pd[i] = -1;
}
void DFS(int v, bool b) {
seen[v] = 1;
if (b) dp[v] = (dp[v] == -1? X : min(dp[v], X));
else pd[v] = (pd[v] == -1? X : max(pd[v], X));
if (!flag && v >= K && dp[v] != -1 && pd[v] != -1 && dp[v] <= pd[v]) flag = 1;
for (int u:adj[v][b]) if (!seen[u]) DFS(u, b);
}
int add_teleporter(int u, int v) {
if (u < K && v < K) {
if (u >= v) return 1;
return 0;
}
adj[u][0].pb(v); adj[v][1].pb(u);
fill(seen, seen+N+1, 0);
if (u < K) {
X = u;
DFS(u, 0);
} else if (v < K) {
X = v;
DFS(v, 1);
} else {
X = pd[u];
DFS(u, 0);
}
// for (int i=K; i<N; i++) if (dp[i] != -1 && pd[i] != -1 && dp[i] <= pd[i]) return 1;
return flag;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
12 ms |
51700 KB |
Output is correct |
3 |
Correct |
12 ms |
51692 KB |
Output is correct |
4 |
Correct |
13 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51644 KB |
Output is correct |
6 |
Correct |
11 ms |
51544 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
12 ms |
51700 KB |
Output is correct |
3 |
Correct |
12 ms |
51692 KB |
Output is correct |
4 |
Correct |
13 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51644 KB |
Output is correct |
6 |
Correct |
11 ms |
51544 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
12 ms |
51544 KB |
Output is correct |
10 |
Correct |
11 ms |
51648 KB |
Output is correct |
11 |
Correct |
11 ms |
51736 KB |
Output is correct |
12 |
Correct |
11 ms |
51672 KB |
Output is correct |
13 |
Correct |
11 ms |
51544 KB |
Output is correct |
14 |
Correct |
11 ms |
51544 KB |
Output is correct |
15 |
Correct |
12 ms |
51720 KB |
Output is correct |
16 |
Correct |
11 ms |
51892 KB |
Output is correct |
17 |
Correct |
11 ms |
51544 KB |
Output is correct |
18 |
Correct |
11 ms |
51692 KB |
Output is correct |
19 |
Correct |
11 ms |
51544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
12 ms |
51700 KB |
Output is correct |
3 |
Correct |
12 ms |
51692 KB |
Output is correct |
4 |
Correct |
13 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51644 KB |
Output is correct |
6 |
Correct |
11 ms |
51544 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
12 ms |
51544 KB |
Output is correct |
10 |
Correct |
11 ms |
51648 KB |
Output is correct |
11 |
Correct |
11 ms |
51736 KB |
Output is correct |
12 |
Correct |
11 ms |
51672 KB |
Output is correct |
13 |
Correct |
11 ms |
51544 KB |
Output is correct |
14 |
Correct |
11 ms |
51544 KB |
Output is correct |
15 |
Correct |
12 ms |
51720 KB |
Output is correct |
16 |
Correct |
11 ms |
51892 KB |
Output is correct |
17 |
Correct |
11 ms |
51544 KB |
Output is correct |
18 |
Correct |
11 ms |
51692 KB |
Output is correct |
19 |
Correct |
11 ms |
51544 KB |
Output is correct |
20 |
Correct |
12 ms |
51544 KB |
Output is correct |
21 |
Correct |
12 ms |
51660 KB |
Output is correct |
22 |
Correct |
12 ms |
51800 KB |
Output is correct |
23 |
Correct |
11 ms |
51800 KB |
Output is correct |
24 |
Correct |
16 ms |
51800 KB |
Output is correct |
25 |
Correct |
18 ms |
52056 KB |
Output is correct |
26 |
Correct |
34 ms |
52060 KB |
Output is correct |
27 |
Correct |
22 ms |
51800 KB |
Output is correct |
28 |
Correct |
13 ms |
51544 KB |
Output is correct |
29 |
Correct |
13 ms |
51800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
12 ms |
51700 KB |
Output is correct |
3 |
Correct |
12 ms |
51692 KB |
Output is correct |
4 |
Correct |
13 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51644 KB |
Output is correct |
6 |
Correct |
11 ms |
51544 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
12 ms |
51544 KB |
Output is correct |
10 |
Correct |
11 ms |
51648 KB |
Output is correct |
11 |
Correct |
11 ms |
51736 KB |
Output is correct |
12 |
Correct |
11 ms |
51672 KB |
Output is correct |
13 |
Correct |
11 ms |
51544 KB |
Output is correct |
14 |
Correct |
11 ms |
51544 KB |
Output is correct |
15 |
Correct |
12 ms |
51720 KB |
Output is correct |
16 |
Correct |
11 ms |
51892 KB |
Output is correct |
17 |
Correct |
11 ms |
51544 KB |
Output is correct |
18 |
Correct |
11 ms |
51692 KB |
Output is correct |
19 |
Correct |
11 ms |
51544 KB |
Output is correct |
20 |
Correct |
12 ms |
51544 KB |
Output is correct |
21 |
Correct |
12 ms |
51660 KB |
Output is correct |
22 |
Correct |
12 ms |
51800 KB |
Output is correct |
23 |
Correct |
11 ms |
51800 KB |
Output is correct |
24 |
Correct |
16 ms |
51800 KB |
Output is correct |
25 |
Correct |
18 ms |
52056 KB |
Output is correct |
26 |
Correct |
34 ms |
52060 KB |
Output is correct |
27 |
Correct |
22 ms |
51800 KB |
Output is correct |
28 |
Correct |
13 ms |
51544 KB |
Output is correct |
29 |
Correct |
13 ms |
51800 KB |
Output is correct |
30 |
Correct |
44 ms |
53568 KB |
Output is correct |
31 |
Correct |
16 ms |
52312 KB |
Output is correct |
32 |
Correct |
51 ms |
53992 KB |
Output is correct |
33 |
Correct |
56 ms |
54428 KB |
Output is correct |
34 |
Correct |
1034 ms |
55200 KB |
Output is correct |
35 |
Correct |
973 ms |
54764 KB |
Output is correct |
36 |
Correct |
1701 ms |
54132 KB |
Output is correct |
37 |
Correct |
881 ms |
53940 KB |
Output is correct |
38 |
Correct |
988 ms |
53312 KB |
Output is correct |
39 |
Correct |
1394 ms |
53752 KB |
Output is correct |
40 |
Correct |
1012 ms |
55092 KB |
Output is correct |
41 |
Correct |
633 ms |
54824 KB |
Output is correct |
42 |
Correct |
283 ms |
54004 KB |
Output is correct |
43 |
Execution timed out |
4019 ms |
55460 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
51544 KB |
Output is correct |
2 |
Correct |
12 ms |
51700 KB |
Output is correct |
3 |
Correct |
12 ms |
51692 KB |
Output is correct |
4 |
Correct |
13 ms |
51544 KB |
Output is correct |
5 |
Correct |
11 ms |
51644 KB |
Output is correct |
6 |
Correct |
11 ms |
51544 KB |
Output is correct |
7 |
Correct |
11 ms |
51544 KB |
Output is correct |
8 |
Correct |
11 ms |
51544 KB |
Output is correct |
9 |
Correct |
12 ms |
51544 KB |
Output is correct |
10 |
Correct |
11 ms |
51648 KB |
Output is correct |
11 |
Correct |
11 ms |
51736 KB |
Output is correct |
12 |
Correct |
11 ms |
51672 KB |
Output is correct |
13 |
Correct |
11 ms |
51544 KB |
Output is correct |
14 |
Correct |
11 ms |
51544 KB |
Output is correct |
15 |
Correct |
12 ms |
51720 KB |
Output is correct |
16 |
Correct |
11 ms |
51892 KB |
Output is correct |
17 |
Correct |
11 ms |
51544 KB |
Output is correct |
18 |
Correct |
11 ms |
51692 KB |
Output is correct |
19 |
Correct |
11 ms |
51544 KB |
Output is correct |
20 |
Correct |
12 ms |
51544 KB |
Output is correct |
21 |
Correct |
12 ms |
51660 KB |
Output is correct |
22 |
Correct |
12 ms |
51800 KB |
Output is correct |
23 |
Correct |
11 ms |
51800 KB |
Output is correct |
24 |
Correct |
16 ms |
51800 KB |
Output is correct |
25 |
Correct |
18 ms |
52056 KB |
Output is correct |
26 |
Correct |
34 ms |
52060 KB |
Output is correct |
27 |
Correct |
22 ms |
51800 KB |
Output is correct |
28 |
Correct |
13 ms |
51544 KB |
Output is correct |
29 |
Correct |
13 ms |
51800 KB |
Output is correct |
30 |
Correct |
44 ms |
53568 KB |
Output is correct |
31 |
Correct |
16 ms |
52312 KB |
Output is correct |
32 |
Correct |
51 ms |
53992 KB |
Output is correct |
33 |
Correct |
56 ms |
54428 KB |
Output is correct |
34 |
Correct |
1034 ms |
55200 KB |
Output is correct |
35 |
Correct |
973 ms |
54764 KB |
Output is correct |
36 |
Correct |
1701 ms |
54132 KB |
Output is correct |
37 |
Correct |
881 ms |
53940 KB |
Output is correct |
38 |
Correct |
988 ms |
53312 KB |
Output is correct |
39 |
Correct |
1394 ms |
53752 KB |
Output is correct |
40 |
Correct |
1012 ms |
55092 KB |
Output is correct |
41 |
Correct |
633 ms |
54824 KB |
Output is correct |
42 |
Correct |
283 ms |
54004 KB |
Output is correct |
43 |
Execution timed out |
4019 ms |
55460 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |