#include "plants.h"
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N = 2e5 + 10;
int n , k , f[2][N];
vector <int> a;
void init(int kk, vector<int> r) {
a = r;
k = kk;
n = r.size();
f[0][n - 1] = -1;
f[1][n - 1] = -1;
f[a[n - 1]][n - 1] = n - 1;
for(int i = n - 2 ; i >= 0 ; i--)
{
f[0][i] = f[0][i + 1];
f[1][i] = f[1][i + 1];
f[a[i]][i] = i;
}
for(int i = n - 1 ; i >= 0 ; i--)
{
if(f[0][i] == -1)
f[0][i] = f[0][0];
if(f[1][i] == -1)
f[1][i] = f[1][0];
}
return;
}
int compare_plants(int x, int y) {
int res = 1;
if(x > y)
{
swap(x , y);
res = -1;
}
int ans = 0;
if(f[0][x] >= y || f[0][x] < x)
{
ans = res * -1;
}
else if(f[1][x] >= y || f[1][x] < x)
{
ans = res;
}
else if(f[0][y] >= x && f[0][y] < y)
{
ans = res;
}
else if(f[1][y] >= x && f[1][y] < y)
ans = res * -1;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
26 ms |
3068 KB |
Output is correct |
7 |
Correct |
30 ms |
3412 KB |
Output is correct |
8 |
Correct |
39 ms |
6484 KB |
Output is correct |
9 |
Correct |
38 ms |
6652 KB |
Output is correct |
10 |
Correct |
38 ms |
6492 KB |
Output is correct |
11 |
Correct |
40 ms |
6484 KB |
Output is correct |
12 |
Correct |
40 ms |
6480 KB |
Output is correct |
13 |
Correct |
37 ms |
6488 KB |
Output is correct |
14 |
Correct |
38 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
420 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
26 ms |
3068 KB |
Output is correct |
7 |
Correct |
30 ms |
3412 KB |
Output is correct |
8 |
Correct |
39 ms |
6484 KB |
Output is correct |
9 |
Correct |
38 ms |
6652 KB |
Output is correct |
10 |
Correct |
38 ms |
6492 KB |
Output is correct |
11 |
Correct |
40 ms |
6484 KB |
Output is correct |
12 |
Correct |
40 ms |
6480 KB |
Output is correct |
13 |
Correct |
37 ms |
6488 KB |
Output is correct |
14 |
Correct |
38 ms |
6484 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |