prithivMLmods/Coder-Stat huggingface dataset:
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
/////////////////////////////////////////
///       Please Give Me AC!!!!!      ///
/////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in)                                                              \
  for (int i = 0; i < (int)in.size(); i++)                                     \
  cin >> in[i]
#define forout(out)                                                            \
  for (int i = 0; i < (int)out.size(); i++)                                    \
  cout << out[i] << endl
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  const int dx[] = {1, -1, 0, 0};
  const int dy[] = {0, 0, 1, -1};

  int H, W;
  cin >> H >> W;

  vector<string> s(H);
  forin(s);

  bool IsOk = true;
  rep(i, H) rep(j, W) {
    if (s[i][j] == '#') {
      bool IsNextOk = false;
      rep(k, 4) {
        int y = i + dy[k];
        int x = j + dx[k];
        if (x >= 0 && x < H && y >= 0 && y < W) {
          if (s[y][x] == '#')
            IsNextOk = true;
        }
      }
      if (!IsNextOk)
        IsOk = false;
    }
  }
  if (IsOk)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
/////////////////////////////////////////
///       Please Give Me AC!!!!!      ///
/////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in)                                                              \
  for (int i = 0; i < (int)in.size(); i++)                                     \
  cin >> in[i]
#define forout(out)                                                            \
  for (int i = 0; i < (int)out.size(); i++)                                    \
  cout << out[i] << endl
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  const int dx[] = {1, -1, 0, 0};
  const int dy[] = {0, 0, 1, -1};

  int H, W;
  cin >> H >> W;

  vector<string> s(H);
  forin(s);

  bool IsOk = true;
  rep(i, H) rep(j, W) {
    if (s[i][j] == '#') {
      bool IsNextOk = false;
      rep(k, 4) {
        int y = i + dy[k];
        int x = j + dx[k];
        if (x >= 0 && x < W && y >= 0 && y < H) {
          if (s[y][x] == '#')
            IsNextOk = true;
        }
      }
      if (!IsNextOk)
        IsOk = false;
    }
  }
  if (IsOk)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int x, y;
  char s[50][50];
  int i, j;
  cin >> x >> y;

  for (int k = 0; k <= y + 1; k++) {
    s[0][k] = '.';
  }
  for (i = 1; i <= x; i++) {
    s[i][0] = '.';
    for (j = 1; j <= y; j++) {
      cin >> s[i][j];
    }
    s[i][y + 1] = '.';
  }
  for (int k = 0; k <= y + 1; k++) {
    s[x + 1][k] = '.';
  }
  bool tf = true;
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      if (s[i][j] == '.')
        continue;
      if (s[i][j - 1] != '#' && s[i][j + 1] != '#' && s[i - 1][j] != '#' &&
          s[i + 1][j] != '#') {
        tf = false;
      }
    }
  }
  if (tf)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int x, y;
  char s[55][55];
  int i, j;
  cin >> x >> y;

  for (int k = 0; k <= y + 1; k++) {
    s[0][k] = '.';
  }
  for (i = 1; i <= x; i++) {
    s[i][0] = '.';
    for (j = 1; j <= y; j++) {
      cin >> s[i][j];
    }
    s[i][y + 1] = '.';
  }
  for (int k = 0; k <= y + 1; k++) {
    s[x + 1][k] = '.';
  }
  bool tf = true;
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      if (s[i][j] == '.')
        continue;
      if (s[i][j - 1] != '#' && s[i][j + 1] != '#' && s[i - 1][j] != '#' &&
          s[i + 1][j] != '#') {
        tf = false;
      }
    }
  }
  if (tf)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (Int i = 0; i < h; i++)
    cin >> s[i];
  vector<string> t(h, string(w, '.'));
  for (Int i = 0; i < h; i++) {
    for (Int j = 0; j < w; j++) {
      if (s[i][j] != '#')
        continue;
      if (j + 1 < w && s[i][j + 1] == '#') {
        t[i][j] = '#';
        t[i][j + 1] = '#';
      }
      if (i + 1 < w && s[i + 1][j] == '#') {
        t[i][j] = '#';
        t[i + 1][j] = '#';
      }
    }
  }
  cout << (s == t ? "Yes" : "No") << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (Int i = 0; i < h; i++)
    cin >> s[i];
  vector<string> t(h, string(w, '.'));
  for (Int i = 0; i < h; i++) {
    for (Int j = 0; j < w; j++) {
      if (s[i][j] != '#')
        continue;
      if (j + 1 < w && s[i][j + 1] == '#') {
        t[i][j] = '#';
        t[i][j + 1] = '#';
      }
      if (i + 1 < h && s[i + 1][j] == '#') {
        t[i][j] = '#';
        t[i + 1][j] = '#';
      }
    }
  }
  cout << (s == t ? "Yes" : "No") << endl;

  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;

const double PI = acos(-1.0);

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
  int h, w;
  cin >> h >> w;
  string s[50];
  rep(i, h) cin >> s[i];

  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '.')
        continue;

      bool find = false;
      rep(d, 4) {
        int ni = i + dy[d];
        int nj = j + dx[d];

        if (s[ni][nj] == '#')
          find = true;
      }
      if (!find) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;

const double PI = acos(-1.0);

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
  int h, w;
  cin >> h >> w;
  char s[50][50];
  rep(i, h) {
    rep(j, w) { cin >> s[i][j]; }
  }

  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '.')
        continue;

      bool find = false;
      rep(d, 4) {
        int ni = i + dy[d];
        int nj = j + dx[d];

        if (s[ni][nj] == '#')
          find = true;
      }
      if (!find) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  int num = 0;
  string board[50];
  for (int i = 0; i < h; ++i)
    cin >> board[i];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (board[i][j] == '#' && board[i][j - 1] != '#' &&
          board[i - 1][j] != '#' && board[i][j + 1] != '#' &&
          board[i + 1][j] != '#')
        num++;
    }
  }
  if (num == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  int num = 0;
  string board[50];
  for (int i = 0; i < h; ++i)
    cin >> board[i];

  for (int i = 1; i < h; ++i) {
    for (int j = 1; j < w; ++j) {

      if (board[i][j] == '#' && board[i][j - 1] != '#' &&
          board[i - 1][j] != '#' && board[i][j + 1] != '#' &&
          board[i + 1][j] != '#')
        num++;
    }
  }
  if (num == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H + 2);

  for (int i = 0; i <= H + 1; i++) {
    for (int j = 0; j <= W + 1; j++) {
      S.at(i) += ".";
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S.at(i).at(j);
    }
  }

  bool result = true;

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= H; j++) {
      if (S.at(i).at(j) == '#') {
        if (S.at(i - 1).at(j) == '.' && S.at(i).at(j - 1) == '.' &&
            S.at(i + 1).at(j) == '.' && S.at(i).at(j + 1) == '.') {
          result = false;
          break;
        }
      }
    }
  }

  if (result) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H + 2);

  for (int i = 0; i <= H + 1; i++) {
    for (int j = 0; j <= W + 1; j++) {
      S.at(i) += ".";
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S.at(i).at(j);
    }
  }

  bool result = true;

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (S.at(i).at(j) == '#') {
        if (S.at(i - 1).at(j) == '.' && S.at(i).at(j - 1) == '.' &&
            S.at(i + 1).at(j) == '.' && S.at(i).at(j + 1) == '.') {
          result = false;
          break;
        }
      }
    }
  }

  if (result) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define fi first
#define se second

using namespace std;

int main() {

  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++)
      cin >> s[i][k];
  }

  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++) {
      int c = 0;
      if (s[i][k] == '#') {
        if (i != 0 && s[i - 1][k] == '#')
          c++;
        if (i != h - 1 && s[i + 1][k] == '#')
          c++;
        if (k != 0 && s[i][k - 1] == '#')
          c++;
        if (k != w - 1 && s[i][k + 1] == '#')
          c++;
        if (c == 0) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define fi first
#define se second

using namespace std;

int main() {

  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }

  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++) {
      int c = 0;
      if (s[i][k] == '#') {
        if (i != 0 && s[i - 1][k] == '#')
          c++;
        if (i != h - 1 && s[i + 1][k] == '#')
          c++;
        if (k != 0 && s[i][k - 1] == '#')
          c++;
        if (k != w - 1 && s[i][k + 1] == '#')
          c++;
        if (c == 0) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
template <class T> // 多次元ベクトルの生成
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  int h, w;
  std::cin >> h >> w;
  auto s = make_vec<char>(h, w);
  bool han = 1;
  rep(j, h) rep(i, w) std::cin >> s[i][j];
  rep(j, h) rep(i, w) {
    {
      if (s[i][j] == '#')
        if (!(i >= 1 && s[i - 1][j] == '#' || j >= 1 && s[i][j - 1] == '#' ||
              i < w - 1 && s[i + 1][j] == '#' ||
              j < h - 1 && s[i][j + 1] == '#'))
          han = 0;
    }
  }
  if (han)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
template <class T> // 多次元ベクトルの生成
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  int h, w;
  std::cin >> h >> w;
  auto s = make_vec<char>(w, h);
  bool han = 1;
  rep(j, h) rep(i, w) std::cin >> s[i][j];
  rep(j, h) rep(i, w) {
    {
      if (s[i][j] == '#')
        if (!(i >= 1 && s[i - 1][j] == '#' || j >= 1 && s[i][j - 1] == '#' ||
              i < w - 1 && s[i + 1][j] == '#' ||
              j < h - 1 && s[i][j + 1] == '#'))
          han = 0;
    }
  }
  if (han)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
    cin >> s[i];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        if (s[i - 1][j] == '#')
          continue;
        else if (s[i + 1][j] == '#')
          continue;
        else if (s[i][j - 1] == '#')
          continue;
        else if (s[i][j + 1] == '#')
          continue;
        else {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
    cin >> s[i];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        bool f = true;
        if (i != 0)
          if (s[i - 1][j] == '#')
            f = false;
        if (i != h - 1)
          if (s[i + 1][j] == '#')
            f = false;
        if (j != 0)
          if (s[i][j - 1] == '#')
            f = false;
        if (j != w - 1)
          if (s[i][j + 1] == '#')
            f = false;
        if (f) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/11/20 07:34:59
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  vector<string> grid;
  for (auto &l : grid)
    cin >> l;
  auto solve = [&]() {
    constexpr int dir[4][2]{
        {1, 0},
        {0, 1},
        {-1, 0},
        {0, -1},
    };
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (grid[i][j] == '.')
          continue;
        bool ok = false;
        for (auto [dx, dy] : dir) {
          int x = i + dx, y = j + dy;
          if (x < 0 or x >= h or y < 0 or y >= w)
            continue;
          ok |= grid[x][y] == '#';
        }
        if (!ok) {
          return false;
        }
      }
    }
    return true;
  };
  cout << (solve() ? "Yes" : "No") << endl;

  return 0;
}


Fixed submission:
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/11/20 07:34:59
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (auto &l : grid)
    cin >> l;
  auto solve = [&]() {
    constexpr int dir[4][2]{
        {1, 0},
        {0, 1},
        {-1, 0},
        {0, -1},
    };
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (grid[i][j] == '.')
          continue;
        bool ok = false;
        for (auto [dx, dy] : dir) {
          int x = i + dx, y = j + dy;
          if (x < 0 or x >= h or y < 0 or y >= w)
            continue;
          ok |= grid[x][y] == '#';
        }
        if (!ok) {
          return false;
        }
      }
    }
    return true;
  };
  cout << (solve() ? "Yes" : "No") << endl;

  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int h, w;
  cin >> h >> w;

  vector<vector<char>> s;

  vector<char> kari;
  for (int i = 0; i < w + 2; i++) {
    kari.push_back('.');
  }
  s.push_back(kari);
  for (int i = 0; i < h; i++) {
    vector<char> gyou;
    gyou.push_back('.');
    for (int j = 0; i < w; j++) {
      char ness;
      cin >> ness;
      gyou.push_back(ness);
    }
    gyou.push_back('.');
    s.push_back(gyou);
  }
  s.push_back(kari);

  bool able = true;

  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      if (s[i][j] == '#') {
        if (s[i - 1][j] == '.' && s[i + 1][j] == '.' && s[i][j - 1] == '.' &&
            s[i][j + 1] == '.') {
          able = false;
        }
      }
    }
  }

  if (able) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int h, w;
  cin >> h >> w;

  vector<vector<char>> s;

  vector<char> kari;
  for (int i = 0; i < w + 2; i++) {
    kari.push_back('.');
  }
  s.push_back(kari);
  for (int i = 0; i < h; i++) {
    vector<char> gyou;
    gyou.push_back('.');
    for (int j = 0; j < w; j++) {
      char ness;
      cin >> ness;
      gyou.push_back(ness);
    }
    gyou.push_back('.');
    s.push_back(gyou);
  }
  s.push_back(kari);

  bool able = true;

  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      if (s[i][j] == '#') {
        if (s[i - 1][j] == '.' && s[i + 1][j] == '.' && s[i][j - 1] == '.' &&
            s[i][j + 1] == '.') {
          able = false;
        }
      }
    }
  }

  if (able) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, m, flg;
string s[55];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      cin >> s[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#' && s[i][j + 1] == '.' && s[i + 1][j] == '.' &&
          s[i - 1][j] == '.' && s[i][j - 1] == '.') {
        flg = 1;
        break;
      }
    }
  if (flg == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m, flg;
char s[55][55];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      cin >> s[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#' && s[i][j + 1] == '.' && s[i + 1][j] == '.' &&
          s[i - 1][j] == '.' && s[i][j - 1] == '.') {
        flg = 1;
        break;
      }
    }
  if (flg == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
typedef long long ll;

int main(void) {
  int i, j, k, sa = 1, h, w;
  scanf("%d%d", &h, &w);
  char s[i][j + 10];
  for (i = 0; i < h; ++i)
    scanf("%s", s[i]);
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j)
      if (s[i][j] == '#') {
        int tmp = 1;
        if (i && s[i - 1][j] == '#')
          tmp = 0;
        if (j && s[i][j - 1] == '#')
          tmp = 0;
        if (i != h - 1 && s[i + 1][j] == '#')
          tmp = 0;
        if (j != w - 1 && s[i][j + 1] == '#')
          tmp = 0;
        if (tmp)
          sa = 0;
      }
    if (!sa)
      break;
  }
  if (sa)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Fixed submission:
#include <stdio.h>
typedef long long ll;

int main(void) {
  int i, j, k, sa = 1, h, w;
  scanf("%d%d", &h, &w);
  char s[h][w + 10];
  for (i = 0; i < h; ++i)
    scanf("%s", s[i]);
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j)
      if (s[i][j] == '#') {
        int tmp = 1;
        if (i && s[i - 1][j] == '#')
          tmp = 0;
        if (j && s[i][j - 1] == '#')
          tmp = 0;
        if (i != h - 1 && s[i + 1][j] == '#')
          tmp = 0;
        if (j != w - 1 && s[i][j + 1] == '#')
          tmp = 0;
        if (tmp)
          sa = 0;
      }
    if (!sa)
      break;
  }
  if (sa)
    printf("Yes");
  else
    printf("No");
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
// typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;４近傍
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007;                       // 10^9 + 7
const double PI = 3.14159265358979323846264338327950288;

int main() {

  //==================================
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  //==================================

  int H, W;
  cin >> H >> W;
  vector<string> S;
  for (int i = 0; i < H; i++) {
    string temp;
    cin >> temp;
    S.emplace_back(temp);
  }

  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {

      if (S[i][j] == '#') {
        int count = 0;
        for (int k = 0; k < 4; k++) {
          if (0 <= i + DX[k] && i + DX[k] < H && 0 <= j + DY[k] &&
              j + DY[k] < W) {
            if (S[i + DX[k]][j + DY[k]] == '#') {
              count++;
            }
          }
        }

        if (count == 0) {
          cout << "No";
          return 0;
        }
      }
    }
  }

  cout << "Yes";
}


Fixed submission:
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
// typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;４近傍
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007;                       // 10^9 + 7
const double PI = 3.14159265358979323846264338327950288;

int main() {

  //==================================
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  //==================================

  int H, W;
  cin >> H >> W;
  vector<string> S;
  for (int i = 0; i < H; i++) {
    string temp;
    cin >> temp;
    S.emplace_back(temp);
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {

      if (S[i][j] == '#') {
        int count = 0;
        for (int k = 0; k < 4; k++) {
          if (0 <= i + DX[k] && i + DX[k] < H && 0 <= j + DY[k] &&
              j + DY[k] < W) {
            if (S[i + DX[k]][j + DY[k]] == '#') {
              count++;
            }
          }
        }

        if (count == 0) {
          cout << "No";
          return 0;
        }
      }
    }
  }

  cout << "Yes";
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
int N, M;
char A[55][55];

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++)
    scanf("%s", A[i] + 1);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (A[i][j] == '#' && (A[i - 1][j] == '.' || !(i - 1)) &&
          (A[i][j - 1] == '.' || !(j - 1)) &&
          (A[i + 1][j] == '.' || i + 1 > N) &&
          (A[i][j + 1] == '.' || j + 1 > M))
        return puts("No");
    }
  }
  puts("Yes");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
int N, M;
char A[55][55];

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++)
    scanf("%s", A[i] + 1);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (A[i][j] == '#' && (A[i - 1][j] == '.' || !(i - 1)) &&
          (A[i][j - 1] == '.' || !(j - 1)) &&
          (A[i + 1][j] == '.' || i + 1 > N) &&
          (A[i][j + 1] == '.' || j + 1 > M))
        return puts("No"), 0;
    }
  }
  puts("Yes");
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
#define REP(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 16
#define MAXC 100000000000014
#define MAXV 1000000009

int h, w;
char s[MAXN][MAXN];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, rec;

int main() {
  cin >> h >> w;
  REP(i, 0, h) {
    REP(j, 0, w) { cin >> s[i][j]; }
  }
  REP(i, 0, h) {
    REP(j, 0, w) {
      rec = 0;
      if (s[i][j] == '#') {
        REP(k, 0, 4) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (0 <= nx && nx < h && 0 <= ny && ny < w) {
            if (s[nx][ny] == '#')
              rec++;
            // printf("%d %d rec++\n", nx, ny);
          }
        }
        if (rec == 0) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
#define REP(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 51
#define MAXC 100000000000014
#define MAXV 1000000009

int h, w;
char s[MAXN][MAXN];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, rec;

int main() {
  cin >> h >> w;
  REP(i, 0, h) {
    REP(j, 0, w) { cin >> s[i][j]; }
  }
  REP(i, 0, h) {
    REP(j, 0, w) {
      rec = 0;
      if (s[i][j] == '#') {
        REP(k, 0, 4) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (0 <= nx && nx < h && 0 <= ny && ny < w) {
            if (s[nx][ny] == '#')
              rec++;
            // printf("%d %d rec++\n", nx, ny);
          }
        }
        if (rec == 0) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

int main(int argc, char const *argv[]) {
  int h, w;
  std::cin >> h >> w;

  std::vector<std::string> grid(h);
  for (auto &g : grid) {
    std::cin >> g;
  }

  for (int x = 0; x < w; ++x) {
    for (int y = 0; y < h; ++y) {
      bool e = false;
      if (grid[x][y] == '.') {
        continue;
      }
      if (x != 0) {
        e |= grid[y][x - 1] == '#';
      }
      if (y != 0) {
        e |= grid[y - 1][x] == '#';
      }
      if (x != w - 1) {
        e |= grid[y][x + 1] == '#';
      }
      if (y != h - 1) {
        e |= grid[y + 1][x] == '#';
      }
      if (!e) {
        std::cout << "No" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>

int main(int argc, char const *argv[]) {
  int h, w;
  std::cin >> h >> w;

  std::vector<std::string> grid(h);
  for (auto &g : grid) {
    std::cin >> g;
  }

  for (int x = 0; x < w; ++x) {
    for (int y = 0; y < h; ++y) {
      bool e = false;
      if (grid[y][x] == '.') {
        continue;
      }
      if (x != 0) {
        e |= grid[y][x - 1] == '#';
      }
      if (y != 0) {
        e |= grid[y - 1][x] == '#';
      }
      if (x != w - 1) {
        e |= grid[y][x + 1] == '#';
      }
      if (y != h - 1) {
        e |= grid[y + 1][x] == '#';
      }
      if (!e) {
        std::cout << "No" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int h, w, a[2550], b[2550], cnt = 0;
  fill(a, a + 2500, 100);
  cin >> h >> w;
  string s[h + 1];
  s[0] = s[h + 1] =
      "########################################################################"
      "########################################################################"
      "########################################################################"
      "#######################";
  for (int i = 0; i < h; i++) {
    s[i + 1] = "###############################################################"
               "###############################################################"
               "###############################################################"
               "##################################################";
    for (int j = 0; j < w; j++) {
      cin >> s[i + 1][j + 1];
      if (s[i + 1][j + 1] == '#')
        a[cnt] = i + 1, b[cnt] = j + 1, cnt++;
    }
  }

  for (int i = 0; i < 2550; i++) {
    if (a[i] == 100) {
      break;
    }
    if (s[a[i] - 1][b[i]] != '#' and s[a[i] + 1][b[i]] != '#' and
        s[a[i]][b[i] - 1] != '#' and s[a[i]][b[i] + 1] != '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int h, w, a[2550], b[2550], cnt = 0;
  fill(a, a + 2500, 100);
  cin >> h >> w;
  string s[h + 2];
  s[0] = s[h + 1] =
      "########################################################################"
      "########################################################################"
      "########################################################################"
      "#######################";
  for (int i = 0; i < h; i++) {
    s[i + 1] = "###############################################################"
               "###############################################################"
               "###############################################################"
               "##################################################";
    for (int j = 0; j < w; j++) {
      cin >> s[i + 1][j + 1];
      if (s[i + 1][j + 1] == '#')
        a[cnt] = i + 1, b[cnt] = j + 1, cnt++;
    }
  }

  for (int i = 0; i < 2550; i++) {
    if (a[i] == 100) {
      break;
    }
    if (s[a[i] - 1][b[i]] != '#' and s[a[i] + 1][b[i]] != '#' and
        s[a[i]][b[i] - 1] != '#' and s[a[i]][b[i] + 1] != '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 1, vector<char>(W + 1, '.'));
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      char a = S.at(i).at(j);
      if (a == '#' && S[i][j - 1] != '#' && S[i - 1][j] != '#' &&
          S[i][j + 1] != '#' && S[i + 1][j] != '#')
        cnt++;
    }
  }
  puts(cnt == 0 ? "Yes" : "No");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '.'));
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      char a = S.at(i).at(j);
      if (a == '#' && S[i][j - 1] != '#' && S[i - 1][j] != '#' &&
          S[i][j + 1] != '#' && S[i + 1][j] != '#')
        cnt++;
    }
  }
  puts(cnt == 0 ? "Yes" : "No");
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (int NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF = 1000000000000000;

int main() {
  int h, w;

  cin >> h >> w;

  vector<vector<int>> a(h + 2, vector<int>(w + 2));

  char t53;

  FOR(i, 1, h + 1) {

    FOR(j, 1, h + 1) {

      cin >> t53;
      if (t53 == '.')
        a.at(i).at(j) = 0;
      else
        a.at(i).at(j) = 1;
    }
  }

  int count;

  FOR(i, 1, h + 1) {

    FOR(j, 1, w + 1) {

      count = 0;

      if (a.at(i).at(j) == 1) {

        count += a.at(i - 1).at(j);
        count += a.at(i).at(j - 1);
        count += a.at(i).at(j + 1);
        count += a.at(i + 1).at(j);

        if (count == 0) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (int NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF = 1000000000000000;

int main() {
  int h, w;

  cin >> h >> w;

  vector<vector<int>> a(h + 2, vector<int>(w + 2));

  char t53;

  FOR(i, 1, h + 1) {

    FOR(j, 1, w + 1) {

      cin >> t53;
      if (t53 == '.')
        a.at(i).at(j) = 0;
      else
        a.at(i).at(j) = 1;
    }
  }

  int count;

  FOR(i, 1, h + 1) {

    FOR(j, 1, w + 1) {

      count = 0;

      if (a.at(i).at(j) == 1) {

        count += a.at(i - 1).at(j);
        count += a.at(i).at(j - 1);
        count += a.at(i).at(j + 1);
        count += a.at(i + 1).at(j);

        if (count == 0) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for (ll i = (k); i < (n); i++)
#define FORe(i, k, n) for (ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  REP(i, H) cin >> s[i];

  int dx[] = {0, 0, -1, 1};
  int dy[] = {1, -1, 0, 0};
  bool ok = true;
  REP(i, H) REP(j, W) {
    if (s[i][j] == '.')
      continue;
    bool f = false;
    REP(k, 4) {
      int id = i + dx[k];
      int jd = j + dy[k];
      if (id < 0 || id >= W || jd < 0 || jd >= H)
        continue;
      if (s[id][jd] == '#')
        f = true;
    }
    if (!f)
      ok = false;
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for (ll i = (k); i < (n); i++)
#define FORe(i, k, n) for (ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  REP(i, H) cin >> s[i];

  int dx[] = {0, 0, -1, 1};
  int dy[] = {1, -1, 0, 0};
  bool ok = true;
  REP(i, H) REP(j, W) {
    if (s[i][j] == '.')
      continue;
    bool f = false;
    REP(k, 4) {
      int id = i + dx[k];
      int jd = j + dy[k];
      if (id < 0 || id >= H || jd < 0 || jd >= W)
        continue;
      if (s[id][jd] == '#')
        f = true;
    }
    if (!f)
      ok = false;
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
using namespace std;
char s[51][51] = {};
int h, w;
int bfs(int y, int x) {
  int size = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(y, x));
  while (!que.empty()) {
    pair<int, int> now = que.front();
    que.pop();
    int nowx, nowy;
    nowy = now.first;
    nowx = now.second;
    s[nowy][nowx] = '.';
    size++;
    for (int i = 0; i < 4; i++) {
      int nexty = nowy + dy[i];
      int nextx = nowx + dx[i];
      if (nextx < 0 or nexty < 0 or nexty >= h or nextx >= w or
          s[nexty][nextx] == '.') {
        continue;
      } else {
        que.push(make_pair(nexty, nextx));
      }
    }
  }
  return size;
}
int main(void) {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  bool ok = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        if (bfs(i, j) <= 1) {
          ok = false;
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
using namespace std;
char s[51][51] = {};
int h, w;
int bfs(int y, int x) {
  int size = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(y, x));
  while (!que.empty()) {
    pair<int, int> now = que.front();
    que.pop();
    int nowx, nowy;
    nowy = now.first;
    nowx = now.second;
    s[nowy][nowx] = '.';
    size++;
    for (int i = 0; i < 4; i++) {
      int nexty = nowy + dy[i];
      int nextx = nowx + dx[i];
      if (nextx < 0 or nexty < 0 or nexty >= h or nextx >= w or
          s[nexty][nextx] == '.') {
        continue;
      } else {
        s[nexty][nextx] = '.';
        que.push(make_pair(nexty, nextx));
      }
    }
  }
  return size;
}
int main(void) {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  bool ok = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        if (bfs(i, j) <= 1) {
          ok = false;
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <cstdlib>
#include <iostream>

using namespace std;
int main() {
  int i, j, h, w;
  char p;
  bool canvas[50][50]; // [row][col]
  cin >> h >> w;
  for (i = 0; i <= h + 1; i++) {
    for (j = 0; j <= w + 1; j++) {
      canvas[i][j] = false;
    }
  }

  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      cin >> p;
      if (p == '#')
        canvas[i][j] = true;
      else
        canvas[i][j] = false;
    }
  }

  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      if (canvas[i][j]) {
        if (!canvas[i - 1][j] && !canvas[i + 1][j] && !canvas[i][j - 1] &&
            !canvas[i][j + 1]) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;
}

Fixed submission:
#include <cstdlib>
#include <iostream>

using namespace std;
int main() {
  int i, j, h, w;
  char p;
  bool canvas[60][60]; // [row][col]
  cin >> h >> w;
  for (i = 0; i <= h + 1; i++) {
    for (j = 0; j <= w + 1; j++) {
      canvas[i][j] = false;
    }
  }

  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      cin >> p;
      if (p == '#')
        canvas[i][j] = true;
      else
        canvas[i][j] = false;
    }
  }

  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      if (canvas[i][j]) {
        if (!canvas[i - 1][j] && !canvas[i + 1][j] && !canvas[i][j - 1] &&
            !canvas[i][j + 1]) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int>> grid(h, vector<int>(w));
  rep(i, h) rep(j, w) grid[i][j] = 0;
  rep(i, h) {
    rep(j, w) {
      rep(k, 4) {
        if (s[i][j] != '#')
          continue;
        int x = i + dx[k];
        int y = j + dy[k];

        if (x == -1 or x == w or y == -1 or y == w)
          continue;
        if (s[x][y] == '#')
          grid[i][j]++;
      }
    }
  }
  bool flag = true;
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#' and grid[i][j] == 0)
      flag = false;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int>> grid(h, vector<int>(w));
  rep(i, h) rep(j, w) grid[i][j] = 0;
  rep(i, h) {
    rep(j, w) {
      rep(k, 4) {
        if (s[i][j] != '#')
          continue;
        int x = i + dx[k];
        int y = j + dy[k];

        if (x == -1 or x == h or y == -1 or y == w)
          continue;
        if (s[x][y] == '#')
          grid[i][j]++;
      }
    }
  }
  bool flag = true;
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#' and grid[i][j] == 0)
      flag = false;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03361 (Python)

Buggy submission (status: Runtime Error):
def main():
    h, w = map(int, input().split())

    m = []
    wall = ["." for _ in range(w + 2)]
    m.append(wall)
    for _ in range(w):
        r = ["."] + list(input()) + ["."]
        m.append(r)
    m.append(wall)

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if m[i][j] == "#":
                f = any(
                    [
                        m[i + x][j + y] == "#"
                        for (x, y) in ((1, 0), (-1, 0), (0, 1), (0, -1))
                    ]
                )
                if not f:
                    print("No")
                    exit()
    else:
        print("Yes")


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    h, w = map(int, input().split())

    m = []
    wall = ["." for _ in range(w + 2)]
    m.append(wall)
    for _ in range(h):
        r = ["."] + list(input()) + ["."]
        m.append(r)
    m.append(wall)

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if m[i][j] == "#":
                f = any(
                    [
                        m[i + x][j + y] == "#"
                        for (x, y) in ((1, 0), (-1, 0), (0, 1), (0, -1))
                    ]
                )
                if not f:
                    print("No")
                    exit()
    else:
        print("Yes")


if __name__ == "__main__":
    main()
Problem p03361 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
import sys

try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    print(
        YES
        if all(
            any(
                s[y + dy][x + dx] == "#"
                for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]
                if 0 <= x + dx < W and 0 <= y + dy < H
            )
            for y in range(H)
            for x in range(W)
            if s[y][x] == "#"
        )
        else NO
    )


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    print(
        YES
        if all(
            any(
                s[y + dy][x + dx] == "#"
                for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]
                if 0 <= x + dx < W and 0 <= y + dy < H
            )
            for y in range(H)
            for x in range(W)
            if s[y][x] == "#"
        )
        else NO
    )


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == "__main__":
    main()