///题意: 求一个串至少出现k次的最长重复子串的长度,可重叠 #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <cstdlib> #define MAXN 42222 using namespace std; int max(int a,int b) { return a>=b?a:b; } int r[MAXN]; char s[MAXN]; int wa[MAXN], wb[MAXN], wv[MAXN], tmp[MAXN],a[MAXN];; int sa[MAXN]; //index range 1~n value range 0~n-1 int 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, *ws = tmp; ///对r中长度为1的子串进行基数排序 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; ///对r中长度为j的子串进行基数排序 for (j = 1, p = 1; p < n; j *= 2, 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 = 1; i < m; i++) ws[i] += ws[i - 1]; for (i = n - 1; i >= 0; i--) sa[--ws[wv[i]]] = y[i]; for (swap(x, y), 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++; } } int rank[MAXN]; //index range 0~n-1 value range 1~n int height[MAXN],pre,st,nst; //index from 1 (height[1] = 0) void calheight(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); return; } int check(int mid,int n,int k) { pre=0; int tt=-1,last=0,flag=0; for(int sum=1,i =1; i<=n; i++) { if(height[i]<mid) { sum=1; last=i; tt=-1; } else { sum++; } tt=max(tt,sa[i]); if(sum>=k) { pre=max(pre,tt); flag=1; } } return flag; } int main() { int n,k,i,j; //freopen("//media/学习/ACM/input.txt","r",stdin); while(~scanf("%d",&k) ,k) { cin>>s; n=strlen(s); if(k==1) { printf("%d %d\n",n,0); continue; } for(i = 0; i < n; i++) a[i]=s[i],r[i] =a[i]; r[n] = 0; da(r, sa, n + 1, 256); calheight(r, sa, n); /* for(int i=0;i<=n;i++) cout<<height[i]<<' '; cout<<endl; for(i=0;i<=n;i++) cout<<sa[i]<<' '; cout<<endl; */ int low =0, high = n, ans =0; while(low <= high) { int mid = (low + high) >> 1; if(check(mid,n,k)) { low=mid+1; ans=mid; st=pre; //st=nst; } else high=mid-1; } if(ans<=0)puts("none"); else printf("%d %d\n",ans,st); } return 0; } /* 3 baaaababababbababbab 11 baaaababababbababbab 3 cccccc 1 abcdef 0 */