이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include <vector>
#include <unordered_map>
int sequence(int N, std::vector<int> A) {
int max_median_count = 0;
// Iterate through all subarrays
for (int l = 0; l < N; ++l) {
std::unordered_map<int, int> count;
for (int r = l; r < N; ++r) {
// Update count for the current element
count[A[r]]++;
int num = A[r];
// Check if the current element can be a median (early termination)
if (count[num] <= max_median_count) {
continue;
}
int half_length = (r - l + 1) / 2;
if (count[num] >= half_length && count[num] <= half_length + 1) {
max_median_count = std::max(max_median_count, count[num]);
}
}
}
return max_median_count;
}
# | 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... |