Advertisement
Guest User

Untitled

a guest
Apr 17th, 2016
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(false); cin.tie(0);
  7.  
  8.     int n, m;
  9.     cin >> n >> m;
  10.     vector<string> a(n);
  11.     for (int i = 0; i < n; i++) {
  12.         cin >> a[i];
  13.     }
  14.  
  15.     bool flag = true;
  16.     for (int i = 0; i < n; i++) {
  17.         for (int j = 0; j < m; j++) {
  18.             if (a[i][j] == '#') continue;
  19.             int degree = 0;
  20.             if (i != 0 && a[i - 1][j] != '#') degree++;
  21.             if (i != n - 1 && a[i + 1][j] != '#') degree++;
  22.             if (j != 0 && a[i][j - 1] != '#') degree++;
  23.             if (j != m - 1 && a[i][j + 1] != '#') degree++;
  24.             if (degree >= 3) {
  25.                 cout << "YES\n";
  26.                 return 0;
  27.             }
  28.             if (degree == 1) flag = false;
  29.         }
  30.     }
  31.  
  32.     if (flag) cout << "YES\n";
  33.     else cout << "NO\n";
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement