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 "sequence.h"
#include <bits/stdc++.h>
#define SZ(s) ((int) ((s).size()))
using namespace std;
int sequence(int n, std::vector<int> a) {
int res = 0;
int ln = *max_element(a.begin(), a.end());
for (int median = 0; median <= ln; ++median) {
vector<int> cnt_less(n, 0);
vector<int> cnt_equal(n, 0);
vector<int> cnt_greater(n, 0);
for (int i = 0; i < n; ++i) {
cnt_less[i] = a[i] < median;
cnt_equal[i] = a[i] == median;
cnt_greater[i] = a[i] > median;
}
std::partial_sum(cnt_less.begin(), cnt_less.end(), cnt_less.begin());
std::partial_sum(cnt_equal.begin(), cnt_equal.end(), cnt_equal.begin());
std::partial_sum(cnt_greater.begin(), cnt_greater.end(), cnt_greater.begin());
auto f = [&] (int i) {
// +n to make sure result >= 0
if (i < 0) return 0+n;
return cnt_less[i] + cnt_equal[i] - cnt_greater[i] + n;
};
for (int l = 0; l < n; ++l) {
for (int r = l + 1; r < n; ++r) {
if (f(r) >= f(l-1)) {
int cnt = cnt_equal[r] - (l > 0 ? cnt_equal[l-1] : 0);
res = max(res, cnt);
}
}
}
}
return res;
}
# | 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... |