_
_____________________________
我的做法是错的,但它可以过- -正确的做法应该是用扩展kmp,
______________________________1 Program stone; 2 var i,j,k,n,m,lc,rc:longint; 3 s:array[1..10000,1..100]of char; 4 b:array[1..10000,1..100]of longint; 5 function gcd(x,y:longint):longint; 6 var i,j,k:longint; 7 begin 8 if x>y then begin i:=x;j:=y;end 9 else begin i:=y;j:=x;end;10 while i mod j<>0 do11 begin12 k:=i-j;13 if k0)and(s[i,j]<>s[i,k+1]) do k:=b[i,k];33 if s[i,j]=s[i,k+1] then inc(k);34 b[i,j]:=k;35 end;36 k:=m-b[i,m];37 lc:=gcd(lc,k);38 end;39 if lc>m then lc:=m;40 fillchar(b,sizeof(b),0);41 for i:=1 to m do42 begin43 k:=0;b[1,i]:=0;44 for j:=2 to n do45 begin46 while (k>0)and(s[j,i]<>s[k+1,i]) do k:=b[k,i];47 if s[j,i]=s[k+1,i] then inc(k);48 b[j,i]:=k;49 end;50 k:=n-b[n,i];51 rc:=gcd(rc,k);52 end;53 if rc>m then rc:=m;54 write(lc*rc);55 end.56 57