#include"sequence.h"
#include<vector>
#include<iostream>
using namespace std;
int n;
int arr2[500000];
int tree[500001];
vector<int>arr[500000];
int sequence(int N,vector<int>A){
n=N;
for(int i=0;i<n;i++){
arr[A[i]-1].push_back(i);
arr2[i]=A[i]-1;
}
for(int i=0;i<=n;i++)
tree[i]=-i;
int res=0,res2=0;
for(int v=0;v<n;v++){
for(int idx=0;idx<(int)arr[v].size();idx++){
for(int i=arr[v][idx]+1;i<=n;i++)
tree[i]+=2;
int min2=1e9;
int max2=-1e9;
for(int i=arr[v][idx]+1;i<=n;i++){
int sum=tree[i];
min2=min(min2,sum);
max2=max(max2,sum);
}
int min1=1e9;
int max1=-1e9;
for(int i=0;i<=arr[v][idx];i++){
int sum=tree[i];
min1=min(min1,sum);
max1=max(max1,sum);
//cout<<min1<<" "<<max1<<", "<<min2<<" "<<max2<<"\n";
if(max1<min2-1||max2<min1)
continue;
int i2=0;
while(arr[v][i2]<i)
i2++;
res=max(res,idx-i2+1);
break;
}
for(int i=0;i<n;i++){
int num=0;
for(int j=i;j<n;j++){
if(arr2[j]==v)
num++;
int sum=tree[j+1]-tree[i];
if(sum==0||sum==1)
res2=max(res2,num);
}
}
}
}
return res2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15136 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
4 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
5 ms |
14936 KB |
Output is correct |
7 |
Correct |
5 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14936 KB |
Output is correct |
9 |
Correct |
5 ms |
14936 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
6 ms |
15192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15136 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
4 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
5 ms |
14936 KB |
Output is correct |
7 |
Correct |
5 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14936 KB |
Output is correct |
9 |
Correct |
5 ms |
14936 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
6 ms |
15192 KB |
Output is correct |
13 |
Execution timed out |
2039 ms |
14936 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15136 KB |
Output is correct |
2 |
Execution timed out |
2094 ms |
29740 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Execution timed out |
2013 ms |
23040 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2031 ms |
35448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15136 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
4 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
5 ms |
14936 KB |
Output is correct |
7 |
Correct |
5 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14936 KB |
Output is correct |
9 |
Correct |
5 ms |
14936 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
6 ms |
15192 KB |
Output is correct |
13 |
Execution timed out |
2039 ms |
14936 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15136 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
4 ms |
14936 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
5 ms |
14936 KB |
Output is correct |
7 |
Correct |
5 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14936 KB |
Output is correct |
9 |
Correct |
5 ms |
14936 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
6 ms |
15192 KB |
Output is correct |
13 |
Execution timed out |
2039 ms |
14936 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |