#include "game.h"
#include <bits/stdc++.h>
#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 62)
#define INF32 (1 << 30)
#define mset multiset
#define uset unordered_set
#define umap unordered_map
#define pqueue priority_queue
#define ptr(A) shared_ptr<A>
using namespace std;
vector<vector<int>> adj;
vector<vector<int>> inv_adj;
vector<int> source;
vector<int> destiny;
int K, N;
bool isCycled = 0;
void init(int n, int k) {
adj.resize(n);
inv_adj.resize(n);
destiny.resize(n, INF32);
source.resize(n, -1);
K = k;
N = n;
range(i, 0, k) {
if (i < k-1) {
adj[i].push_back(i+1);
inv_adj[i+1].push_back(i);
}
if (i)
source[i] = i-1;
if (i < k-1)
destiny[i] = i+1;
}
}
void furthest_source (int i, int& x) {
if (x <= source[i])
return;
source[i] = x;
if (source[i] >= destiny[i]) {
isCycled = 1;
return;
}
for (int& it : adj[i])
furthest_source(it, x);
}
void nearest_destiny(int i, int& x) {
if (x >= destiny[i])
return;
destiny[i] = x;
if (source[i] >= destiny[i]) {
isCycled = 1;
return;
}
for (int& it : inv_adj[i])
nearest_destiny(it, x);
}
int add_teleporter(int u, int v) {
adj[u].push_back(v);
inv_adj[v].push_back(u);
if (u == v && u < K)
return 1;
if (u < K)
furthest_source(v, u);
furthest_source(v, source[u]);
if (isCycled)
return 1;
if (v < K)
nearest_destiny(u, v);
nearest_destiny(u, destiny[v]);
if (isCycled)
return 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
500 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
500 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
500 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
14 ms |
3624 KB |
Output is correct |
31 |
Correct |
4 ms |
2392 KB |
Output is correct |
32 |
Correct |
19 ms |
4576 KB |
Output is correct |
33 |
Correct |
18 ms |
4600 KB |
Output is correct |
34 |
Correct |
882 ms |
5180 KB |
Output is correct |
35 |
Correct |
311 ms |
4952 KB |
Output is correct |
36 |
Correct |
35 ms |
4388 KB |
Output is correct |
37 |
Correct |
27 ms |
4420 KB |
Output is correct |
38 |
Correct |
31 ms |
4420 KB |
Output is correct |
39 |
Correct |
32 ms |
4576 KB |
Output is correct |
40 |
Correct |
730 ms |
5416 KB |
Output is correct |
41 |
Correct |
139 ms |
4612 KB |
Output is correct |
42 |
Correct |
94 ms |
4212 KB |
Output is correct |
43 |
Correct |
29 ms |
4952 KB |
Output is correct |
44 |
Correct |
632 ms |
5464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
500 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
14 ms |
3624 KB |
Output is correct |
31 |
Correct |
4 ms |
2392 KB |
Output is correct |
32 |
Correct |
19 ms |
4576 KB |
Output is correct |
33 |
Correct |
18 ms |
4600 KB |
Output is correct |
34 |
Correct |
882 ms |
5180 KB |
Output is correct |
35 |
Correct |
311 ms |
4952 KB |
Output is correct |
36 |
Correct |
35 ms |
4388 KB |
Output is correct |
37 |
Correct |
27 ms |
4420 KB |
Output is correct |
38 |
Correct |
31 ms |
4420 KB |
Output is correct |
39 |
Correct |
32 ms |
4576 KB |
Output is correct |
40 |
Correct |
730 ms |
5416 KB |
Output is correct |
41 |
Correct |
139 ms |
4612 KB |
Output is correct |
42 |
Correct |
94 ms |
4212 KB |
Output is correct |
43 |
Correct |
29 ms |
4952 KB |
Output is correct |
44 |
Correct |
632 ms |
5464 KB |
Output is correct |
45 |
Correct |
203 ms |
29052 KB |
Output is correct |
46 |
Correct |
12 ms |
17500 KB |
Output is correct |
47 |
Correct |
9 ms |
17260 KB |
Output is correct |
48 |
Correct |
277 ms |
39732 KB |
Output is correct |
49 |
Correct |
240 ms |
36288 KB |
Output is correct |
50 |
Execution timed out |
4090 ms |
40516 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |