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

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

const int MAX_H = 2000;
const int MAX_W = 2000;
int H, W, v[MAX_H][MAX_W], h[MAX_H][MAX_W];
string M[MAX_H];

int dfs_v(int y, int x, int num) {
  if (v[y][x] != 0)
    return v[y][x];
  if (M[y][x] == '#' || y >= H)
    return num;
  return v[y][x] = dfs_v(y + 1, x, num + 1);
}

int dfs_h(int y, int x, int num) {
  if (h[y][x] != 0)
    return h[y][x];
  if (M[y][x] == '#' || x >= W)
    return num;
  return h[y][x] = dfs_h(y, x + 1, num + 1);
}

int main() {
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      v[i][j] = 0;
      h[i][j] = 0;
    }
  }
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> M[i];
  }
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      ans = max(ans, dfs_v(i, j, 0) + dfs_h(i, j, 0) - 1);
    }
  }
  cout << ans << endl;
}


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

const int MAX_H = 2010;
const int MAX_W = 2010;
int H, W, v[MAX_H][MAX_W], h[MAX_H][MAX_W];
string M[MAX_H];

int dfs_v(int y, int x, int num) {
  if (v[y][x] != 0)
    return v[y][x];
  if (M[y][x] == '#' || y >= H)
    return num;
  return v[y][x] = dfs_v(y + 1, x, num + 1);
}

int dfs_h(int y, int x, int num) {
  if (h[y][x] != 0)
    return h[y][x];
  if (M[y][x] == '#' || x >= W)
    return num;
  return h[y][x] = dfs_h(y, x + 1, num + 1);
}

int main() {
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      v[i][j] = 0;
      h[i][j] = 0;
    }
  }
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> M[i];
  }
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      ans = max(ans, dfs_v(i, j, 0) + dfs_h(i, j, 0) - 1);
    }
  }
  cout << ans << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int H, W, x = 0, y = 0;
  cin >> H >> W;
  vector<string> S(H);
  int a[200][200] = {0}, b[200][200] = {0};
  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] == '.') {
        x = 0;
        while (j + x < W && S[i][j + x] != '#')
          x++;
        while (j < W && S[i][j] != '#') {
          a[i][j] = x;
          j++;
        }
      }
    }
  }
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {

      if (S[j][i] == '.') {
        x = 0;
        while (j + x < H && S[j + x][i] != '#')
          x++;
        while (j < H && S[j][i] != '#') {
          b[j][i] = x;
          j++;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, a[i][j] + b[i][j]);
    }
  }
  cout << ans - 1 << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int H, W, x = 0, y = 0;
  cin >> H >> W;
  vector<string> S(H);
  int a[2001][2001] = {0}, b[2001][2001] = {0};
  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] == '.') {
        x = 0;
        while (j + x < W && S[i][j + x] != '#')
          x++;
        while (j < W && S[i][j] != '#') {
          a[i][j] = x;
          j++;
        }
      }
    }
  }
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {

      if (S[j][i] == '.') {
        x = 0;
        while (j + x < H && S[j + x][i] != '#')
          x++;
        while (j < H && S[j][i] != '#') {
          b[j][i] = x;
          j++;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, a[i][j] + b[i][j]);
    }
  }
  cout << ans - 1 << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
int n, m;
int s[MAXN][MAXN], s1[MAXN][MAXN];
int t[MAXN][MAXN], t1[MAXN][MAXN];
char str[MAXN][MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '.') {
        s[i][j] = s[i][j - 1] + 1;
        t[i][j] = t[i - 1][j] + 1;
      }
    }
  }
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      if (str[i][j] == '.') {
        s1[i][j] = s1[i][j + 1] + 1;
        t1[i][j] = t1[i + 1][j] +
                   1; // cout<<i<<" "<<j<<" "<<s1[i][j]<<" "<<t1[i][j]<<endl;
      }
    }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '.')
        ans = max(ans, s[i][j] + s1[i][j] + t[i][j] + t1[i][j] - 3);
    }
  }
  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4000;
int n, m;
int s[MAXN][MAXN], s1[MAXN][MAXN];
int t[MAXN][MAXN], t1[MAXN][MAXN];
char str[MAXN][MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '.') {
        s[i][j] = s[i][j - 1] + 1;
        t[i][j] = t[i - 1][j] + 1;
      }
    }
  }
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      if (str[i][j] == '.') {
        s1[i][j] = s1[i][j + 1] + 1;
        t1[i][j] = t1[i + 1][j] +
                   1; // cout<<i<<" "<<j<<" "<<s1[i][j]<<" "<<t1[i][j]<<endl;
      }
    }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '.')
        ans = max(ans, s[i][j] + s1[i][j] + t[i][j] + t1[i][j] - 3);
    }
  }
  cout << ans;

  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

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];
  }

  vector<vector<int>> L(H, vector<int>(W));
  vector<vector<int>> R(H, vector<int>(W));
  vector<vector<int>> U(H, vector<int>(W));
  vector<vector<int>> D(H, vector<int>(W));

  for (int i = 0; i < H; i++) {
    int cnt = 0;
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      L[i][j] = cnt;
    }
  }

  for (int i = 0; i < H; i++) {
    int cnt = 0;
    for (int j = W - 1; j >= 0; j--) {
      if (S[i][j] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      R[i][j] = cnt;
    }
  }

  for (int i = 0; i < W; i++) {
    int cnt = 0;
    for (int j = 0; j < H; j++) {
      if (S[j][i] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      U[j][i] = cnt;
    }
  }

  for (int i = 0; i < W; i++) {
    int cnt = 0;
    for (int j = H - 1; j >= 0; j--) {
      if (S[j][i] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      D[i][j] = cnt;
    }
  }

  int max_sum = 0;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int c = U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3;
      max_sum = max(c, max_sum);
    }
  }

  cout << max_sum << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

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];
  }

  vector<vector<int>> L(H, vector<int>(W));
  vector<vector<int>> R(H, vector<int>(W));
  vector<vector<int>> U(H, vector<int>(W));
  vector<vector<int>> D(H, vector<int>(W));

  for (int i = 0; i < H; i++) {
    int cnt = 0;
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      L[i][j] = cnt;
    }
  }

  for (int i = 0; i < H; i++) {
    int cnt = 0;
    for (int j = W - 1; j >= 0; j--) {
      if (S[i][j] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      R[i][j] = cnt;
    }
  }

  for (int i = 0; i < W; i++) {
    int cnt = 0;
    for (int j = 0; j < H; j++) {
      if (S[j][i] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      U[j][i] = cnt;
    }
  }

  for (int i = 0; i < W; i++) {
    int cnt = 0;
    for (int j = H - 1; j >= 0; j--) {
      if (S[j][i] == '#') {
        cnt = 0;
      } else {
        cnt++;
      }
      D[j][i] = cnt;
    }
  }

  int max_sum = 0;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int c = U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3;
      max_sum = max(c, max_sum);
    }
  }

  cout << max_sum << endl;
  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll h, w, a, b;
  in2(h, w);
  vector<vector<char>> c(h, vector<char>(w));
  vector<vector<ll>> d(h, vector<ll>(w, 0));
  rep(i, h) { rep(j, w) in(c[i][j]); }
  rep(i, h) {
    a = 0;
    while (a < w) {
      while (c[i][a] == '#') {
        a++;
        if (a == w)
          break;
      }
      if (a == w)
        break;
      b = a;
      if (b != w - 1) {
        while (c[i][b + 1] == '.') {
          b++;
          if (b == w - 1)
            break;
        }
      }
      rep2(j, a, b + 1) d[i][j] += b - a + 1;
      a = b + 1;
    }
  }
  rep(i, w) {
    a = 0;
    while (a < h) {
      while (c[a][i] == '#') {
        a++;
        if (a == h)
          break;
      }
      if (a == h)
        break;
      b = a;
      if (b != w - 1) {
        while (c[b + 1][i] == '.') {
          b++;
          if (b == h - 1)
            break;
        }
      }
      rep2(j, a, b + 1) d[j][i] += b - a + 1;
      a = b + 1;
    }
  }
  a = 0;
  rep(i, h) { rep(j, w) a = max(a, d[i][j]); }
  out(a - 1);
  memi;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll h, w, a, b;
  in2(h, w);
  vector<vector<char>> c(h, vector<char>(w));
  vector<vector<ll>> d(h, vector<ll>(w, 0));
  rep(i, h) { rep(j, w) in(c[i][j]); }
  rep(i, h) {
    a = 0;
    while (a < w) {
      while (c[i][a] == '#') {
        a++;
        if (a == w)
          break;
      }
      if (a == w)
        break;
      b = a;
      if (b != w - 1) {
        while (c[i][b + 1] == '.') {
          b++;
          if (b == w - 1)
            break;
        }
      }
      rep2(j, a, b + 1) d[i][j] += b - a + 1;
      a = b + 1;
    }
  }
  rep(i, w) {
    a = 0;
    while (a < h) {
      while (c[a][i] == '#') {
        a++;
        if (a == h)
          break;
      }
      if (a == h)
        break;
      b = a;
      if (b != h - 1) {
        while (c[b + 1][i] == '.') {
          b++;
          if (b == h - 1)
            break;
        }
      }
      rep2(j, a, b + 1) d[j][i] += b - a + 1;
      a = b + 1;
    }
  }
  a = 0;
  rep(i, h) { rep(j, w) a = max(a, d[i][j]); }
  out(a - 1);
  memi;
}
Problem p03014 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  int a[2003][2003];
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) {
      if (s[j] == '#')
        a[i][j] = 0;
      else
        a[i][j] = 1;
    }
  }
  int ans = 0;
  int cc = 1;
  int tt = 0;
  rep(i, h) rep(j, w) {
    int tmp = 0;
    if (a[i][j] == 1) {
      ++tmp;
      cc = 1;
      while (a[i - cc][j] == 1 && i - cc >= 0) {
        ++tmp;
        ++cc;
      }
      cc = 1;
      while (a[i + cc][j] == 1 && i + cc <= h - 1) {
        ++tmp;
        ++cc;
      }
      cc = 1;
      while (a[i][j - cc] == 1 && j - cc >= 0) {
        ++tmp;
        ++cc;
      }
      cc = 1;
      while (a[i][j + cc] == 1 && j + cc <= w - 1) {
        ++tmp;
        ++cc;
      }
    }
    ans = max(ans, tmp);
    ++tt;
    if (ans >= 1960 && tt >= 1000000)
      break;
  }
  cout << ans << 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;

int main() {
  int h, w;
  cin >> h >> w;
  int a[2003][2003];
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) {
      if (s[j] == '#')
        a[i][j] = 0;
      else
        a[i][j] = 1;
    }
  }
  int ans = 0;
  int cc = 1;
  int tt = 0;
  rep(i, h) rep(j, w) {
    int tmp = 0;
    if (a[i][j] == 1) {
      ++tmp;
      cc = 1;
      while (a[i - cc][j] == 1 && i - cc >= 0) {
        ++tmp;
        ++cc;
      }
      cc = 1;
      while (a[i + cc][j] == 1 && i + cc <= h - 1) {
        ++tmp;
        ++cc;
      }
      cc = 1;
      while (a[i][j - cc] == 1 && j - cc >= 0) {
        ++tmp;
        ++cc;
      }
      cc = 1;
      while (a[i][j + cc] == 1 && j + cc <= w - 1) {
        ++tmp;
        ++cc;
      }
    }
    ans = max(ans, tmp);
    ++tt;
    if (ans >= 1960 && tt >= 100000)
      break;
  }
  cout << ans << endl;
  return 0;
}
Problem p03014 (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, f, s, k, ans = 0;
  cin >> h >> w;
  char a[h][w];
  int b[h][w];
  fill((int *)b, (int *)b[h], 0);
  rep(i, h) scanf("%s", a[i]);
  rep(i, h) {
    f = -1;
    s = 0;
    rep(j, w) {
      if (a[i][j] == '.') {
        if (b[i][j] == 0) {
          k = i;
          while (a[k][j] == '.' && k < h) {
            k++;
          }
          for (int l = i; l < k; l++) {
            b[l][j] = k - i;
          }
        }
        if (f < j) {
          k = j;
          while (a[i][k] == '.' && k < w) {
            k++;
          }
          f = k;
          s = k - j;
        }
        ans = max(ans, b[i][j] + s);
      }
    }
  }
  cout << ans - 1;
}


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, f, s, k, ans = 0;
  cin >> h >> w;
  char a[h + 10][w + 10];
  int b[h][w];
  fill((int *)b, (int *)b[h], 0);
  rep(i, h) scanf("%s", a[i]);
  rep(i, h) {
    f = -1;
    s = 0;
    rep(j, w) {
      if (a[i][j] == '.') {
        if (b[i][j] == 0) {
          k = i;
          while (a[k][j] == '.' && k < h) {
            k++;
          }
          for (int l = i; l < k; l++) {
            b[l][j] = k - i;
          }
        }
        if (f < j) {
          k = j;
          while (a[i][k] == '.' && k < w) {
            k++;
          }
          f = k;
          s = k - j;
        }
        ans = max(ans, b[i][j] + s);
      }
    }
  }
  cout << ans - 1;
}
Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007  // 10^9+7
#define INF 99999999999 // 10^12-1
#define dev 998244353   // tenka1
#define P pair<int, int>
#define F first
#define S second
int w, h, ans = 0;
char c[4000][4000];
int l[4000][4000], r[4000][4000];
int u[4000][4000], d[4000][4000];
signed main() {
  cin >> h >> w;
  rep(i, h) {
    rep(j, w) { cin >> c[i][j]; }
  }
  rep(i, h) {
    rep(j, w) {
      if (c[i][j] == '#')
        continue;
      int x = i;
      while (x >= 0 && c[x][j] == '.') {
        u[i][j]++;
        x--;
      }
      x = i;
      while (x < h && c[x][j] == '.') {
        d[i][j]++;
        x++;
      }
      int y = j;
      while (y >= 0 && c[i][y] == '.') {
        l[i][j]++;
        y--;
      }
      y = j;
      while (y < w && c[i][y] == '.') {
        r[i][j]++;
        y++;
      }
    }
  }
  rep(i, h) {
    rep(j, w) { ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3); }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007  // 10^9+7
#define INF 99999999999 // 10^12-1
#define dev 998244353   // tenka1
#define P pair<int, int>
#define F first
#define S second
int w, h, ans = 0;
char c[4000][4000];
int l[4000][4000], r[4000][4000];
int u[4000][4000], d[4000][4000];
signed main() {
  cin >> h >> w;
  rep(i, h) {
    rep(j, w) { cin >> c[i][j]; }
  }
  rep(i, h) {
    rep(j, w) {
      if (c[i][j] == '#')
        continue;
      if (j == 0)
        l[i][j] = 1;
      else
        l[i][j] = l[i][j - 1] + 1;
    }
  }
  rep(i, h) {
    for (int j = w - 1; j >= 0; j--) {
      if (c[i][j] == '#')
        continue;
      if (j == w - 1)
        r[i][j] = 1;
      else
        r[i][j] = r[i][j + 1] + 1;
    }
  }
  rep(i, w) {
    rep(j, h) {
      if (c[j][i] == '#')
        continue;
      if (j == 0)
        u[j][i] = 1;
      else
        u[j][i] = u[j - 1][i] + 1;
    }
  }
  rep(i, w) {
    for (int j = h - 1; j >= 0; j--) {
      if (c[j][i] == '#')
        continue;
      if (j == h - 1)
        d[j][i] = 1;
      else
        d[j][i] = d[j + 1][i] + 1;
    }
  }
  rep(i, h) {
    rep(j, w) { ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3); }
  }
  cout << ans << endl;
  return 0;
}
Problem p03014 (Python)

Buggy submission (status: Runtime Error):
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy
    up = s.copy
    down = s.copy
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy()
    up = s.copy()
    down = s.copy()
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


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

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

try:
    from typing import List
except ImportError:
    pass


def solve(H: int, W: int, S: "List[str]"):
    d = [[0] * W for _ in range(H)]
    for y in range(H):
        x = 0
        while x < W:
            while x < W and S[y][x] == "#":
                x += 1
            xstt = x
            while x < W and S[y][x] == ".":
                x += 1
            xend = x
            for x2 in range(xstt, xend):
                d[y][x2] += xend - xstt
    for x in range(H):
        y = 0
        while y < H:
            while y < H and S[y][x] == "#":
                y += 1
            ystt = y
            while y < H and S[y][x] == ".":
                y += 1
            yend = y
            for y2 in range(ystt, yend):
                d[y2][x] += yend - ystt

    print(max(max(r) for r in d) - 1)


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()


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

try:
    from typing import List
except ImportError:
    pass


def solve(H: int, W: int, S: "List[str]"):
    d = [[0] * W for _ in range(H)]
    for y in range(H):
        x = 0
        while x < W:
            while x < W and S[y][x] == "#":
                x += 1
            xstt = x
            while x < W and S[y][x] == ".":
                x += 1
            xend = x
            for x2 in range(xstt, xend):
                d[y][x2] += xend - xstt
    for x in range(W):
        y = 0
        while y < H:
            while y < H and S[y][x] == "#":
                y += 1
            ystt = y
            while y < H and S[y][x] == ".":
                y += 1
            yend = y
            for y2 in range(ystt, yend):
                d[y2][x] += yend - ystt

    print(max(max(r) for r in d) - 1)


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()
Problem p03014 (Python)

Buggy submission (status: Time Limit Exceeded):
H, W = map(int, input().split())
MAP = [[] for _ in range(H)]
L = [[[] for h in range(W)] for _ in range(H)]
R = [[[] for h in range(W)] for _ in range(H)]
D = [[[] for h in range(W)] for _ in range(H)]
U = [[[] for h in range(W)] for _ in range(H)]

for i in range(H):
    MAP[i] = list(input())

for i in range(H):
    for j in range(W):
        if MAP[i][j] == "#":
            L[i][j] = 0
        elif j == 0:
            L[i][j] = 1
        else:
            L[i][j] = L[i][j - 1] + 1

        if MAP[i][W - j - 1] == "#":
            R[i][W - j - 1] = 0
        elif j == 0:
            R[i][W - j - 1] = 1
        else:
            R[i][W - j - 1] = R[i][W - j] + 1

for j in range(W):
    for i in range(H):
        if MAP[i][j] == "#":
            U[i][j] = 0
        elif i == 0:
            U[i][j] = 1
        else:
            U[i][j] = U[i - 1][j] + 1

        if MAP[H - i - 1][j] == "#":
            D[H - i - 1][j] = 0
        elif i == 0:
            D[H - i - 1][j] = 1
        else:
            D[H - i - 1][j] = D[H - i][j] + 1
result = 0
for i in range(H):
    for j in range(W):
        result = max(result, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)

print(result)


Fixed submission:
H, W = map(int, input().split())
MAP = [list(input()) for _ in range(H)]
L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if MAP[i][j] == "#":
            L[i][j] = 0
        elif j == 0:
            L[i][j] = 1
        else:
            L[i][j] = L[i][j - 1] + 1

        if MAP[i][W - j - 1] == "#":
            R[i][W - j - 1] = 0
        elif j == 0:
            R[i][W - j - 1] = 1
        else:
            R[i][W - j - 1] = R[i][W - j] + 1

for j in range(W):
    for i in range(H):
        if MAP[i][j] == "#":
            U[i][j] = 0
        elif i == 0:
            U[i][j] = 1
        else:
            U[i][j] = U[i - 1][j] + 1

        if MAP[H - i - 1][j] == "#":
            D[H - i - 1][j] = 0
        elif i == 0:
            D[H - i - 1][j] = 1
        else:
            D[H - i - 1][j] = D[H - i][j] + 1
result = 0
for i in range(H):
    for j in range(W):
        result = max(result, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)

print(result)
Problem p03014 (Python)

Buggy submission (status: Runtime Error):
from collections import defaultdict


H, W = map(int, input().split())
mass = list()
for i in range(H):
    mass.append(input())

values_col = defaultdict(int)
values_row = defaultdict(int)

ind_row = [[0 for i in range(H)] for j in range(W)]
ind_col = [[0 for i in range(H)] for j in range(W)]

ind = 0
for i, m_row in enumerate(mass):
    ind += 1
    for j, chr in enumerate(mass[i]):
        if chr == "#":
            ind += 1
        else:
            values_row[ind] += 1
            ind_row[i][j] = ind

# print('ROW')
# for i in range(H):
#     for j in range(W):
#         print(values_row[ind_row[i][j]], end=' ')
#     print()

ind = 0
for j in range(W):
    ind += 1
    for i in range(H):
        chr = mass[i][j]
        if chr == "#":
            ind += 1
        else:
            values_col[ind] += 1
            ind_col[i][j] = ind

# print('COL')
# for i in range(H):
#     for j in range(W):
#         print(values_col[ind_col[i][j]], end=' ')
#     print()

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1)
print(ans)


Fixed submission:
from collections import defaultdict


H, W = map(int, input().split())
mass = list()
for i in range(H):
    mass.append(input())

values_col = defaultdict(int)
values_row = defaultdict(int)

ind_row = [[0 for i in range(W)] for j in range(H)]
ind_col = [[0 for i in range(W)] for j in range(H)]

ind = 0
for i, m_row in enumerate(mass):
    ind += 1
    for j, chr in enumerate(mass[i]):
        if chr == "#":
            ind += 1
        else:
            values_row[ind] += 1
            ind_row[i][j] = ind

# print('ROW')
# for i in range(H):
#     for j in range(W):
#         print(values_row[ind_row[i][j]], end=' ')
#     print()

ind = 0
for j in range(W):
    ind += 1
    for i in range(H):
        chr = mass[i][j]
        if chr == "#":
            ind += 1
        else:
            values_col[ind] += 1
            ind_col[i][j] = ind

# print('COL')
# for i in range(H):
#     for j in range(W):
#         print(values_col[ind_col[i][j]], end=' ')
#     print()

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1)
print(ans)
Problem p03014 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np

h, w = map(int, input().split())
grid = [[False for j in range(w)] for i in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == ".":
            grid[i][j] = 1
        else:
            grid[i][j] = 0

grid = np.array(grid)

L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)

for j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]


nums = []
for i in range(h):
    for j in range(w):
        nums.append(L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)

print(np.max(L + R + U + D - 3))


Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = [[False for j in range(w)] for i in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == ".":
            grid[i][j] = 1
        else:
            grid[i][j] = 0

grid = np.array(grid)

L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)

for j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

print(np.max(L + R + U + D - 3))
Problem p03014 (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.at(i);
  }

  vector<vector<int>> cnt(h, vector<int>(w));

  for (int i = 0; i < h; i++) {
    vector<int> done(w);
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '#') {
        continue;
      }
      if (done.at(j)) {
        continue;
      }
      int l = 0;
      while ((j + l) < w) {
        if (s.at(i).at(j + l) == '#') {
          break;
        }
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt.at(i).at(j + k) += l;
        done.at(j + k) = 1;
      }
    }
  }

  for (int j = 0; j < w; j++) {
    vector<int> done(h);
    for (int i = 0; i < h; i++) {
      if (s.at(i).at(j) == '#') {
        continue;
      }
      if (done.at(i)) {
        continue;
      }
      int l = 0;
      while ((i + l) < w) {
        if (s.at(i + l).at(j) == '#') {
          break;
        }
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt.at(i + k).at(j) += l;
        done.at(i + k) = 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cnt.at(i).at(j) - 1);
    }
  }
  cout << ans << 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.at(i);
  }

  vector<vector<int>> cnt(h, vector<int>(w));

  for (int i = 0; i < h; i++) {
    vector<int> done(w);
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '#') {
        continue;
      }
      if (done.at(j)) {
        continue;
      }
      int l = 0;
      while ((j + l) < w) {
        if (s.at(i).at(j + l) == '#') {
          break;
        }
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt.at(i).at(j + k) += l;
        done.at(j + k) = 1;
      }
    }
  }

  for (int j = 0; j < w; j++) {
    vector<int> done(h);
    for (int i = 0; i < h; i++) {
      if (s.at(i).at(j) == '#') {
        continue;
      }
      if (done.at(i)) {
        continue;
      }
      int l = 0;
      while ((i + l) < h) {
        if (s.at(i + l).at(j) == '#') {
          break;
        }
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt.at(i + k).at(j) += l;
        done.at(i + k) = 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cnt.at(i).at(j) - 1);
    }
  }
  cout << ans << endl;
}
Problem p03014 (C++)

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

int H, W;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define WMAX 200
#define HMAX WMAX
char s[HMAX][WMAX];
int dp[HMAX][WMAX][4]; // dp[i][j][k] (0:right 1:down 2:left 3:up)

int dfs(int x, int y, int k) {
  if (s[y][x] == '#')
    return 0;
  if (dp[y][x][k] != -1)
    return dp[y][x][k];
  int nx = x + dx[k];
  int ny = y + dy[k];
  if (0 <= nx && nx < W && 0 <= ny && ny < H && s[ny][nx] != '#') {
    int num = dfs(nx, ny, k) + 1;
    dp[y][x][k] = num;
    return num;
  }
  dp[y][x][k] = 0;
  return 0;
}

int main() {
  int res = 0;
  cin >> H >> W;

  rep(i, H) cin >> s[i];
  memset(dp, -1, sizeof dp);

  rep(y, H) {
    rep(x, W) {
      int sum = 0;
      rep(k, 4) { sum += dfs(x, y, k); }
      if (s[y][x] != '#')
        sum++;
      res = max(sum, res);
      // printf("%3d ", sum);
    }
    // cout << endl;
  }

  cout << res << endl;
}


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

int H, W;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define WMAX 2001
#define HMAX WMAX
char s[HMAX][WMAX];
int dp[HMAX][WMAX][4]; // dp[i][j][k] (0:right 1:down 2:left 3:up)

int dfs(int x, int y, int k) {
  if (s[y][x] == '#')
    return 0;
  if (dp[y][x][k] != -1)
    return dp[y][x][k];
  int nx = x + dx[k];
  int ny = y + dy[k];
  if (0 <= nx && nx < W && 0 <= ny && ny < H && s[ny][nx] != '#') {
    int num = dfs(nx, ny, k) + 1;
    dp[y][x][k] = num;
    return num;
  }
  dp[y][x][k] = 0;
  return 0;
}

int main() {
  int res = 0;
  cin >> H >> W;

  rep(i, H) cin >> s[i];
  memset(dp, -1, sizeof dp);

  rep(y, H) {
    rep(x, W) {
      int sum = 0;
      rep(k, 4) { sum += dfs(x, y, k); }
      if (s[y][x] != '#')
        sum++;
      res = max(sum, res);
      // printf("%3d ", sum);
    }
    // cout << endl;
  }

  cout << res << endl;
}
Problem p03014 (C++)

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

using namespace std;

typedef long long ll;

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

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

  vector<vector<char>> S(H, vector<char>(W));
  vector<vector<pair<int, int>>> B(H, vector<pair<int, int>>(W));

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

  vector<int> c(H * W);

  int num = 0;
  int count = 0;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        c[num] = count;
        count = 0;
        num++;
      } else {
        count++;
        B[i][j].first = num;
      }
    }

    c[num] = count;
    count = 0;
    num++;
  }

  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (S[j][i] == '#') {
        c[num] = count;
        count = 0;
        num++;
      } else {
        count++;
        B[j][i].second = num;
      }
    }

    c[num] = count;
    count = 0;
    num++;
  }

  int max = 0;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int x = c[B[i][j].first] + c[B[i][j].second];
      if (x > max)
        max = x;
    }
  }

  cout << max - 1 << endl;
}

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

using namespace std;

typedef long long ll;

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

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

  vector<vector<char>> S(H, vector<char>(W));
  vector<vector<pair<int, int>>> B(H, vector<pair<int, int>>(W));

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

  vector<int> c(H * W * 3);

  int num = 0;
  int count = 0;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        c[num] = count;
        count = 0;
        num++;
      } else {
        count++;
        B[i][j].first = num;
      }
    }

    c[num] = count;
    count = 0;
    num++;
  }

  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (S[j][i] == '#') {
        c[num] = count;
        count = 0;
        num++;
      } else {
        count++;
        B[j][i].second = num;
      }
    }

    c[num] = count;
    count = 0;
    num++;
  }

  int max = 0;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int x = c[B[i][j].first] + c[B[i][j].second];
      if (x > max)
        max = x;
    }
  }

  cout << max - 1 << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int H, W, ans = 0, v[20][20] = {}, k = 0, n = 0;
  char masu[21][21];
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    k = 0;
    n = 0;
    for (int j = 0; j < W; j++) {
      cin >> masu[i][j];
      if (masu[i][j] == '.')
        k++;
      else {
        for (int l = 0; l < k; l++) {
          v[i][n] += k;
          n++;
        }
        n = n + 1;
        k = 0;
      }
    }
    if (masu[i][W - 1] == '.') {
      for (int l = 0; l < k; l++) {
        v[i][n] += k;
        n++;
      }
      n = n + 1;
      k = 0;
    }
  }
  for (int i = 0; i < W; i++) {
    k = 0;
    n = 0;
    for (int j = 0; j < H; j++) {
      if (masu[j][i] == '.')
        k++;
      else {
        for (int l = 0; l < k; l++) {
          v[n][i] += k;
          n++;
        }
        n = n + 1;
        k = 0;
      }
    }
    if (masu[H - 1][i] == '.') {
      for (int l = 0; l < k; l++) {
        v[n][i] += k;
        n++;
      }
      k = 0;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(v[i][j], ans);
      // cout << v[i][j] << " ";
    }
    // cout << endl;
  }
  cout << ans - 1;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int H, W, ans = 0, v[2001][2001] = {}, k = 0, n = 0;
  char masu[2001][2001];
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    k = 0;
    n = 0;
    for (int j = 0; j < W; j++) {
      cin >> masu[i][j];
      if (masu[i][j] == '.')
        k++;
      else {
        for (int l = 0; l < k; l++) {
          v[i][n] += k;
          n++;
        }
        n = n + 1;
        k = 0;
      }
    }
    if (masu[i][W - 1] == '.') {
      for (int l = 0; l < k; l++) {
        v[i][n] += k;
        n++;
      }
      n = n + 1;
      k = 0;
    }
  }
  for (int i = 0; i < W; i++) {
    k = 0;
    n = 0;
    for (int j = 0; j < H; j++) {
      if (masu[j][i] == '.')
        k++;
      else {
        for (int l = 0; l < k; l++) {
          v[n][i] += k;
          n++;
        }
        n = n + 1;
        k = 0;
      }
    }
    if (masu[H - 1][i] == '.') {
      for (int l = 0; l < k; l++) {
        v[n][i] += k;
        n++;
      }
      k = 0;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(v[i][j], ans);
      // cout << v[i][j] << " ";
    }
    // cout << endl;
  }
  cout << ans - 1;
}
Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int n, m;
char a[2005][2005];
int ans = 0;

int main() {
  scanf("%d%d", &n, &m);
  int ma = n + m - 1;
  for (int i = 0; i < n; i++)
    scanf("%s", a[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int s = 1;
      if (a[i][j] == '.') {
        for (int k = j - 1; k >= 0; k--)
          if (a[i][k] == '.')
            s++;
          else
            break;
        for (int k = j + 1; k < m; k++)
          if (a[i][k] == '.')
            s++;
          else
            break;
        for (int l = i - 1; l >= 0; l--)
          if (a[l][j] == '.')
            s++;
          else
            break;
        for (int l = i + 1; l < n; l++)
          if (a[l][j] == '.')
            s++;
          else
            break;
        ans = max(s, ans);
      }
    }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

int n, m;
char a[2005][2005];
int ans = 0;

int main() {
  scanf("%d%d", &n, &m);
  int ma = n + m - 1;
  for (int i = 0; i < n; i++)
    scanf("%s", a[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int s = 1;
      if (a[i][j] == '.') {
        for (int k = j - 1; k >= 0; k--)
          if (a[i][k] == '.')
            s++;
          else
            break;
        for (int k = j + 1; k < m; k++)
          if (a[i][k] == '.')
            s++;
          else
            break;
        for (int l = i - 1; l >= 0; l--)
          if (a[l][j] == '.')
            s++;
          else
            break;
        for (int l = i + 1; l < n; l++)
          if (a[l][j] == '.')
            s++;
          else
            break;
        ans = max(s, ans);
        if (ans == ma)
          break;
      }
    }
  printf("%d\n", ans);
  return 0;
}
Problem p03014 (C++)

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

int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }

  int maxcnt = 0;
  int temp;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#')
        continue;
      temp = 1;
      for (int ii = i - 1; ii >= 0; ii--) {
        if (S[ii][j] == '#')
          break;
        temp++;
      }
      for (int ii = i + 1; ii <= H - 1; ii++) {
        if (S[ii][j] == '#')
          break;
        temp++;
      }
      for (int jj = j - 1; jj >= 0; jj--) {
        if (S[i][jj] == '#')
          break;
        temp++;
      }
      for (int jj = j + 1; jj <= W - 1; jj++) {
        if (S[i][jj] == '#')
          break;
        temp++;
      }
      maxcnt = max(maxcnt, temp);
    }
  }
  cout << maxcnt << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }

  int maxcnt = 0;
  int temp;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#')
        continue;
      temp = 1;
      for (int ii = i - 1; ii >= 0; ii--) {
        if (S[ii][j] == '#')
          break;
        temp++;
      }
      for (int ii = i + 1; ii <= H - 1; ii++) {
        if (S[ii][j] == '#')
          break;
        temp++;
      }
      for (int jj = j - 1; jj >= 0; jj--) {
        if (S[i][jj] == '#')
          break;
        temp++;
      }
      for (int jj = j + 1; jj <= W - 1; jj++) {
        if (S[i][jj] == '#')
          break;
        temp++;
      }
      maxcnt = max(maxcnt, temp);
      if (maxcnt == W + H - 1)
        break;
    }
  }
  cout << maxcnt << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, a, b) for (ll i = a; i < b; i++)
const int max_n = 1e5;
const ll mod = 1e9 + 7;
typedef long double ld;
int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  rep(i, 0, h) cin >> s[i];
  int d[2005][2005];
  rep(i, 0, h) rep(j, 0, w) d[i][j] = 0;
  int ma = 0;
  rep(i, 0, h) rep(j, 0, w) {
    if ((j - 1 < 0 || s[i][j - 1] == '#') && s[i][j] == '.') {
      int k = j;
      while (s[i][j] == s[i][k] && k < w)
        k++;
      rep(t, j, k) {
        d[i][t] += k - j - 1;
        ma = max(ma, d[i][t]);
      }
    }
    if ((i - 1 < 0 || s[i - 1][j] == '#') && s[i][j] == '.') {
      int k = i;
      while (s[i][j] == s[k][j] && k < h)
        k++;
      rep(t, i, k) {
        d[t][j] += k - i;
        ma = max(ma, d[t][j]);
      }
    }
  }
  cout << ma << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, a, b) for (ll i = a; i < b; i++)
const int max_n = 1e5;
const ll mod = 1e9 + 7;
typedef long double ld;
int main() {
  int h, w;
  cin >> h >> w;
  string s[h + 5];
  rep(i, 0, h) cin >> s[i];
  int d[2005][2005];
  rep(i, 0, h) rep(j, 0, w) d[i][j] = 0;
  int ma = 0;
  rep(i, 0, h) rep(j, 0, w) {
    if ((j - 1 < 0 || s[i][j - 1] == '#') && s[i][j] == '.') {
      int k = j;
      while (s[i][j] == s[i][k] && k < w)
        k++;
      rep(t, j, k) {
        d[i][t] += k - j - 1;
        ma = max(ma, d[i][t]);
      }
    }
    if ((i - 1 < 0 || s[i - 1][j] == '#') && s[i][j] == '.') {
      int k = i;
      while (s[i][j] == s[k][j] && k < h)
        k++;
      rep(t, i, k) {
        d[t][j] += k - i;
        ma = max(ma, d[t][j]);
      }
    }
  }
  cout << ma << endl;
  return 0;
}
Problem p03014 (C++)

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

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  vector<vector<int>> ans_h(h, vector<int>(w, 0));
  vector<vector<int>> ans_w(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    cin >> s[i];
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      int cnt = 0;
      while (j + cnt < w && s[i][j + cnt] == '.')
        cnt++;
      for (int k = j; k < j + cnt; k++)
        ans_w[i][k] = cnt;
      j += cnt - 1;
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (s[j][i] == '#')
        continue;
      int cnt = 0;
      while (j + cnt < w && s[j + cnt][i] == '.')
        cnt++;
      for (int k = j; k < j + cnt; k++)
        ans_h[k][i] = cnt;
      j += cnt - 1;
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, ans_w[i][j] + ans_h[i][j] - 1);
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  vector<vector<int>> ans_h(h, vector<int>(w, 0));
  vector<vector<int>> ans_w(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    cin >> s[i];
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      int cnt = 0;
      while (j + cnt < w && s[i][j + cnt] == '.')
        cnt++;
      for (int k = j; k < j + cnt; k++)
        ans_w[i][k] = cnt;
      j += cnt - 1;
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (s[j][i] == '#')
        continue;
      int cnt = 0;
      while (j + cnt < h && s[j + cnt][i] == '.')
        cnt++;
      for (int k = j; k < j + cnt; k++)
        ans_h[k][i] = cnt;
      j += cnt - 1;
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, ans_w[i][j] + ans_h[i][j] - 1);
    }
  }

  cout << ans << endl;
}