//in the name of Allah
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e16
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
const ll N = 2000,Mod = 1e9 + 7;
ll n,m;
char a[N][N];
string s;
/// 0 -> Down , 1 -> Top , 2 -> Right, 3 -> Left
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll Dp[N][N][5];
pll C[N][N],Cur = {-1,-1};
ll Solve(int i,int j,int d)
{
if(i >= n || i < 0 || j >= m || j < 0)
R 0;
if(a[i][j] == '#')
R 0;
ll &Res = Dp[i][j][d];
if(Res + 1)
R Res;
Res = 0;
int Nxt_i = i + dx[d];
int Nxt_j = j + dy[d];
int new_d = d;
if(a[i][j] == '.')
{
Res = 1 + Solve(Nxt_i,Nxt_j,d);
}
else if(a[i][j] == '/')
{
if(d == 0) // Down
{
Nxt_i = i;
Nxt_j = j-1;
new_d = 3;
}
else if(d == 1) // Top
{
Nxt_i = i;
Nxt_j = j+1;
new_d = 2;
}
else if(d == 2) // Right
{
Nxt_i = i-1;
Nxt_j = j;
new_d = 1;
}
else if(d == 3) // Left
{
Nxt_i = i+1;
Nxt_j = j;
new_d = 0;
}
Res = Solve(Nxt_i,Nxt_j,new_d);
}
else
{
if(d == 0) // Down
{
Nxt_i = i;
Nxt_j = j+1;
new_d = 2;
}
else if(d == 1) // Top
{
Nxt_i = i;
Nxt_j = j-1;
new_d = 3;
}
else if(d == 2) // Right
{
Nxt_i = i+1;
Nxt_j = j;
new_d = 0;
}
else if(d == 3) // Left
{
Nxt_i = i-1;
Nxt_j = j;
new_d = 1;
}
Res = Solve(Nxt_i,Nxt_j,new_d);
}
if(Cur.fr == Nxt_i && Cur.sc == Nxt_j)
{
C[Cur.fr][Cur.sc] = {i,j};
}
R Res;
}
int main()
{
SPEED;
cin >> n >> m;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
cin >> a[i][j];
C[i][j] = {-1,-1};
}
}
memset(Dp,-1,sizeof Dp);
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
for(int d=0; d<4; d++)
{
if(a[i][j] == '.')
{
Cur = {i,j};
Solve(i,j,d);
}
}
}
}
ll Ans = 0;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
ll Res = 1;
if(a[i][j] != '.')
continue;
for(int d=0; d<4; d++)
{
int new_i = i + dx[d];
int new_j = j + dy[d];
if(C[i][j].fr == new_i && C[i][j].sc == new_j)
continue;
Res += Solve(new_i,new_j,d);
}
Ans = max(Ans,Res);
}
}
cout << Ans << endl;
R 0;
}
Copy