Maximum repetition substring
[Submit] [Go Back] [Status] Description The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same consecutive substrings. For example, the repetition number of ababab is 3 and ababa is 1. Given a string containing lowercase letters, you are to find a substring of it with maximum repetition number. Input The input consists of multiple test cases. Each test case contains exactly one line, which The last test case is followed by a line containing a '#'. Output For each test case, print a line containing the test case number( beginning with 1) followed by the substring of maximum repetition number. If there are multiple substrings of maximum repetition number, print the lexicographically smallest one. Sample Input ccabababc daabbccaa # Sample Output Case 1: ababab Case 2: aa Source 2008 Asia Hefei Regional Contest Online by USTC[Submit] [Go Back] [Status] |
![]() |
#include#include #include #include #include #include using namespace std; const int maxn=1000012; int sa[maxn],rank[maxn],rank2[maxn],h[maxn],c[maxn],*x,*y,ans[maxn]; char str[maxn]; bool cmp(int* r,int a,int b,int l,int n) { if(r[a]==r[b]&&a+l =0;i--) sa[--c[x[y[i]]]]=y[i]; } void get_sa(char c[],int n,int sz=128) { x=rank,y=rank2; for(int i=0;i =len) y[yid++]=sa[i]-len; radix_sort(n,sz); swap(x,y); x[sa[0]]=yid=0; for(int i=1;i =n) break; } for(int i=0;i r) swap(l,r); int a=l+1,b=r; int k=Log[b-a+1]; return min(dp[a][k],dp[b-(1< =0&&k%l!=0) { if(lcp(t,t+l)>=k) r++; } if(r>maxx) { a=0; maxx=r; ans[a++]=l; } else if(r==maxx) { ans[a++]=l; } } } int pos; int st,b=0,c; for(int i=0;i =(maxx-1)*tl) { st=sa[i]; pos=i; l=tl*maxx; b=1; break; } } } printf(Case %d: ,cas++); for (int i=0;i
