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>
using namespace std;
#define vec vector
int sequence(int N, std::vector<int> A) {
int ans = 0;
for(int i =0; i<N; i++) {
vec<int> cnt(N);
set<int> vals;
int lw = 0;
int hi = 0;
int med = A[i];
for(int j = i; j<N; j++) {
cnt[A[j]]++;
vals.insert(A[j]);
if(A[j] < med) {
lw++;
}
else {
hi++;
}
if(vals.upper_bound(med) != vals.end()) {
int hmed = *vals.upper_bound(med);
int lw2 = lw+cnt[med];
int hi2 = hi-cnt[hmed];
if(abs(lw2-hi2) < cnt[hmed]*2) {
ans = max(ans, cnt[hmed]);
med = hmed;
lw = lw2;
hi = hi2;
}
}
if(vals.find(med) != vals.begin()) {
auto it = vals.find(med);
it--;
int lmed = *it;
int lw2 = lw-cnt[lmed];
int hi2 = hi+cnt[med];
if(abs(lw2-hi2) < cnt[lmed]*2) {
ans = max(ans, cnt[lmed]);
med = lmed;
lw = lw2;
hi = hi2;
}
}
ans = max(ans, cnt[med]);
}
}
return ans;
}
# | 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... |