이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |