#include "sequence.h"
#include<bits/stdc++.h>
using namespace std;
#define vec vector
bool check(int cnt_med, int cnt_lw, int cnt_hi) {
return cnt_med >= 1 && cnt_hi <= cnt_med+cnt_lw && cnt_lw <= cnt_med+cnt_hi;
}
int sequence(int N, std::vector<int> A) {
int ans = 0;
for(int i =0; i<N; i++) {
vec<int> cnt(N);
set<int> vals;
int lw = 0;
int hi = 0;
int med = A[i];
for(int j = i; j<N; j++) {
cnt[A[j]]++;
vals.insert(A[j]);
if(A[j] < med) {
lw++;
}
else if(A[j] > med) {
hi++;
}
if(check(cnt[med], lw, hi)) ans = max(ans, cnt[med]);
if(vals.upper_bound(med) != vals.end()) {
int hmed = *vals.upper_bound(med);
int lw2 = lw+cnt[med];
int hi2 = hi-cnt[hmed];
if(check(cnt[hmed], lw2, hi2)) {
ans = max(ans, cnt[hmed]);
med = hmed;
lw = lw2;
hi = hi2;
}
}
if(vals.find(med) != vals.begin()) {
auto it = vals.find(med);
it--;
int lmed = *it;
int lw2 = lw-cnt[lmed];
int hi2 = hi+cnt[med];
if(check(cnt[lmed], lw2, hi2)) {
ans = max(ans, cnt[lmed]);
med = lmed;
lw = lw2;
hi = hi2;
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
2025 ms |
21176 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
2019 ms |
6220 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2045 ms |
29772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |