이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int sequence(int N, vector<int> A) {
int maxOccurrences = 0;
// Frequency array to count occurrences of each number
vector<int> freq(N + 1, 0);
// Iterate over each possible starting point of subarray
for (int l = 0; l < N; ++l) {
fill(freq.begin(), freq.end(), 0); // Reset frequency array for each new starting point
vector<int> subarray;
// Iterate over each possible ending point of subarray starting from 'l'
for (int r = l; r < N; ++r) {
subarray.push_back(A[r]);
freq[A[r]]++;
// Sort the current subarray to find medians
vector<int> temp = subarray;
sort(temp.begin(), temp.end());
int k = temp.size();
int median1 = temp[(k - 1) / 2];
int median2 = temp[k / 2];
maxOccurrences = max(maxOccurrences, freq[median1]);
if (median1 != median2) {
maxOccurrences = max(maxOccurrences, freq[median2]);
}
}
}
return maxOccurrences;
}
# | 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... |