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>
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define f first
#define s second
using namespace std;
const int N=4001;
char mat[N][N];
int dist[N][N];
vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
int h,w;
bool inside(int x,int y)
{
return x>=0&&x<h&&y>=0&&y<w&&(mat[x][y]=='F'||mat[x][y]=='R');
}
int main()
{
cin >> h >> w;
for(int i=0;i<h;i++)
scanf("%s",mat[i]);
deque<pair<int,int> > q;
q.pb({0,0});
dist[0][0]=1;
int sol=1;
while(q.size())
{
auto tr=q.front();
q.pop_front();
sol=max(sol,dist[tr.f][tr.s]);
for(int k=0;k<4;k++)
{
int x=tr.f+dx[k],y=tr.s+dy[k];
if(inside(x,y)&&dist[x][y]==0)
{
if(mat[x][y]==mat[tr.f][tr.s])
{
dist[x][y]=dist[tr.f][tr.s];
q.push_front({x,y});
}
else
{
dist[x][y]=dist[tr.f][tr.s]+1;
q.push_back({x,y});
}
}
}
}
printf("%i\n",sol);
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:22:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",mat[i]);
~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |