이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include <bits/stdc++.h>
// #include "grader.cpp"
using namespace std;
const int LIM=2e3+10;
int pre[LIM][LIM];
int a[LIM],n;
void compute_pre()
{
for(int i=1;i<=n;i++)
pre[0][i]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
pre[i][j]=pre[i-1][j]+(a[i-1]<=j);
}
}
}
int count_less(int l,int r,int x)
{
return pre[r+1][x]-pre[l][x];
}
int count(int l,int r,int x)
{
int tp=count_less(l,r,x)-count_less(l,r,x-1);
// if(tp==4)
// cout<<"FOR "<<l<<' '<<r<<' '<<x<<endl;
return tp;
}
int sequence(int NP, std::vector<int> AP) {
if(NP<LIM)
{
n=NP;
for(int j=0;j<n;j++)
a[j]=AP[j];
compute_pre();
int ans=1;
for(int l=0;l<n;l++)
{
for(int r=l+1;r<n;r++)
{
int s=0;
int e=n+1;
int len=(r-l+1);
int flooor=(len-1)/2;
/*
if len is even
then there are two medain = floor((len-1)/2) and ceil((len-1)/2)
else if len is odd
single medain
*/
while(s+1<e)
{
int mid=(s+e)/2;
if(count_less(l,r,mid)<=flooor)
{
s=mid;
}
else{
e=mid;
}
}
ans=max(ans,count(l,r,e));
if(len%2==0)
{
int ceill=flooor+1;
s=0;
e=n+1;
while(s+1<e)
{
int mid=(s+e)/2;
if(count_less(l,r,mid)<=ceill)
{
s=mid;
}
else{
e=mid;
}
}
ans=max(ans,count(l,r,e));
}
}
}
return ans;
// cout<<ans<<endl;
}
return 0;
}
# | 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... |