#include "game.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adjchart;
int K, N;
bool cycledetector4000(int i, int oi, bool f, vector<bool>& q, vector<bool>& dpcache){
if (!f && i == oi){
return true;
}
if (q[i]){
return dpcache[i];
}
bool pl = false;
q[i] = true;
for (int j : adjchart[i]){
pl |= cycledetector4000(j, oi, false, q, dpcache);
}
return dpcache[i] = pl;
}
void init(int n, int k) {
adjchart.resize(n + 10);
K = k;
N = n;
for (int i = 0; i < k - 1; ++i){
adjchart[i].push_back(i + 1);
}
}
int add_teleporter(int u, int v) {
adjchart[u].push_back(v);
vector<bool> q(N);
vector<bool> dpcache(N);
bool pl = false;
for (int i = K - 1; i >= 0; --i){
pl |= cycledetector4000(i, i, true, q, dpcache);
}
if (pl){
return 1;
}
return 0;
}
int balls() {
int n, k, m;
cin >> n >> k >> m;
init(n, k);
for (int i = 0; i < m; ++i){
int a, b;
cin >> a >> b;
cout << add_teleporter(a, b) << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
252 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 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 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 |
1 ms |
252 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 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
11 ms |
356 KB |
Output is correct |
25 |
Correct |
59 ms |
352 KB |
Output is correct |
26 |
Correct |
74 ms |
336 KB |
Output is correct |
27 |
Correct |
89 ms |
340 KB |
Output is correct |
28 |
Correct |
23 ms |
340 KB |
Output is correct |
29 |
Correct |
65 ms |
464 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 |
1 ms |
252 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 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
11 ms |
356 KB |
Output is correct |
25 |
Correct |
59 ms |
352 KB |
Output is correct |
26 |
Correct |
74 ms |
336 KB |
Output is correct |
27 |
Correct |
89 ms |
340 KB |
Output is correct |
28 |
Correct |
23 ms |
340 KB |
Output is correct |
29 |
Correct |
65 ms |
464 KB |
Output is correct |
30 |
Correct |
202 ms |
1516 KB |
Output is correct |
31 |
Correct |
102 ms |
1224 KB |
Output is correct |
32 |
Correct |
70 ms |
3148 KB |
Output is correct |
33 |
Correct |
41 ms |
1944 KB |
Output is correct |
34 |
Correct |
1427 ms |
4288 KB |
Output is correct |
35 |
Execution timed out |
4029 ms |
1784 KB |
Time limit exceeded |
36 |
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 |
1 ms |
252 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 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
11 ms |
356 KB |
Output is correct |
25 |
Correct |
59 ms |
352 KB |
Output is correct |
26 |
Correct |
74 ms |
336 KB |
Output is correct |
27 |
Correct |
89 ms |
340 KB |
Output is correct |
28 |
Correct |
23 ms |
340 KB |
Output is correct |
29 |
Correct |
65 ms |
464 KB |
Output is correct |
30 |
Correct |
202 ms |
1516 KB |
Output is correct |
31 |
Correct |
102 ms |
1224 KB |
Output is correct |
32 |
Correct |
70 ms |
3148 KB |
Output is correct |
33 |
Correct |
41 ms |
1944 KB |
Output is correct |
34 |
Correct |
1427 ms |
4288 KB |
Output is correct |
35 |
Execution timed out |
4029 ms |
1784 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |