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 <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
bool visited[4001][4001];
char grid[4001][4001];
ll depth[4001][4001];
vector<ll> xx = {-1,1,0,0}, yy = {0,0,-1,1};
int main(){
FOR(i,0,4001){
FOR(j,0,4001){
visited[i][j] = 0;
grid[i][j] = 0;
depth[i][j] = 0;
}
}
ll n,m;
cin >> n >> m;
FOR(i,0,n){
string temp;
cin >> temp;
FOR(j,0,m){
grid[i][j] = temp[j];
}
}
vector<char> ani;
if (grid[0][0] == 'F'){
ani = {'F','R'};
}else ani = {'R','F'};
deque<vector<ll>> q;
q.push_front({0,0,0});
while (q.size()){
vector<ll> node = q.front();
depth[node[1]][node[2]] = node[0];
q.pop_front();
FOR(i,0,4){
ll x = node[1] + xx[i];
ll y = node[2] + yy[i];
if (0<=x && x<n && 0<=y && y<m && grid[x][y] != '.'){
if (grid[x][y] == ani[node[0]%2] && !visited[x][y]){
visited[x][y] = 1;
q.push_front({node[0], x,y});
}
if (grid[x][y] != ani[node[0]%2] && !visited[x][y]){
visited[x][y] = 1;
q.push_back({node[0]+1, x,y});
}
}
}
}
ll maxi = -1;
FOR(i,0,4001){
FOR(j,0,4001){
maxi = max(maxi, depth[i][j]);
}
}
cout << maxi+1;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |