# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42411 | Hassoony | Tracks in the Snow (BOI13_tracks) | C++14 | 1423 ms | 49620 KiB |
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>
#include<unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double D;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=4002;
int n,m,ans;
bool vis[MX][MX];
char a[MX][MX],c;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)scanf("%s",&a[i]);
queue<pair<int,int> >q[2];
int node=0;
if(a[0][0]=='.'){
puts("0");
return 0;
}
q[node].push({0,0});
while(!q[node].empty()){
ans++;
while(!q[node].empty()){
int x=q[node].front().first,y=q[node].front().second;q[node].pop();
if(vis[x][y])continue;
vis[x][y]=1;
for(int i=0;i<4;i++){
int nx=dx[i]+x,ny=dy[i]+y;
if(nx>=n||ny>=m||nx<0||ny<0||vis[nx][ny]||a[nx][ny]=='.')continue;
if(a[nx][ny]==a[x][y])q[node].push({nx,ny});
else q[node^1].push({nx,ny});
}
}
node^=1;
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |