This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <deque>
#define MAXN 4005
#define MAXV 17000000
int n, m;
std::deque<std::pair<int, int> > bfs;
bool vis[MAXN][MAXN];
int d[MAXN][MAXN];
//std::vector<std::pair<int, bool> > Adj[MAXV];
int mat[MAXN][MAXN];
int main()
{
std::ios::sync_with_stdio(false);
std::cin >> n >> m;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
char c;
std::cin >> c;
if(c == 'R')
mat[i][j] = 1;
else if(c == 'F')
mat[i][j] = 2;
else
mat[i][j] = 0;
}
}
bfs.push_front({0, 0});
d[0][0] = 0;
vis[0][0] = true;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int answer = 0;
while(!bfs.empty())
{
std::pair<int, int> u = bfs.front();
bfs.pop_front();
int i = u.first;
int j = u.second;
for(int k = 0; k < 4; k++)
{
int p = i + dx[k];
int q = j + dy[k];
if(p < 0 || p >= n || q < 0 || q >= m)
continue;
if(!vis[p][q] && mat[p][q])
{
vis[p][q] = true;
bool type = (mat[p][q] != mat[i][j]);
d[p][q] = d[i][j];
if(type)
{
d[p][q]++;
bfs.push_back({p, q});
}
else
bfs.push_front({p, q});
answer = std::max(answer, d[p][q]);
}
}
}
std::cout << answer+1 << std::endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |