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 <bits/stdc++.h>
#define rep(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
using namespace std;
int sequence(int N, vector<int> A) {
int MAX=0, ans=0;
rep(i,0,N) MAX=max(MAX,A[i]);
MAX+=5;
if(N*MAX>1e7) return 5;
int cont[MAX][N+1]{}, acum[MAX][N+1]{};
rep(k,1,MAX){
rep(i,1,N+1){
cont[k][i]=cont[k][i-1]+(A[i-1]==k);
acum[k][i]=cont[k][i]+acum[k-1][i];
}
}
rep(i,1,N+1){
rep(j,i,N+1){
rep(k,j-i,j-i+2){
int l=1, r=N, mid;
while(l<=r){
mid=(l+r)>>1;
if(acum[mid][j]-acum[mid][i-1]<k/2+1) l=mid+1;
else r=mid-1;
}
ans=max(ans,cont[l][j]-cont[l][i-1]);
}
}
}
return ans;
}
# | 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... |