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>
using namespace std;
#define ll long long
#define el '\n'
#define ld long double
const int maxn=4e3+1,oo=1e9;
char c[maxn][maxn];
bool ok[maxn][maxn]={0};
int n,m,ans,x,y,nx,ny;
char cnt;
struct pnt{
int x,y;
};
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
vector<pnt> now,net;
bool check(int xx,int yy){
if(!ok[xx][yy]) return 0;
ok[xx][yy]=0;
return 1;
}
int main(){
//freopen("T.INP","r",stdin);
//freopen("T.OUT","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j){
cin >> c[i][j];
if(c[i][j]!='.') ok[i][j]=1;
}
cnt=c[1][1];
ok[1][1]=0;
now.push_back({1,1});
ans=0;
while(!now.empty()){
net.resize(0);
ans++;
while(!now.empty()){
x=now.back().x;
y=now.back().y;
now.pop_back();
for(int i=0;i<4;++i){
nx=x+dx[i];
ny=y+dy[i];
if(check(nx,ny)){
if(c[nx][ny]==cnt) now.push_back({nx,ny});
else net.push_back({nx,ny});
}
}
}
now=net;
if(cnt=='F') cnt='R';
else cnt='F';
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |