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

Buggy submission (status: Runtime Error):
def solve(field):
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if field[i][j] == ".":
                continue
            if (
                field[i - 1][j]
                == field[i + 1][j]
                == field[i][j - 1]
                == field[i][j + 1]
                == "."
            ):
                return False
    return True


h, w = list(map(int, input().split()))
field = ["." + input() + "." for _ in range(h)]
field = ["." * w] + field + ["." * w]
print("Yes" if solve(field) else "No")


Fixed submission:
def solve(field):
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if field[i][j] == ".":
                continue
            if (
                field[i - 1][j]
                == field[i + 1][j]
                == field[i][j - 1]
                == field[i][j + 1]
                == "."
            ):
                return False
    return True


h, w = list(map(int, input().split()))
field = ["." + input() + "." for _ in range(h)]
field = ["." * (w + 2)] + field + ["." * (w + 2)]
print("Yes" if solve(field) else "No")
Problem p03361 (Python)

Buggy submission (status: Runtime Error):
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    field = []
    for row in inputs:
        line = []
        for c in row:
            line.append(c)
        field.append(line)

    if len(field) == 1:
        if len(field[0]) == 1:
            return "No"

    for i, row in enumerate(field):
        for j, _ in enumerate(row):
            available = False
            if field[i][j] == ".":
                continue
            if i - 1 >= 0:
                available |= field[i - 1][j] == "#"

            if j - 1 >= 0:
                available |= field[i][j - 1] == "#"
            if j + 1 < len(row):
                available |= field[i][j + 1] == "#"

            if i + 1 < len(row):
                available |= field[i + 1][j] == "#"
            if not available:
                return "No"

    return "Yes"


if __name__ == "__main__":
    [N, _] = map(lambda x: int(x), input().split())
    ret = solve(inputs(N))
    print(ret)


Fixed submission:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    field = []
    for row in inputs:
        line = []
        for c in row:
            line.append(c)
        field.append(line)

    if len(field) == 1:
        if len(field[0]) == 1:
            return "No"

    for i, row in enumerate(field):
        for j, _ in enumerate(row):
            available = False
            if field[i][j] == ".":
                continue
            if i - 1 >= 0:
                available |= field[i - 1][j] == "#"

            if j - 1 >= 0:
                available |= field[i][j - 1] == "#"
            if j + 1 < len(row):
                available |= field[i][j + 1] == "#"

            if i + 1 < len(field):
                available |= field[i + 1][j] == "#"
            if not available:
                return "No"

    return "Yes"


if __name__ == "__main__":
    [N, _] = map(lambda x: int(x), input().split())
    ret = solve(inputs(N))
    print(ret)
Problem p03361 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  string s[50];
  for (int i = 1; i <= H; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= H; i++) {
    s[i] = "." + s[i] + ".";
  }
  for (int i = 0; i <= W + 1; i++) {
    s[0] = s[0] + ".";
    s[H + 1] = s[H + 1] + ".";
  }

  bool flag = true;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (s[i][j] == '#' && s[i][j + 1] == '.' && s[i][j - 1] == '.' &&
          s[i - 1][j] == '.' && s[i + 1][j] == '.') {
        flag = false;
      }
    }
  }

  /*for (int i = 0; i <= H + 1; i++){
      cout << s[i] << endl;
  }*/

  if (flag == true) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string s[100];
  for (int i = 1; i <= H; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= H; i++) {
    s[i] = "." + s[i] + ".";
  }
  for (int i = 0; i <= W + 1; i++) {
    s[0] = s[0] + ".";
    s[H + 1] = s[H + 1] + ".";
  }

  bool flag = true;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (s[i][j] == '#' && s[i][j + 1] == '.' && s[i][j - 1] == '.' &&
          s[i - 1][j] == '.' && s[i + 1][j] == '.') {
        flag = false;
      }
    }
  }

  /*for (int i = 0; i <= H + 1; i++){
      cout << s[i] << endl;
  }*/

  if (flag == true) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
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 pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\n"

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

  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (int i = 0; i < H; i++)
    cin >> s[i];
  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      bool ok = false;
      if (s[j][i] == '#') {
        for (int k = 0; k < 4; k++) {
          int X = j + dx[k];
          int Y = i + dy[k];
          if (0 <= X && X < W && 0 <= Y && Y < H && s[Y][X] == '#')
            ok = true;
        }
        if (!ok) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\n"

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

  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (int i = 0; i < H; i++)
    cin >> s[i];
  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      bool ok = false;
      if (s[i][j] == '#') {
        for (int k = 0; k < 4; k++) {
          int X = j + dx[k];
          int Y = i + dy[k];
          if (0 <= X && X < W && 0 <= Y && Y < H && s[Y][X] == '#')
            ok = true;
        }
        if (!ok) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << 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<vector<char>> grid(H + 2, vector<char>(W + 2));

  for (int j = 0; j < W + 2; j++) {
    grid.at(0).at(j) = '.';
  }
  for (int i = 1; i <= H; i++) {
    grid.at(i).at(0) = '.';
    for (int j = 1; j <= W; j++) {
      cin >> grid.at(i).at(j);
    }
    grid.at(i).at(W + 1) = '.';
  }
  for (int j = 0; j < W + 2; j++) {
    grid.at(H + 1).at(j) = '.';
  }

  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < H + 1; j++) {
      if (grid.at(i).at(j) == '#' && grid.at(i - 1).at(j) == '.' &&
          grid.at(i + 1).at(j) == '.' && grid.at(i).at(j - 1) == '.' &&
          grid.at(i).at(j + 1) == '.') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H + 2, vector<char>(W + 2));

  for (int j = 0; j < W + 2; j++) {
    grid.at(0).at(j) = '.';
  }
  for (int i = 1; i <= H; i++) {
    grid.at(i).at(0) = '.';
    for (int j = 1; j <= W; j++) {
      cin >> grid.at(i).at(j);
    }
    grid.at(i).at(W + 1) = '.';
  }
  for (int j = 0; j < W + 2; j++) {
    grid.at(H + 1).at(j) = '.';
  }

  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      if (grid.at(i).at(j) == '#' && grid.at(i - 1).at(j) == '.' &&
          grid.at(i + 1).at(j) == '.' && grid.at(i).at(j - 1) == '.' &&
          grid.at(i).at(j + 1) == '.') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03361 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  char c[53][53];

  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      cin >> c[i][j];

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' &&
          c[i][j + 1] != '#' && c[i + 1][j] != '#') {
        cout << "No" << endl;
        return 1;
      }
    }
  }
  cout << "Yes" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  char c[53][53];

  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      cin >> c[i][j];

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' &&
          c[i][j + 1] != '#' && c[i + 1][j] != '#') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}
Problem p03361 (C++)

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

const string YES = "Yes";
const string NO = "No";
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, 1, -1, 0};

int solve(long long H, long long W, std::vector<std::string> S) {
  for (int i = 0; i < H; i++) // y
  {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < 4; k++) {
        long long x = j + dx[k];
        long long y = i + dy[k];

        if (x < 0 || x >= W)
          continue;
        if (y < 0 || y >= H)
          continue;

        if (S[i][j] == '#' && S[y][x] == '#') {
          break;
        } else if (S[i][j] == '#' && k == 3) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
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 < W; i++) {
    std::cin >> S[i];
  }
  solve(H, W, std::move(S));
  return 0;
}


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

const string YES = "Yes";
const string NO = "No";
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, 1, -1, 0};

int solve(long long H, long long W, std::vector<std::string> S) {
  for (int i = 0; i < H; i++) // y
  {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < 4; k++) {
        long long x = j + dx[k];
        long long y = i + dy[k];

        if (x < 0 || x >= W)
          continue;
        if (y < 0 || y >= H)
          continue;

        if (S[i][j] == '#' && S[y][x] == '#') {
          break;
        } else if (S[i][j] == '#' && k == 3) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
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;
}
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;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using vc2 = vector<vector<char>>;
int H;
int W;
v1 mh = {-1, 0, 0, 1};
v1 mw = {0, -1, 1, 0};

void paint(vc2 &s, int h, int w) {
  if (s.at(h).at(w) == '.')
    return;
  rep(i, 4) {
    int nh = h + mh.at(i);
    int nw = w + mw.at(i);
    if (nh >= H || nw >= W || nh < 0 || nw < 0)
      continue;
    if (s.at(nh).at(nw) == '#') {
      s.at(h).at(w) = 'b';
      s.at(nh).at(nw) = 'b';
    }
  }
}

int main() {
  cin >> H >> W;
  vc2 s(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) { cin >> s.at(i).at(j); }
  }
  rep(i, H) {
    rep(j, H) { paint(s, i, j); }
  }
  rep(i, H) {
    rep(j, W) {
      if (s.at(i).at(j) == '#') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using vc2 = vector<vector<char>>;
int H;
int W;
v1 mh = {-1, 0, 0, 1};
v1 mw = {0, -1, 1, 0};

void paint(vc2 &s, int h, int w) {
  if (s.at(h).at(w) == '.')
    return;
  rep(i, 4) {
    int nh = h + mh.at(i);
    int nw = w + mw.at(i);
    if (nh >= H || nw >= W || nh < 0 || nw < 0)
      continue;
    if (s.at(nh).at(nw) == '#') {
      s.at(h).at(w) = 'b';
      s.at(nh).at(nw) = 'b';
    }
  }
}

int main() {
  cin >> H >> W;
  vc2 s(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) { cin >> s.at(i).at(j); }
  }
  rep(i, H) {
    rep(j, W) { paint(s, i, j); }
  }
  rep(i, H) {
    rep(j, W) {
      if (s.at(i).at(j) == '#') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed << setprecision(n)
#define mm(o, k) memset(o, k, sizeof o)
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
const int maxn = 55;
int a[maxn][maxn];
int main() {
  IO;
  int n, m;
  cin >> n >> m;
  mm(a, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char x;
      cin >> x;
      a[i][j] = x == '#';
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] && !a[i][j + 1] && !a[i][j - 1] && !a[i + 1][j] &&
          !a[i - 1][j])
        exit(puts("No"));
  puts("Yes");
  re 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed << setprecision(n)
#define mm(o, k) memset(o, k, sizeof o)
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
const int maxn = 55;
int a[maxn][maxn];
int main() {
  IO;
  int n, m;
  cin >> n >> m;
  mm(a, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char x;
      cin >> x;
      a[i][j] = x == '#';
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] && !a[i][j + 1] && !a[i][j - 1] && !a[i + 1][j] &&
          !a[i - 1][j])
        re cout << "No\n", 0;
  puts("Yes");
  re 0;
}
Problem p03361 (C++)

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

int main() {
  int H, W;
  int v_d[4] = {-1, 0, 0, 1};
  int h_d[4] = {0, -1, 1, 0};
  cin >> H >> W;
  Grid grid(H);
  for (int i = 0; i < H; ++i) {
    cin >> grid.at(i);
  }
  bool is_paintable = true;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < H; ++j) {
      if (grid.at(i).at(j) == '.')
        continue;
      int count = 0;
      for (int k = 0; k < 4; ++k) {
        int n_i = i + v_d[k];
        int n_j = j + h_d[k];
        if (n_i < 0 || H <= n_i || n_j < 0 || W <= n_j)
          continue;
        if (grid.at(n_i).at(n_j) == '#')
          ++count;
      }
      if (count == 0) {
        is_paintable = false;
        break;
      }
    }
  }
  if (is_paintable)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  int H, W;
  int v_d[4] = {-1, 0, 0, 1};
  int h_d[4] = {0, -1, 1, 0};
  cin >> H >> W;
  Grid grid(H);
  for (int i = 0; i < H; ++i) {
    cin >> grid.at(i);
  }
  bool is_paintable = true;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (grid.at(i).at(j) == '.')
        continue;
      int count = 0;
      for (int k = 0; k < 4; ++k) {
        int n_i = i + v_d[k];
        int n_j = j + h_d[k];
        if (n_i < 0 || H <= n_i || n_j < 0 || W <= n_j)
          continue;
        if (grid.at(n_i).at(n_j) == '#')
          ++count;
      }
      if (count == 0) {
        is_paintable = false;
        break;
      }
    }
  }
  if (is_paintable)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03361 (C++)

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

using namespace std;

int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> s;
  s.push_back(string(W + 2, '.'));
  for (int i = 0; i < H; i++) {
    string x;
    cin >> x;
    s.push_back("." + x + ".");
  }
  s.push_back(string(W + 2, '.'));

  for (int i = 1; i <= W; i++) {
    for (int j = 1; j <= H; j++) {
      if (s[i][j] == '#' && s[i][j + 1] == '.' && s[i][j - 1] == '.' &&
          s[i + 1][j] == '.' && s[i - 1][j] == '.') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> s;
  s.push_back(string(W + 2, '.'));
  for (int i = 0; i < H; i++) {
    string x;
    cin >> x;
    s.push_back("." + x + ".");
  }
  s.push_back(string(W + 2, '.'));

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (s[i][j] == '#' && s[i][j + 1] == '.' && s[i][j - 1] == '.' &&
          s[i + 1][j] == '.' && s[i - 1][j] == '.') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int>>
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  string s[H];
  rep(i, 0, H) cin >> s[i];

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

  rep(i, 0, H) rep(j, 0, W) {
    if (s[j][i] == '#') {
      bool flag = true;
      rep(k, 0, 4) {
        int nx = j + dx[k];
        int ny = i + dy[k];
        if (0 <= nx and nx < W and 0 <= ny and ny < H) {
          if (s[ny][nx] == '#')
            flag = false;
        }
      }

      if (flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int>>
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  string s[H];
  rep(i, 0, H) cin >> s[i];

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

  rep(i, 0, H) rep(j, 0, W) {
    if (s[i][j] == '#') {
      bool flag = true;
      rep(k, 0, 4) {
        int nx = j + dx[k];
        int ny = i + dy[k];
        if (0 <= nx and nx < W and 0 <= ny and ny < H) {
          if (s[ny][nx] == '#')
            flag = false;
        }
      }

      if (flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

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

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ld long double
#define al(a) (a).begin(), (a).end()
#define mk make_pair
#define check cout << "?" << endl;

ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;

int main() {
  int h, w;
  cin >> h >> w;
  string ans = "Yes";
  vector<vector<char>> m(h + 1, vector<char>(w + 1, '.'));
  vector<vector<int>> d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  rep(i, h) rep(j, w) { cin >> m[i + 1][j + 1]; }
  rep(i, h) rep(j, w) {
    if (m[i + 1][j + 1] == '.')
      continue;
    int cnt = 0, dx, dy;
    for (auto c : d) {
      dx = c[0];
      dy = c[1];
      if (m[i + 1 + dx][j + 1 + dy] == '.')
        cnt++;
    }
    if (cnt == 4) {
      ans = "No";
    }
  }
  cout << ans << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ld long double
#define al(a) (a).begin(), (a).end()
#define mk make_pair
#define check cout << "?" << endl;

ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;

int main() {
  int h, w;
  cin >> h >> w;
  string ans = "Yes";
  vector<vector<char>> m(h + 2, vector<char>(w + 2, '.'));
  vector<vector<int>> d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  rep(i, h) rep(j, w) { cin >> m[i + 1][j + 1]; }
  rep(i, h) rep(j, w) {
    if (m[i + 1][j + 1] == '.')
      continue;
    int cnt = 0, dx, dy;
    for (auto c : d) {
      dx = c[0];
      dy = c[1];
      if (m[i + 1 + dx][j + 1 + dy] == '.')
        cnt++;
    }
    if (cnt == 4) {
      ans = "No";
    }
  }
  cout << ans << endl;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// void substring_dfs(vector < int, int > substring){

//}
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};

int main(int argc, const char *argv[]) {
  // insert code here...

  int n, m;
  cin >> n >> m;

  vector<string> map;

  for (int i = 0; i < m; i++) {
    string temp;
    cin >> temp;
    map.push_back(temp);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {

      if (map[i][j] == '#') {
        bool hantei_d = false;
        for (int k = 0; k < 4; k++) {
          int x = i + di[k];
          int y = j + dj[k];
          if (x >= 0 && y >= 0 && x < n && y < m && map[x][y] == '#') {
            hantei_d = true;
            break;
          }
        }
        if (hantei_d == false) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// void substring_dfs(vector < int, int > substring){

//}
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};

int main(int argc, const char *argv[]) {
  // insert code here...

  int n, m;
  cin >> n >> m;

  vector<string> map;

  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    map.push_back(temp);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {

      if (map[i][j] == '#') {
        bool hantei_d = false;
        for (int k = 0; k < 4; k++) {
          int x = i + di[k];
          int y = j + dj[k];
          if (x >= 0 && y >= 0 && x < n && y < m && map[x][y] == '#') {
            hantei_d = true;
            break;
          }
        }
        if (hantei_d == false) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;

  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)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>; // vi <=> vl
using P = pair<int, int>; // int <=> ll
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

void solve() {
  int H, W;
  cin >> H >> W;
  vector<string> G(H + 2, "..");
  rep(i, W) G[0].push_back('.');
  rep(i, W) G[W + 1].push_back('.');
  string s;
  rep(i, H) {
    cin >> s;
    G[i + 1].insert(1, s);
  }

  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (G[i][j] == '.')
        continue;
      if (G[i - 1][j] == '#')
        continue;
      if (G[i + 1][j] == '#')
        continue;
      if (G[i][j - 1] == '#')
        continue;
      if (G[i][j + 1] == '#')
        continue;
      cout << "No\n";
      return;
    }
  }

  cout << "Yes\n";
  return;
}

int main() {
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>; // vi <=> vl
using P = pair<int, int>; // int <=> ll
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

void solve() {
  int H, W;
  cin >> H >> W;
  vector<string> G(H + 2, "..");
  rep(i, W) G[0].push_back('.');
  rep(i, W) G[H + 1].push_back('.');
  string s;
  rep(i, H) {
    cin >> s;
    G[i + 1].insert(1, s);
  }

  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (G[i][j] == '.')
        continue;
      if (G[i - 1][j] == '#')
        continue;
      if (G[i + 1][j] == '#')
        continue;
      if (G[i][j - 1] == '#')
        continue;
      if (G[i][j + 1] == '#')
        continue;
      cout << "No\n";
      return;
    }
  }

  cout << "Yes\n";
  return;
}

int main() {
  solve();
  return 0;
}
Problem p03361 (C++)

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

int main(void) {
  int H, W;
  cin >> H >> W;
  string S[50];

  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

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

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] != '#')
        continue;

      int k;
      for (k = 0; k < 4; k++) {
        int ni = i + dy[k];
        int nj = j + dx[k];

        if (S[ni][nj] == '#')
          break;
      }
      if (k == 4) {
        can = false;
      }
    }
    if (!can)
      break;
  }

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

  return 0;
}

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

int main(void) {
  int H, W;
  cin >> H >> W;
  string S[50];

  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

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

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] != '#')
        continue;

      int k;
      for (k = 0; k < 4; k++) {
        int ni = i + dy[k];
        int nj = j + dx[k];

        if (ni < 0 || ni >= H)
          continue;
        if (nj < 0 || nj >= W)
          continue;
        if (S[ni][nj] == '#')
          break;
      }
      if (k == 4) {
        can = false;
      }
    }
    if (!can)
      break;
  }

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

  return 0;
}
Problem p03361 (C++)

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

int sum(int n) {
  if (n == 0) {
    return 0;
  }

  int s = sum(n - 1);
  return s + n;
}
int main() {
  int N, W;
  cin >> N >> W;
  vector<vector<char>> A(N, vector<char>(W));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < W; i++) {
      cin >> A.at(i).at(j);
    }
  }
  bool hantei = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < W; j++) {
      if (j > 0 && j < (W - 1) && i > 0 && i < (N - 1) &&
          A.at(i).at(j) == '#' && A.at(i + 1).at(j) == '.' &&
          A.at(i - 1).at(j) == '.' && A.at(i).at(j + 1) == '.' &&
          A.at(i).at(j - 1) == '.') {
        hantei = false;
        break;
      }
    }
    if (hantei == false) {
      break;
    }
  }
  if (hantei) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Fixed submission:
#include <iostream>
#include <vector>
// #define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;

int sum(int n) {
  if (n == 0) {
    return 0;
  }

  int s = sum(n - 1);
  return s + n;
}
int main() {
  int N, W;
  cin >> N >> W;
  vector<vector<char>> A(N, vector<char>(W));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  bool hantei = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < W; j++) {
      if (j > 0 && j < (W - 1) && i > 0 && i < (N - 1) &&
          A.at(i).at(j) == '#' && A.at(i + 1).at(j) == '.' &&
          A.at(i - 1).at(j) == '.' && A.at(i).at(j + 1) == '.' &&
          A.at(i).at(j - 1) == '.') {
        hantei = false;
        break;
      }
    }
    if (hantei == false) {
      break;
    }
  }
  if (hantei) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p03361 (C++)

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

using namespace std;
int main() {
  int H, W;
  int res = 0;
  int fail = 0;
  string S[3000];
  cin >> H >> W;
  for (int n = 1; n <= H; n++) {
    for (int i = 1; i <= W; i++)
      cin >> S[n][i];
  }
  for (int n = 1; n <= H; n++) {
    for (int i = 1; i <= W; i++)
      if (S[n][i] == '#') {
        if (S[n + 1][i] != '#' && S[n - 1][i] != '#' && S[n][i + 1] != '#' &&
            S[n][i - 1] != '#') {
          fail = 1;
        }
      }
  }

  if (fail == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

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

using namespace std;
int main() {
  int H, W;
  int res = 0;
  int fail = 0;
  char S[55][55];
  cin >> H >> W;
  for (int n = 1; n <= H; n++) {
    for (int i = 1; i <= W; i++)
      cin >> S[n][i];
  }
  for (int n = 1; n <= H; n++) {
    for (int i = 1; i <= W; i++)
      if (S[n][i] == '#') {
        if (S[n + 1][i] != '#' && S[n - 1][i] != '#' && S[n][i + 1] != '#' &&
            S[n][i - 1] != '#') {
          fail = 1;
        }
      }
  }

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

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

int H, W;
vector<vector<int>> s;

vector<vector<int>> moves = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

bool paintable(int i, int j) {
  s[i][j] = 0;
  bool res = false;
  for (auto d : moves) {
    int ni = i + d[0], nj = j + d[1];
    printf("%d %d\n", ni, nj);
    if (ni >= 0 && ni < H && nj >= 0 && nj < W) {
      res = true;
      paintable(ni, nj);
    }
  }
  return res;
}

int main() {
  cin >> H >> W;
  s.resize(H, vector<int>(W));

  rep(i, H) rep(j, W) {
    char c;
    cin >> c;
    s[i][j] = (c == '#');
  }

  rep(i, H) rep(j, W) {
    if (s[i][j] && !paintable(i, j)) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

int H, W;
vector<vector<int>> s;

vector<vector<int>> moves = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

bool paintable(int i, int j) {
  s[i][j] = 0;
  bool res = false;
  for (auto d : moves) {
    int ni = i + d[0], nj = j + d[1];
    if (ni >= 0 && ni < H && nj >= 0 && nj < W && s[ni][nj]) {
      res = true;
      paintable(ni, nj);
    }
  }
  return res;
}

int main() {
  cin >> H >> W;
  s.resize(H, vector<int>(W));

  rep(i, H) rep(j, W) {
    char c;
    cin >> c;
    s[i][j] = (c == '#');
  }

  rep(i, H) rep(j, W) {
    if (s[i][j] && !paintable(i, j)) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << 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 = 1; i < H + 1; i++)
    cin >> S[i];

  // banpei
  for (int i = 0; i < W + 2; i++) {
    S[0] = ".";
    S[H + 1] = ".";
  }
  for (int i = 1; i < H + 1; i++) {
    S[i] = "." + S[i] + ".";
  }

  string ans = "Yes";
  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      if (S[i][j] == '#') {
        if (S[i - 1][j] != '#' && S[i + 1][j] != '#' && S[i][j - 1] != '#' &&
            S[i][j + 1] != '#')
          ans = "No";
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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 = 1; i < H + 1; i++)
    cin >> S[i];

  // banpei
  for (int i = 0; i < W + 2; i++) {
    S[0][i] = '.';
    S[H + 1][i] = '.';
  }
  for (int i = 1; i < H + 1; i++) {
    S[i] = "." + S[i] + ".";
  }

  string ans = "Yes";
  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      if (S[i][j] == '#') {
        if (S[i - 1][j] != '#' && S[i + 1][j] != '#' && S[i][j - 1] != '#' &&
            S[i][j + 1] != '#')
          ans = "No";
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03361 (C++)

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

int main() {
  int H, W;
  std::cin >> H >> W;

  char canvas[H][W];
  for (int i = 0; i <= H + 1; i++) {
    for (int j = 0; j <= W + 1; j++) {
      if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
        canvas[i][j] = 0;
      } else {
        std::cin >> canvas[i][j];
      }
    }
  }

  bool result = true;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (canvas[i][j] == '#' && canvas[i - 1][j] != '#' &&
          canvas[i + 1][j] != '#' && canvas[i][j - 1] != '#' &&
          canvas[i][j + 1] != '#') {
        result = false;
        break;
      }
    }
  }

  std::cout << (result ? "Yes" : "No") << std::endl;

  return 0;
}


Fixed submission:
#include <iostream>

int main() {
  int H, W;
  std::cin >> H >> W;

  char canvas[H + 2][W + 2];
  for (int i = 0; i <= H + 1; i++) {
    for (int j = 0; j <= W + 1; j++) {
      if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
        canvas[i][j] = 0;
      } else {
        std::cin >> canvas[i][j];
      }
    }
  }

  bool result = true;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (canvas[i][j] == '#' && canvas[i - 1][j] != '#' &&
          canvas[i + 1][j] != '#' && canvas[i][j - 1] != '#' &&
          canvas[i][j + 1] != '#') {
        result = false;
        break;
      }
    }
  }

  std::cout << (result ? "Yes" : "No") << std::endl;

  return 0;
}
Problem p03361 (C++)

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

using namespace std;

vector<pair<int, int>> d(4);

int H, W;

void check(int h, int w, vector<vector<char>> &V, vector<vector<bool>> &C,
           int &ptr) {
  // 黒の連結成分に含まれる黒の数をadjにpush_back
  ptr++;
  for (int i = 0; i < 4; i++) {
    int hp = 0;
    hp = h + d[i].first;
    int wp = 0;
    wp = w + d[i].second;
    if (wp < 0 || wp > W - 1 || hp < 0 || hp > H - 1)
      continue;
    if (C[hp][wp])
      continue;
    if (V[hp][wp] == '#') {
      C[hp][wp] = true;
      check(hp, wp, V, C, ptr);
    }
  }
  return;
}

int main() {
  d[0] = make_pair(1, 0);
  d[1] = make_pair(0, 1);
  d[2] = make_pair(-1, 0);
  d[3] = make_pair(0, -1);

  cin >> H >> W;
  vector<vector<char>> V(H, vector<char>(W, 'x'));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> V[i][j];
    }
  }
  vector<int> adj;
  vector<vector<bool>> C(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (C[i][j])
        continue;
      if (V[i][j] == '#') {
        int cnt = 0;
        check(i, j, V, C, cnt);
        adj.push_back(cnt);
      }
      C[i][j] = true;
    }
  }
  sort(adj.begin(), adj.end());
  if (adj[0] <= 1)
    cout << "No";
  else
    cout << "Yes";
}


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

using namespace std;

vector<pair<int, int>> d(4);

int H, W;

void check(int h, int w, vector<vector<char>> &V, vector<vector<bool>> &C,
           int &ptr) {
  // 黒の連結成分に含まれる黒の数をadjにpush_back
  ptr++;
  for (int i = 0; i < 4; i++) {
    int hp = 0;
    hp = h + d[i].first;
    int wp = 0;
    wp = w + d[i].second;
    if (wp < 0 || wp > W - 1 || hp < 0 || hp > H - 1)
      continue;
    if (C[hp][wp])
      continue;
    if (V[hp][wp] == '#') {
      C[hp][wp] = true;
      check(hp, wp, V, C, ptr);
    }
  }
  return;
}

int main() {
  d[0] = make_pair(1, 0);
  d[1] = make_pair(0, 1);
  d[2] = make_pair(-1, 0);
  d[3] = make_pair(0, -1);

  cin >> H >> W;
  vector<vector<char>> V(H, vector<char>(W, 'x'));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> V[i][j];
    }
  }
  vector<int> adj;
  vector<vector<bool>> C(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (C[i][j])
        continue;
      if (V[i][j] == '#') {
        int cnt = 0;
        check(i, j, V, C, cnt);
        adj.push_back(cnt);
      }
      C[i][j] = true;
    }
  }
  sort(adj.begin(), adj.end());
  if (adj.size() > 0 && adj[0] <= 1)
    cout << "No";
  else
    cout << "Yes";
}
Problem p03361 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  char a[n][m];
  for (int i = 0; i < m + 2; i++) {
    a[0][i] = '.';
    a[n + 1][i] = '.';
  }
  for (int i = 0; i < n + 2; i++) {
    a[i][0] = '.';
    a[i][m + 1] = '.';
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      cin >> a[i][j];
    }
  }
  bool ans = true;
  for (int i = 0; i < n + 2; i++) {
    for (int j = 0; j < n + 2; j++) {
      if (a[i][j] == '#') {
        if (a[i - 1][j] == '.' && a[i + 1][j] == '.' && a[i][j - 1] == '.' &&
            a[i][j + 1] == '.') {
          ans = false;
        }
      }
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  char a[n + 2][m + 2];
  for (int i = 0; i < m + 2; i++) {
    a[0][i] = '.';
    a[n + 1][i] = '.';
  }
  for (int i = 0; i < n + 2; i++) {
    a[i][0] = '.';
    a[i][m + 1] = '.';
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      cin >> a[i][j];
    }
  }
  bool ans = true;
  for (int i = 0; i < n + 2; i++) {
    for (int j = 0; j < n + 2; j++) {
      if (a[i][j] == '#') {
        if (a[i - 1][j] == '.' && a[i + 1][j] == '.' && a[i][j - 1] == '.' &&
            a[i][j + 1] == '.') {
          ans = false;
        }
      }
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}
Problem p03361 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  char s[w + 2][h + 2];

  fill(s[0], s[h + 2], '.');

  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      cin >> s[j][i];

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

  put("Yes");
}

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

int main() {
  int h, w;
  cin >> h >> w;
  char s[w + 2][h + 2];

  fill(s[0], s[w + 2], '.');

  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      cin >> s[j][i];

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

  put("Yes");
}
Problem p03361 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  char jooj[H][W];
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cin >> jooj[i][j];
      // branco = .
      // preto = #
    }
  }

  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (jooj[i][j] == '#' and jooj[i + 1][j] == '.' and
          jooj[i][j + 1] == '.' and jooj[i - 1][j] == '.' and
          jooj[i][j - 1] == '.') {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  char jooj[H + 2][W + 2];
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cin >> jooj[i][j];
      // branco = .
      // preto = #
    }
  }

  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (jooj[i][j] == '#' and jooj[i + 1][j] == '.' and
          jooj[i][j + 1] == '.' and jooj[i - 1][j] == '.' and
          jooj[i][j - 1] == '.') {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
typedef long long ll;
typedef long double ld;
int main() {
  ll h, w;
  cin >> h >> w;
  vector<vector<char>> s(50, vector<char>(50));
  // 読み込み
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
    }
  }
  ll count = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j] == '#' && s[i][j - 1] == '.' && s[i - 1][j] == '.' &&
          s[i + 1][j] == '.' && s[i][j + 1] == '.') {
        count++;
      }
    }
  }
  if (count > 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
typedef long long ll;
typedef long double ld;
int main() {
  ll h, w;
  cin >> h >> w;
  vector<vector<char>> s(52, vector<char>(52));
  // 読み込み
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
    }
  }
  ll count = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j] == '#' && s[i][j - 1] == '.' && s[i - 1][j] == '.' &&
          s[i + 1][j] == '.' && s[i][j + 1] == '.') {
        count++;
      }
    }
  }
  if (count > 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }

  return 0;
}
Problem p03361 (C++)

Buggy submission (status: Runtime Error):
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#define all(x) (x).begin(), (x).end()

void solve() {}
int main() {
  int h, w;

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

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

  bool can = true;
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++) {
      if (s[i][k] != '#') {
        continue;
      }
      int cnt = 0;
      bool found = false;
      for (int p = 0; p < 4; p++) {
        const int x = k + dx[p];
        const int y = i + dy[p];
        if (x >= 0 && x < w && y >= 0 && y < h) {
          if (s[y][x] == '#') {
            found = true;
          }
        }
      }
      if (found != true) {
        cout << "No" << endl;
        exit(1);
      }
    }
  }

  cout << "Yes" << endl;
  /*if (can) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }
  */
  return 0;
}


Fixed submission:
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#define all(x) (x).begin(), (x).end()

void solve() {}
int main() {
  int h, w;

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

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

  bool can = true;
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++) {
      if (s[i][k] != '#') {
        continue;
      }
      int cnt = 0;
      bool found = false;
      for (int p = 0; p < 4; p++) {
        const int x = k + dx[p];
        const int y = i + dy[p];
        if (x >= 0 && x < w && y >= 0 && y < h) {
          if (s[y][x] == '#') {
            found = true;
          }
        }
      }
      if (found != true) {
        cout << "No" << endl;
        exit(0);
      }
    }
  }

  cout << "Yes" << endl;
  /*if (can) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }
  */
  return 0;
}