forked from yalza/CPP_code.ptit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP0237 - MA TRẬN VUÔNG LỚN NHẤT
52 lines (51 loc) · 1.23 KB
/
CPP0237 - MA TRẬN VUÔNG LỚN NHẤT
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
#include <iostream>
using namespace std;
int findSubSquare(char mat[][100],int N)
{
int max = 0;
int hor[100][100], ver[100][100];
hor[0][0] = ver[0][0] = (mat[0][0] == 'X');
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (mat[i][j] == 'O')
ver[i][j] = hor[i][j] = 0;
else
{
hor[i][j]
= (j == 0) ? 1 : hor[i][j - 1] + 1;
ver[i][j]
= (i == 0) ? 1 : ver[i - 1][j] + 1;
}
}
}
for (int i = N - 1; i >= 1; i--)
{
for (int j = N - 1; j >= 1; j--)
{
int small = min(hor[i][j], ver[i][j]);
while (small > max)
{
if (ver[i][j - small + 1] >= small
&& hor[i - small + 1][j] >= small)
{
max = small;
}
small--;
}
}
}
return max;
}
int main()
{
int t; cin >> t;
while (t--) {
int n; cin >> n;
char M[100][100];
for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)cin >> M[i][j];
cout << findSubSquare(M, n) << endl;;
}
return 0;
}