vitormartinotti

Untitled

Aug 11th, 2026
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define MAXN 1010
  3.  
  4. using namespace std;
  5.  
  6. int m[MAXN][MAXN];
  7.  
  8. int dx[] = {1,0,-1,0};
  9. int dy[] = {0,1,0,-1};
  10.  
  11. int main(){
  12.     int l, c;
  13.     scanf("%d %d", &l, &c);
  14.     int a, b;
  15.     scanf("%d %d", &a, &b);
  16.    
  17.     int soma = 0;
  18.     for(int i = 1; i <= l; i++){
  19.         for(int j = 1; j <= c; j++){
  20.             scanf("%d", &m[i][j]);
  21.             if(m[i][j] == 1) soma++;
  22.         }
  23.     }
  24.    
  25.     while(soma >= 1){
  26.         for(int k = 0; k <= 3; k++){
  27.             int nx = a+dx[k];
  28.             int ny = b+dy[k];
  29.             if(nx < 1 || nx > l) continue;
  30.             if(ny < 1 || ny > c) continue;
  31.             if(m[nx][ny] == 0) continue;
  32.             m[a][b] = 0;
  33.             a = nx;
  34.             b = ny;
  35.         }
  36.         soma--;
  37.     }
  38.    
  39.     printf("%d %d", a, b);
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment