fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. #define all(x) x.begin(), x.end()
  4. #define f1(i, n) for(int i=1;i<=n;++i)
  5. using namespace std;
  6.  
  7. const int maxn = 1e6 + 5;
  8. const int MOD = 1e9 + 7;
  9.  
  10. char A[30][30];
  11. int n, m;
  12.  
  13. bool check(int i, int j) {
  14. int cnt = 0;
  15. if (A[i - 1][j] == '#')
  16. ++cnt;
  17. if (A[i][j - 1] == '#')
  18. ++cnt;
  19. if (A[i][j + 1] == '#')
  20. ++cnt;
  21. if (A[i + 1][j] == '#')
  22. ++cnt;
  23. if (cnt != 2 and cnt != 4) return false;
  24. return true;
  25.  
  26. }
  27.  
  28. main() {
  29. ios::sync_with_stdio(false);
  30. cin.tie(nullptr);
  31. cout.tie(nullptr);
  32.  
  33. // . là trắng, # là đen
  34.  
  35. cin >> n >> m;
  36. f1(i, n) {
  37. string s;
  38. cin >> s;
  39. f1(j, m) {
  40. A[i][j] = s[j - 1];
  41. }
  42. }
  43.  
  44. // bool ok = false;
  45.  
  46. for (int i = 1; i <= n; ++i) {
  47. for (int j = 1; j <= m; ++j) {
  48. if (A[i][j] == '#') {
  49. if (!check(i, j)) {
  50. // cout<<"---"<<i<<" "<<j<<"---"<<endl;
  51. cout << "No";
  52. return 0;
  53. }
  54. }
  55. }
  56. }
  57. // if(!ok) cout<<"Yes";
  58. cout << "Yes";
  59.  
  60.  
  61.  
  62. }
  63.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Yes