Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助RT。 所有样例都可以过。 所有Discuss里的东西也都OK。 然后WA了。 #include <cstdio> #include <cstring> #include <cctype> #include <climits> #include <algorithm> using namespace std; #define rep(i,a,b) for (int i=(a);i<=(b);i++) #define per(i,a,b) for (int i=(a);i>=(b);i--) const int N=32768; const int MAX=INT_MAX>>1; int n; int s[N]; int t[N]; int ht[N],sa[N],rk[N]; int sum[N],tsa[N],trk[N]; int al,ar; int mid; inline int rd(void) { int x=0,f=1; char c=getchar(); for (;!isdigit(c);c=getchar()) if (c=='-') f=-1; for (;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f; } int Check(int x) { int minLoc,maxLoc; int cur; rep(i,2,n) if (ht[i]>=x) { minLoc=min(sa[i-1],sa[i]); maxLoc=max(sa[i-1],sa[i]); cur=i; while (cur+1<=n&&ht[cur+1]>=x) { cur++; minLoc=min(minLoc,sa[cur]); maxLoc=max(maxLoc,sa[cur]); } i=cur; if (minLoc+x<maxLoc) return 1; } return 0; } int main(void) { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); rep(tur,1,MAX) { n=rd(); if (!n) break; if (n==1) { printf("0\n"); continue; } memset(s,0,sizeof s); rep(i,1,n) s[i]=rd(); rep(i,1,n-1) s[i]=s[i+1]-s[i]+90; s[n--]=MAX; memset(ht,0,sizeof ht); memset(rk,0,sizeof rk); memset(sa,0,sizeof sa); memset(sum,0,sizeof sum); memset(tsa,0,sizeof tsa); memset(trk,0,sizeof trk); int lim=200,p; rep(i,1,n) sum[rk[i]=s[i]]++; rep(i,1,lim) sum[i]+=sum[i-1]; per(i,n,1) sa[sum[rk[i]]--]=i; rk[sa[1]]=p=1; rep(i,2,n) { if (s[sa[i]]!=s[sa[i-1]]) p++; rk[sa[i]]=p; } lim=p; for (int j=1;lim!=n;j<<=1) { p=0; memset(tsa,0,sizeof tsa); rep(i,n-j+1,n) tsa[++p]=i; rep(i,1,n) if (sa[i]>j) tsa[++p]=sa[i]-j; memset(sum,0,sizeof sum); memmove(trk,rk,sizeof rk); rep(i,1,n) sum[rk[i]=trk[tsa[i]]]++; rep(i,1,lim) sum[i]+=sum[i-1]; per(i,n,1) sa[sum[rk[i]]--]=tsa[i]; rk[sa[1]]=p=1; rep(i,2,n) { if (trk[sa[i]]!=trk[sa[i-1]]||trk[sa[i]+j]!=trk[sa[i-1]+j]) p++; rk[sa[i]]=p; } lim=p; } p=0; rep(i,1,n) { if (p>0) p--; while (s[i+p]==s[sa[rk[i]-1]+p]) p++; ht[rk[i]]=p; } al=0,ar=n; while (al<=ar) { mid=(al+ar)>>1; if (Check(mid)) al=mid+1; else ar=mid-1; } if (ar<4) printf("0\n"); else printf("%d\n",ar+1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator