-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJanLong4.cpp
More file actions
128 lines (128 loc) · 1.83 KB
/
JanLong4.cpp
File metadata and controls
128 lines (128 loc) · 1.83 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include<iostream>
using namespace std;
int maxx(int a,int b)
{
if(a<0)
a=-a;
if(b<0)
b=-b;
return (a>=b)?a:b;
}
int min(int a,int b)
{
return (a<=b)?a:b;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m,i,j,k,proof=0; char aa[1001][1001]; bool a[1001][1001];
cin>>n>>m;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>aa[i][j];
if(aa[i][j]=='*')
{
a[i][j]=true;
proof=1;
}
else
a[i][j]=false;
}
}
if(proof==0)
{
cout<<"0\n";
continue;
}
int tx,ty;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]==true)
{
tx=i;ty=j;
break;
}
}
}
int lx,ly;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[j][i]==true)
{
lx=j;ly=i;
break;
}
}
}
int bx,by;
for(i=n-1;i>=0;i--)
{
for(j=m-1;j>=0;j--)
{
if(a[i][j]==true)
{
bx=i;by=j;
break;
}
}
}
int rx,ry;
for(i=m-1;i>=0;i--)
{
for(j=n-1;j>=0;j--)
{
if(a[j][i]==true)
{
rx=j;ry=i;
break;
}
}
}
int x=(tx+bx)/2;
int y=(ly+ry)/2;
int mxx=10000,my,mx,mxxx=10000;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]==true)
{
int mxy=maxx(i-x,j-y);
int xx=i-x,yy=j-y;
if(xx<0)
xx=-xx;
if(yy<0)
yy=-yy;
int mxay=xx+yy;
if(mxx>=mxy)
{
if(mxxx>mxay)
{
mxxx=mxay;
mxx=mxy;
mx=i;
my=j;
}
}
}
}
}
lx=maxx(lx-mx,ly-my);
rx=maxx(rx-mx,ry-my);
tx=maxx(tx-mx,ty-my);
bx=maxx(bx-mx,by-my);
int ans=0;
ans=maxx(maxx(maxx(lx,rx),bx),tx)+1;
cout<<ans<<endl;
}
return 0;
}