记录编号 |
216927 |
评测结果 |
AAAAAAAAAAAAAAA |
题目名称 |
乐曲主题 |
最终得分 |
100 |
用户昵称 |
一個人的雨 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.010 s |
提交时间 |
2016-01-01 16:22:22 |
内存使用 |
3.37 MiB |
显示代码纯文本
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100000+10;
int n,Ws[maxn],wv[maxn],wa[maxn],wb[maxn];
int a[maxn],height[maxn],sa[maxn],rank[maxn];
char ch;
int read(){
int num=0; ch=getchar();
while (ch<'!') ch=getchar();
while (ch>='0'&&ch<='9'){num=num*10+ch-'0';ch=getchar();}
return num;
}
bool cmp(int *r,int a,int b,int l){
return r[a]==r[b]&&r[a+l]==r[b+l];
}
void da(int *r,int *sa,int n,int m){
int i,j,p,*x=wa,*y=wb,*t;
for (i=0;i<m;++i) Ws[i]=0;
for (i=0;i<n;++i) Ws[x[i]=r[i]]++;
for (i=1;i<m;++i) Ws[i]+=Ws[i-1];
for (i=n-1;i>=0;--i) sa[--Ws[x[i]]]=i;
for (j=1,p=1;p<n;j<<=1,m=p){
for (p=0,i=n-j;i<n;++i) y[p++]=i;
for (i=0;i<n;++i) if (sa[i]>=j) y[p++]=sa[i]-j;
for (i=0;i<n;++i) wv[i]=x[y[i]];
for (i=0;i<m;++i) Ws[i]=0;
for (i=0;i<n;++i) Ws[wv[i]]++;
for (i=0;i<m;++i) Ws[i]+=Ws[i-1];
for (i=n-1;i>=0;--i) sa[--Ws[wv[i]]]=y[i];
for (t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1;i<n;i++)
x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
}
}
void calcheight(int *r,int *sa,int n){
int i,j,k=0;
for (i=1;i<=n;++i) rank[sa[i]]=i;
for (i=0;i<n;height[rank[i++]]=k)
for (k?k--:0,j=sa[rank[i]-1];r[i+k]==r[j+k];k++);
}
bool check(int *sa,int n,int x){
int i,mx=sa[1],mi=sa[1];
for (i=2;i<=n;++i){
if (height[i]<x) mx=mi=sa[i];
else{
mx=max(mx,sa[i]);
mi=min(mi,sa[i]);
if (mx-mi>x) return 1;
}
}return 0;
}
int main(){
freopen("theme.in","r",stdin);
freopen("theme.out","w",stdout);
scanf("%d",&n);
int fir=read(); n--;
for (int i=0;i<n;++i){
int sec=read();
a[i]=sec-fir+200;
fir=sec;
}
a[n]=0;
da(a,sa,n+1,500);
calcheight(a,sa,n);
int L=1,R,ans=-1;
if (n&1) R=(n+1)/2;
else R=n/2;
while(L<R){
int mid=(L+R)>>1;
if (check(sa,n,mid)){
L=mid+1;
ans=mid;
}else R=mid;
}
if (ans>=4) printf("%d\n",ans+1);
else printf("0\n");
}