Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define IN freopen("input.txt", "r", stdin)
#define OUT freopen("output.txt", "w", stdout)
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
char arr[1000][1000];
bool vis[1000][1000];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int n, m, ans = 0, mir = 0;
bool valid(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < m;
}
void dfsup(int i, int j);
void dfsdown(int i, int j);
void dfsleft(int i, int j);
void dfsright(int i, int j);
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> arr[i][j];

    int mx = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (arr[i][j] == '.')
            {
                ans = 1;
                dfsup(i, j);
                dfsdown(i, j);
                dfsright(i, j);
                dfsleft(i, j);
            }
            memset(vis, 0, sizeof vis);
            mx = max(ans, mx);
        }
    }
    cout << mx << '\n';
}
void dfsright(int i, int j)
{
    vis[i][j] = 1;
    int di = i + 1;
    if (!valid(di, j))
        return;
    if (arr[di][j] == '.')
    {
        if(!vis[di][j])
        ans++;
        dfsright(di, j);
    }

    else if (arr[di][j] == '/')
    {
        if (!vis[di, j])
            dfsup(di, j);
        return;
    }
    else if (arr[di][j] == '\\')
    {
        if (!vis[di, j])
            dfsdown(di, j);
        return;
    }
    else if (arr[di][j] == '#')
        return;
}
void dfsleft(int i, int j)
{
    vis[i][j] = 1;
    int di = i - 1;
    if (!valid(di, j))
        return;
    if (arr[di][j] == '.')
    {
        if(!vis[di][j])
        ans++;
        dfsleft(di, j);
    }

    else if (arr[di][j] == '/')
    {
        if (!vis[di][j])
            dfsdown(di, j);
        return;
    }
    else if (arr[di][j] == '\\')
    {
        if (!vis[di][j])
            dfsup(di, j);
        return;
    }
    else if (arr[di][j] == '#')
        return;
}
void dfsdown(int i, int j)
{
    vis[i][j] = 1;
    int dj = j + 1;
    if (!valid(i, dj))
        return;
    if (arr[i][dj] == '.')
    {
        if(!vis[i][dj])
        ans++;
        dfsdown(i, dj);
    }
    else if (arr[i][dj] == '/')
    {
        if (!vis[i][dj])
            dfsleft(i, dj);
        return;
    }
    else if (arr[i][dj] == '\\')
    {
        if (!vis[i][dj])
            dfsright(i, dj);
        return;
    }
    else if (arr[i][dj] == '#')
        return;
}
void dfsup(int i, int j)
{
    vis[i][j] = 1;
    int dj = j - 1;
    if (!valid(i, dj))
        return;
    if (arr[i][dj] == '.')
    {
        if(!vis[i][dj])
        ans++;
        dfsup(i, dj);
    }
    else if (arr[i][dj] == '/')
    {
        if (!vis[i][dj])
            dfsright(i, dj);
        return;
    }
    else if (arr[i][dj] == '\\')
    {
        if (!vis[i][dj])
            dfsleft(i, dj);
        return;
    }
    else if (arr[i][dj] == '#')
        return;
}
Copy
Mirrors monther abu zaina1
GNU G++17
2 ms
1.5 MB
Wrong Answer