#include <vector>
#include <iostream>
#include <cstring>
int Count(int* arr, int len, int var) {
int out = 0;
for (int i = 0; i < len; ++i) {
if (arr[i] == var) {
++out; } }
return out; }
int getMedianCount(int* arr, int len, int* sortedArrH) {
memcpy(sortedArrH, arr, len * sizeof(int));
std::qsort(sortedArrH, len, sizeof(int), [](const void* x, const void* y) { if (*(int*)x > *(int*)y) return 1; return 0; });
if (len % 2 == 1) {
return Count(sortedArrH, len, sortedArrH[len / 2]); }
else {
int M1 = Count(sortedArrH, len, sortedArrH[len / 2]);
int M2 = Count(sortedArrH, len, sortedArrH[len / 2 - 1]);
return std::max(M1, M2); } }
int sequence(int N, std::vector<int> A) {
int* arr = A.data();
int* sortedArrH = new int[N];
int LM = getMedianCount(arr, N, sortedArrH);
/*for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N + 1; ++j) { // array is i include j exclude
int LMH = getMedianCount(&arr[i], j - i, sortedArrH);
if (LMH > LM) {
LM = LMH; } } }*/
delete[] sortedArrH;
return LM; }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
58 ms |
8024 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
8020 KB |
Output is correct |
2 |
Correct |
95 ms |
11360 KB |
Output is correct |
3 |
Incorrect |
110 ms |
11344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |