Advertisement
YEZAELP

o12_oct_box

Jan 18th, 2022
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using pi = pair <int, int>;
  5. const int N = 30 + 10;
  6. const int M = 30 + 10;
  7. char ar[N][M];
  8. bool vs[N][M];
  9. int n, m;
  10.  
  11. bool Pst(int i, int j){
  12.     return 1 <= i and i <= n and 1 <= j and j <= m;
  13. }
  14.  
  15. bool Box(int ui, int uj){
  16.     if(!Pst(ui, uj) or ar[ui][uj] == '#') return false;
  17.     if(!Pst(ui + 1, uj) or ar[ui + 1][uj] == '#') return false;
  18.     if(!Pst(ui, uj + 1) or ar[ui][uj + 1] == '#') return false;
  19.     if(!Pst(ui + 1, uj + 1) or ar[ui + 1][uj + 1] == '#') return false;
  20.     return true;
  21. }
  22.  
  23. int main(){
  24.  
  25.     scanf("%d %d", &n, &m);
  26.  
  27.     for(int i=1;i<=n;i++){
  28.         for(int j=1;j<=m;j++){
  29.             scanf(" %c", &ar[i][j]);
  30.         }
  31.     }
  32.  
  33.     queue <pi> q;
  34.     for(int j=1;j<=m;j++){
  35.         if(Box(1, j))
  36.             q.push({1, j});
  37.     }
  38.  
  39.     while(!q.empty()){
  40.         int ui = q.front().first;
  41.         int uj = q.front().second;
  42.         q.pop();
  43.         if(vs[ui][uj])
  44.             continue;
  45.         vs[ui][uj] = true;
  46.         if(ui == n - 1){
  47.             printf("yes");
  48.             return 0;
  49.         }
  50.         if(Box(ui - 1, uj)) q.push({ui - 1, uj});
  51.         if(Box(ui + 1, uj)) q.push({ui + 1, uj});
  52.         if(Box(ui, uj - 1)) q.push({ui, uj - 1});
  53.         if(Box(ui, uj + 1)) q.push({ui, uj + 1});
  54.     }
  55.  
  56.     printf("no");
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement