이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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());
for (int l = 0; l < n; ++l) {
for (int r = l + 1; r < n; ++r) {
int less = cnt_less[r] - (l == 0 ? 0 : cnt_less[l-1]);
int equal = cnt_equal[r] - (l == 0 ? 0 : cnt_equal[l-1]);
int greater = cnt_greater[r] - (l == 0 ? 0 : cnt_greater[l-1]);
if (less + equal >= greater && less < equal + greater) {
res = max(res, equal);
}
}
}
}
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... |