-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathpoveste.cpp
57 lines (50 loc) · 1.19 KB
/
poveste.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# include <fstream>
# include <algorithm>
# include <cstring>
# define NR 1005
using namespace std;
ifstream f("poveste.in");
ofstream g("poveste.out");
int i,j,n,m,x,t,o,maxx,l,k;
int a[NR][NR], pi[NR];
char s[NR];
int main ()
{
f>>t;
for (o=1; o<=t; ++o)
{
f>>n>>m; f.get();
for (i=1; i<=n; ++i)
{
f.getline (s+1, NR);
for (j=1; j<=m; ++j)
a[j][i]=s[j]-'0';
}
swap (n, m); maxx=m;
for (i=1; i<n; ++i) // prima linie
{
//prefix
k=0; memset(pi, 0, sizeof(pi));
for (l=2; l<=m; ++l)
{
while (k>0 && a[i][k+1]!=a[i][l])
k=pi[k];
if (a[i][k+1]==a[i][l]) ++k;
pi[l]=k;
}
for (j=i+1; j<=n; ++j) // a doua linie
{
k=0;
for (l=1; l<=m; ++l)
{
while (k>0 && a[i][k+1]!=a[j][l])
k=pi[k];
if (a[i][k+1]==a[j][l]) ++k;
maxx=max(maxx, (j-i+1)*k);
}
}
}
g<<maxx<<"\n";
}
return 0;
}