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;
int sequence(int N, std::vector<int> A) {
#define int long long
int cnt[N+1], ans = 0;
for(int i = 0; i < N; i++) {
memset(cnt, 0, sizeof(cnt));
multiset<int> l, r;
for(int j = i; j < N; j++) {
cnt[A[j]]++;
if(r.empty() || A[j] <= *r.begin()) l.insert(A[j]);
else r.insert(A[j]);
if(l.size() > r.size()+1) {
r.insert(*--l.end());
l.erase(--l.end());
}
if(r.size() > l.size()) {
l.insert(*r.begin());
r.erase(r.begin());
}
if(l.size() == r.size()) {
ans = max(ans, cnt[*--l.end()]);
ans = max(ans, cnt[*r.begin()]);
} else {
ans = max(ans, cnt[*--l.end()]);
}
}
}
return ans;
#undef int
}
# | 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... |