SHARE
TWEET

CUBE-066: dog_village

LZsolar Mar 26th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m,mp[1010][1010],sur,dayIn[1010][1010],getInf[1010][1010];
  4. bool infected[1010][1010];
  5.  
  6. void isInf(int i,int j,int day){
  7.     if(i<1||j< 1||i>n||j>m){exit;}    
  8.      
  9.     else if(mp[i][j]>day){
  10.         if(getInf[i][j]>day){
  11.             getInf[i][j]=day;
  12.             isInf(i+1,j,day+1);
  13.             isInf(i-1,j,day+1);
  14.             isInf(i,j+1,day+1);
  15.             isInf(i,j-1,day+1);
  16.         }
  17.         else if(!infected[i][j]){
  18.         infected[i][j]=true;
  19.             sur++;
  20.             getInf[i][j]=day;
  21.             isInf(i+1,j,day+1);
  22.             isInf(i-1,j,day+1);
  23.             isInf(i,j+1,day+1);
  24.             isInf(i,j-1,day+1);
  25.         }
  26.      }
  27. }
  28.  
  29. int main(){
  30.     scanf("%d %d",&n,&m);
  31.    
  32.     for(int i=1;i<=n;i++){
  33.         for(int j=1;j<=m;j++){
  34.             scanf("%d",&mp[i][j]);
  35.         }
  36.     }
  37.    
  38.     for(int i=1;i<=n;i++){
  39.         for(int j=1;j<=m;j++){
  40.             if(mp[i][j]==0){
  41.                 infected[i][j]=true; sur++;
  42.                 isInf(i+1,j,1);
  43.                 isInf(i-1,j,1);
  44.                 isInf(i,j+1,1);
  45.                 isInf(i,j-1,1);
  46.             }
  47.         }
  48.     }
  49.  
  50.    
  51.     printf("%d",(n*m)-sur);
  52.    
  53.     return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top