#include <bits/stdc++.h>
using namespace std;
int c;
const int N = 500000;
int H[N];
void call(int i, int k, int n, vector<int> &r, vector<int> &h1)
{
for (int j = i - 1; j > i - k; j--)
{
int id = (j + n) % n;
if (r[id] == 0 && h1[id] == 0)
{
call(id, k, n, r, h1);
}
}
h1[i] = c--;
for (int j = i - 1; j > i - k; j--)
{
int id = (j + n) % n;
r[id]--;
}
}
void init(int k, vector<int> r)
{
int n = r.size();
vector<int> h1(n);
c = n;
int t = 1;
while (t)
{
t = 0;
for (int i = 0; i < n; i++)
{
if (r[i] == 0 && h1[i] == 0)
{
call(i, k, n, r, h1);
t = 1;
}
}
}
for (int i = 0; i < n; i++)
{
H[i] = h1[i];
}
}
int compare_plants(int x, int y)
{
if (H[x] > H[y]) return 1;
return -1;
}
#ifdef LOCAL
int main()
{
int n, k, q;
cin >> n >> k >> q;
vector<int> r(n);
for (int i = 0; i < n; i++) cin >> r[i];
init(k, r);
while (q--)
{
int x, y;
cin >> x >> y;
cout << compare_plants(x, y) << endl;
}
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
384 KB |
Output is correct |
7 |
Correct |
299 ms |
3320 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
384 KB |
Output is correct |
10 |
Correct |
294 ms |
3320 KB |
Output is correct |
11 |
Correct |
205 ms |
3192 KB |
Output is correct |
12 |
Correct |
227 ms |
3308 KB |
Output is correct |
13 |
Correct |
349 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
11 ms |
384 KB |
Output is correct |
7 |
Correct |
299 ms |
3320 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
384 KB |
Output is correct |
10 |
Correct |
294 ms |
3320 KB |
Output is correct |
11 |
Correct |
205 ms |
3192 KB |
Output is correct |
12 |
Correct |
227 ms |
3308 KB |
Output is correct |
13 |
Correct |
349 ms |
3308 KB |
Output is correct |
14 |
Correct |
2340 ms |
3452 KB |
Output is correct |
15 |
Execution timed out |
4059 ms |
4984 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
75 ms |
3192 KB |
Output is correct |
4 |
Execution timed out |
4053 ms |
8824 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |