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 <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... |