#include <bits/stdc++.h>
#include "sequence.h"
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
int sequence(int n, vector<int> a)
{
int peak = 0;
while(peak+1<n&&a[peak]<=a[peak+1])
peak++;
int res = 1, l = 0, r;
for(int i = 1;i<n;i++)
if(a[i]!=a[i-1])
l=i;
else
res=max(res,i-l+1);
l = r = peak;
while(l>0&&a[l-1]==a[l])
l--;
while(r<n-1&&a[r+1]==a[r])
r++;
while(l>0&&r<n-1)
{
if(a[l]>a[r])
l--;
else if(a[l]<a[r])
r++;
else
l--,
r++;
int c1 = 1, c2 = 1;
while(l>0&&a[l-1]==a[l])
c1++,
l--;
while(r<n-1&&a[r+1]==a[r])
c2++,
r++;
if(a[l]==a[r])
{
int mi = l+(n-r-1), cur = c1+c2, mx = n-mi-cur;
if(abs(mi-mx)<=cur)
res=max(res,cur);
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
56 ms |
4208 KB |
Output is correct |
3 |
Incorrect |
55 ms |
4172 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
4164 KB |
Output is correct |
2 |
Correct |
56 ms |
4168 KB |
Output is correct |
3 |
Incorrect |
64 ms |
4168 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |