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;
vector<vector<int>> cont(MAX), acum(MAX);
rep(i,0,N){
acum[0].pb(0);
cont[0].pb(0);
}
rep(k,1,MAX){
cont[k].pb(0);
acum[k].pb(0);
rep(i,1,N+1){
cont[k].pb(cont[k][i-1]+(A[i-1]==k));
acum[k].pb(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=MAX, 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... |