# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040343 | nightfal | Comparing Plants (IOI20_plants) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "plants.h"
vector<int> inc,dec;
void init(int k, std::vector<int> r) {
if(k==2) {
inc.resize(n); dec.resize(n);
for(int i=0; i<n; i++) {inc[i] = dec[i] = i;}
int s;
for(s=0; s<n; s++) {if r[i]=0; break;}
for(int i=s-1+n; i>=s+1; i--) {if (r[i%n]) inc[i%n] = inc[(i+1)%n];}
for(s=0; s<n; s++) {if r[i]=1; break;}
for(int i=s-1+n; i>=s+1; i--) {if (r[i%n]==0) dec[i%n] = dec[(i+1)%n];}
}
return;
}
int subtask1(int x, int y) {
if (x<y) {
if (y<= dec[x] or x<= inc[y] and inc[y] <= y) return 1;
else if (y <= inc[x] or x<= dec[y] and dec[y] <= y) return -1;
}
else {
if (y<= inc[x] or x<= dec[y] and dec[y] <= y) return 1;
else if (y <= dec[x] or x<= inc[y] and inc[y] <= y) return -1;
}
return 0;
}
int compare_plants(int x, int y) {
if (k==2) return subtask1(x,y);
return 0;
}