Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int resp=0;
- int M,N;
- char mat[1004][1004];
- int dx[] = {-1,0,1,0,-1};
- int mat2[1004][1004];
- void dfs(int x, int y){
- for(int i=0, u,v;i<4;i++){
- u=x+dx[i];
- v=y+dx[i+1];
- if(u<0 || v<0 || u>=M+2 || v>=N+2) continue;
- if(u<1 || v<1 || u>M || v>N)
- mat[u][v]='.';
- if(mat[u][v]=='#' && mat2[u][v]!=1){
- resp++;
- mat2[u][v]=1;
- }
- else if(mat[u][v]!='#' && mat2[u][v]!=1){
- mat2[u][v]=1;
- dfs(u,v);
- }
- }
- }
- int main(){
- cin>>M>>N;
- for(int i=0;i<M;i++){
- for(int j=0;j<N;j++){
- cin>>mat[i+1][j+1];
- }
- }
- mat2[0][0]=1;
- dfs(0,0);
- cout<<resp<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement