Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<queue>
- using namespace std;
- struct dog{
- int I,J,Day;
- };
- bool InB(int I,int N){
- return (1 <= I && I <= N);
- }
- int main()
- {
- int n,m;
- scanf("%d %d",&n,&m);
- int arr[n+1][m+1];
- queue<dog> q;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- scanf("%d",&arr[i][j]);
- if(arr[i][j] == 0){
- q.push({i,j,0});
- }
- }
- }
- bool visited[n+1][m+1];for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)visited[i][j] = false;
- int moveI[4] = {-1,0,1,0};
- int moveJ[4] = {0,1,0,-1};
- int cnt = 0;
- while(!q.empty()){
- int uI = q.front().I;
- int uJ = q.front().J;
- int uDay = q.front().Day;
- q.pop();
- if(visited[uI][uJ])continue;
- visited[uI][uJ] = true;
- cnt++;
- for(int i=0;i<4;i++){
- int vI = uI + moveI[i];
- int vJ = uJ + moveJ[i];
- if(InB(vI,n) && InB(vJ,m) && arr[vI][vJ] > uDay + 1){
- q.push({vI,vJ,uDay + 1});
- }
- }
- }
- printf("%d",(n*m) - cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment