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"
#include <bits/stdc++.h>
using namespace std;
int subtask = 0, n;
vector<array<int, 2>> prefix;
void init(int k, vector<int> r){
n = r.size();
if(k == 2) subtask = 1;
prefix.assign(n, array{0, 0});
if(r[0] == 0) prefix[0][0] = 1;
else if(r[0] == 1) prefix[0][1] = 1;
for(int i = 1; i < n; i++){
prefix[i] = prefix[i - 1];
if(r[i] == 0) prefix[i][0]++;
else if(r[i] == 1) prefix[i][1]++;
}
}
int compare_plants(int x, int y){
int cnt0 = prefix[y - 1][0] - (x != 0 ? prefix[x - 1][0] : 0);
int cnt1 = prefix[y - 1][1] - (x != 0 ? prefix[x - 1][1] : 0);
if(cnt0 == 0) return -1;
else if(cnt1 == 0) return 1;
cnt0 = prefix[n - 1][0] - cnt0;
cnt1 = prefix[n - 1][1] - cnt1;
if(cnt0 == 0) return 1;
else if(cnt1 == 0) return -1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |