이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]));
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+3)/2)
r=mid;
else
l=mid+1;
}
ans=max(ans, freq[j][l]-(i==0?0:freq[i-1][l]));
}
}
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... |