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 DEBUG if (1)
int sequence(int N, std::vector<int> A) {
int ans = 0;
for (int i = 0; i < N; i++) {
priority_queue<int> a;
priority_queue<int, vector<int>, greater<int>> b;
vector<int> cnt(N + 1, 0);
for (int j = i; j < N; j++) {
if (a.empty() && b.empty()) a.push(A[j]);
else if (a.empty() || (a.size() <= b.size())) {
if (A[j] <= b.top()) a.push(A[j]);
else {
a.push(b.top());
b.pop();
b.push(A[j]);
}
} else if (b.empty() || (a.size() > b.size())) {
if (A[j] >= a.top()) b.push(A[j]);
else {
b.push(a.top());
a.pop();
a.push(A[j]);
}
} else assert(false);
int median;
if (a.empty()) median = b.top();
else if (b.empty()) median = a.top();
else median = (a.top() + b.top()) / 2;
cnt[A[j]]++;
ans = max(ans, cnt[median]);
}
}
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... |