fork download
  1. program casino;
  2. Uses sysutils;
  3. {$H+}
  4. const lung=1000000;
  5. var N,M,C,w,v,coppie,index:Int64;
  6. temp: AnsiString;
  7. S,S_ruotate:array[0..lung] of AnsiString;
  8. funz_errore : array[0..2000000] of Int64;
  9. function LexicalMinRotation(var x: AnsiString):Int64;
  10. var
  11. len,K,i,j:Int64;
  12.  
  13. begin
  14. temp:=x+x;
  15. len:=length(x);
  16. for i:=1 to len do funz_errore[i]:=-1; (*inizializzo la funzione errore a -1*)
  17. K:=0;
  18. for j:=1 to len do
  19. begin
  20. i:=1;
  21. while (i <> -1 ) and (x[j mod len] <> x[(k + i + 1 ) mod len]) do
  22. begin
  23. i:=funz_errore[j - k - 1];
  24. if x[j mod len] < x[(k + i + 1) mod len] then k:= j - i - 1;
  25. i:= funz_errore[i];
  26. end;
  27. if (i = -1) and (s[j mod len ] <> s[(k + i+1 ) mod len ]) then
  28. begin
  29. if s[j mod len] < s[(k + i+1 ) mod len] then k:= j;
  30. funz_errore[j - k]:= -1;
  31. end
  32. else
  33. funz_errore[j - k]:= i + 1;
  34.  
  35. end;
  36. LexicalMinRotation:=k;
  37.  
  38. end;
  39.  
  40. begin
  41. (*assign(input, 'input.txt'); reset(input);
  42.   assign(output, 'output.txt'); rewrite(output);*)
  43. readln (N,M);
  44. for w:=0 to N-1 do readln(S[w]);
  45. coppie:=0;
  46. for w:=0 to N-1 do
  47. begin
  48. index:=LexicalMinRotation(S[w]);
  49. writeln(index);
  50. S_ruotate[w]:=copy(temp,index,M);
  51. writeln(S_ruotate[w]);
  52. end;
  53. for w:=0 to N-2 do
  54. for v:=w+1 to N-1 do
  55. begin
  56. C:= CompareStr(S_ruotate[w], S_ruotate[v]);
  57. if C=0 then coppie:=coppie+1;
  58. end;
  59. writeln (coppie);
  60. end.
Success #stdin #stdout 0.02s 5284KB
stdin
Standard input is empty
stdout
0