Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i, x, n) for (int i = x; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
#define sp(p) cout << setprecision(16) << fixed << p << endl;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v)                                                                \
  for (int i = 0; i < (int)v.size() - 1; i++) {                                \
    cout << v[i] << " ";                                                       \
  }                                                                            \
  cout << v[v.size() - 1] << "\n";
#define debg(a) cerr << #a << " " << a << endl;
#define show(a)                                                                \
  for (cont & y : a) {                                                         \
    for (cont & x : y) {                                                       \
      cout << x << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
template <class T> inline int out(const T &t) {
  print(t);
  putchar('\n');
  return 0;
}
template <class T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return (gcd(b, a % b));
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
vector<ll> dp;

const string YES = "Yes";
const string NO = "No";
#define judge(f) cout << (f ? YES : NO) << "\n";

const ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool check(long long H, long long W, std::vector<std::string> s, ll i, ll j) {
  for (ll k = 0; k < 4; k++) {
    if (i + dy[k] < 0 || i + dy[k] >= H || j + dx[k] < 0 || j + dx[k] >= W)
      continue;
    if (s[i + dy[k]][j + dx[k]] == '#') {
      return true;
    }
  }
  return false;
}

void solve(long long H, long long W, std::vector<std::string> s) {
  bool f = true;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      if (s[i][j] == '.')
        continue;
      f = check(H, W, s, i, j);
      if (f == true)
        continue;
      if (f == false) {
        judge(f);
        return;
      }
    }
  }
  judge(f);
  return;
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> s(W);
  for (int i = 0; i < H; i++) {
    std::cin >> s[i];
  }
  solve(H, W, std::move(s));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i, x, n) for (int i = x; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
#define sp(p) cout << setprecision(16) << fixed << p << endl;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v)                                                                \
  for (int i = 0; i < (int)v.size() - 1; i++) {                                \
    cout << v[i] << " ";                                                       \
  }                                                                            \
  cout << v[v.size() - 1] << "\n";
#define debg(a) cerr << #a << " " << a << endl;
#define show(a)                                                                \
  for (cont & y : a) {                                                         \
    for (cont & x : y) {                                                       \
      cout << x << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
template <class T> inline int out(const T &t) {
  print(t);
  putchar('\n');
  return 0;
}
template <class T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return (gcd(b, a % b));
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
vector<ll> dp;

const string YES = "Yes";
const string NO = "No";
#define judge(f) cout << (f ? YES : NO) << "\n";

const ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool check(long long H, long long W, std::vector<std::string> s, ll i, ll j) {
  for (ll k = 0; k < 4; k++) {
    if (i + dy[k] < 0 || i + dy[k] >= H || j + dx[k] < 0 || j + dx[k] >= W)
      continue;
    if (s[i + dy[k]][j + dx[k]] == '#') {
      return true;
    }
  }
  return false;
}

void solve(long long H, long long W, std::vector<std::string> s) {
  bool f = true;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      if (s[i][j] == '.')
        continue;
      f = check(H, W, s, i, j);
      if (f == true)
        continue;
      if (f == false) {
        judge(f);
        return;
      }
    }
  }
  judge(f);
  return;
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> s(H);
  for (int i = 0; i < H; i++) {
    std::cin >> s[i];
  }
  solve(H, W, std::move(s));
  return 0;
}