#include "sequence.h"
#include<bits/stdc++.h>
#include <vector>
using namespace std;
const int N=5e5+5;
int T[N];
int sequence(int N, std::vector<int> A) {
int sn, pn, ans;
if(N<=2000){
for(int i=0; i<=N; i++){
T[i]=0;
}
ans=1;
for(int i=0; i<N; i++){
multiset< int > S, P;
multiset< int > :: iterator it, ip;
sn=1;
pn=0;
S.insert(A[i]);
T[A[i]]++;
for(int j=i+1; j<N; j++){
T[A[j]]++;
if(pn==0){
P.insert(A[j]);
pn++;
it=S.begin();
ans=max(ans, max(T[A[j]], T[*it]));
}
else{
it=S.end();
it--;
if((*it)>=A[j]){
S.insert(A[j]);
sn++;
}
else{
P.insert(A[j]);
pn++;
}
if(sn>=pn+2){
it=S.begin();
P.insert(*it);
S.erase(it);
}
if(pn>=sn+2){
it=P.begin();
S.insert(*it);
P.erase(it);
}
it=S.end();
it--;
ip=P.begin();
if((sn+pn)%2==0){
ans=max(ans, max(T[*it], T[*ip]));
}
else{
ans=max(ans, T[*it]);
}
}
}
for(int j=i; j<N; j++){
T[A[j]]=0;
}
}
return ans;
}
}
Compilation message
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
72 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
2043 ms |
10580 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
33 ms |
13404 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
42 ms |
15700 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |