Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pi = pair <int, int>;
- const int N = 30 + 10;
- const int M = 30 + 10;
- char ar[N][M];
- bool vs[N][M];
- int n, m;
- bool Pst(int i, int j){
- return 1 <= i and i <= n and 1 <= j and j <= m;
- }
- bool Box(int ui, int uj){
- if(!Pst(ui, uj) or ar[ui][uj] == '#') return false;
- if(!Pst(ui + 1, uj) or ar[ui + 1][uj] == '#') return false;
- if(!Pst(ui, uj + 1) or ar[ui][uj + 1] == '#') return false;
- if(!Pst(ui + 1, uj + 1) or ar[ui + 1][uj + 1] == '#') return false;
- return true;
- }
- int main(){
- scanf("%d %d", &n, &m);
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- scanf(" %c", &ar[i][j]);
- }
- }
- queue <pi> q;
- for(int j=1;j<=m;j++){
- if(Box(1, j))
- q.push({1, j});
- }
- while(!q.empty()){
- int ui = q.front().first;
- int uj = q.front().second;
- q.pop();
- if(vs[ui][uj])
- continue;
- vs[ui][uj] = true;
- if(ui == n - 1){
- printf("yes");
- return 0;
- }
- if(Box(ui - 1, uj)) q.push({ui - 1, uj});
- if(Box(ui + 1, uj)) q.push({ui + 1, uj});
- if(Box(ui, uj - 1)) q.push({ui, uj - 1});
- if(Box(ui, uj + 1)) q.push({ui, uj + 1});
- }
- printf("no");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement