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>
using namespace std;
int freq[2005][2005], freqsum[2005][2005];
int sequence(int n, vector<int> a)
{
for (int i=0; i<n; i++)
freq[i][a[i]]++;
for (int i=1; i<n; i++)
for (int j=1; j<=n; j++)
freq[i][j]+=freq[i-1][j];
for (int i=0; i<n; i++)
for (int j=1; j<=n; j++)
freqsum[i][j]=freqsum[i][j-1]+freq[i][j];
int ans=0;
for (int i=0; i<n; i++)
{
for (int j=i; j<n; j++)
{
int l=1, r=n;
while (l<r)
{
int mid=(l+r)/2;
if (freqsum[j][mid]-(i==0?0:freqsum[i-1][mid])>=(j-i+2)/2)
r=mid;
else
l=mid+1;
}
ans=max(ans, freq[j][l]-(i==0?0:freq[i-1][l]));
if (freqsum[j][l]-(i==0?0:freqsum[i-1][l])<(j-i+3)/2)
ans=max(ans, freq[j][l+1]-(i==0?0:freq[i-1][l+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... |