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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<string, int> P;
const ll MOD = 1e9 + 7;
string s[2000];
int irui[2000][2000];
int jrui[2000][2000];
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> s[i];
  for (int i = 0; i < h; i++) {
    if (s[i][0] == '.')
      jrui[i][0] = 1;
  }
  for (int i = 0; i < w; i++)
    if (s[0][i] == '.')
      irui[0][i] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (s[i][j] == '#')
        jrui[i][j] = 0;
      else
        jrui[i][j] = jrui[i][j - 1] + 1;
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = 1; i < h; i++) {
      if (s[i][j] == '#')
        irui[i][j] = 0;
      else
        irui[i][j] = irui[i - 1][j] + 1;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = w - 2; j > -1; j--) {
      if (jrui[i][j] > 0 && jrui[i][j + 1] > 0)
        jrui[i][j] = jrui[i][j + 1];
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = h - 2; i > -1; i--) {
      if (irui[i][j] > 0 && irui[i + 1][j] > 0)
        irui[i][j] = irui[i + 1][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      cerr << jrui[i][j] << " ";
    cerr << endl;
  }
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (s[i][j] == '.')
        ans = max(ans, irui[i][j] + jrui[i][j] - 1);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<string, int> P;
const ll MOD = 1e9 + 7;
string s[2000];
int irui[2000][2000];
int jrui[2000][2000];
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> s[i];
  for (int i = 0; i < h; i++) {
    if (s[i][0] == '.')
      jrui[i][0] = 1;
  }
  for (int i = 0; i < w; i++)
    if (s[0][i] == '.')
      irui[0][i] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (s[i][j] == '#')
        jrui[i][j] = 0;
      else
        jrui[i][j] = jrui[i][j - 1] + 1;
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = 1; i < h; i++) {
      if (s[i][j] == '#')
        irui[i][j] = 0;
      else
        irui[i][j] = irui[i - 1][j] + 1;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = w - 2; j > -1; j--) {
      if (jrui[i][j] > 0 && jrui[i][j + 1] > 0)
        jrui[i][j] = jrui[i][j + 1];
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = h - 2; i > -1; i--) {
      if (irui[i][j] > 0 && irui[i + 1][j] > 0)
        irui[i][j] = irui[i + 1][j];
    }
  }
  /*
  for(int i=0;i<h;i++)
  {
          for(int j=0;j<w;j++)
                  cerr<<jrui[i][j]<<" ";
          cerr<<endl;
  }*/
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (s[i][j] == '.')
        ans = max(ans, irui[i][j] + jrui[i][j] - 1);
  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 (long long int i = 0; i < n; ++i)
typedef long long int ll;

int main() {

  int h, w;
  cin >> h >> w;
  vector<string> s(h);

  rep(i, h) { cin >> s[i]; }

  vector<vector<int>> r(h, vector<int>(w, 0)), l(h, vector<int>(w, 0));
  vector<vector<int>> u(w, vector<int>(h, 0)), d(w, vector<int>(h, 0));

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j == 0 || s[i][j - 1] == '#') {
        l[i][j] = 0;
      } else {
        l[i][j] = l[i][j - 1] + 1;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = w - 1; j >= 0; j--) {
      if (j == w - 1 || s[i][j + 1] == '#') {
        r[i][j] = 0;
      } else {
        r[i][j] = r[i][j + 1] + 1;
      }
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (j == 0 || s[j - 1][i] == '#') {
        u[j][i] = 0;
      } else {
        u[j][i] = u[j - 1][i] + 1;
      }
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = h - 1; j >= 0; j--) {
      if (j == h - 1 || s[j + 1][i] == '#') {
        d[j][i] = 0;
      } else {
        d[j][i] = d[j + 1][i] + 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] != '#') {
        int tt;
        tt = u[i][j] + d[i][j] + l[i][j] + r[i][j];
        tt++;
        ans = max(tt, ans);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {

  int h, w;
  cin >> h >> w;
  vector<string> s(h);

  rep(i, h) { cin >> s[i]; }

  vector<vector<int>> r(h, vector<int>(w, 0)), l(h, vector<int>(w, 0));
  vector<vector<int>> u(h, vector<int>(w, 0)), d(h, vector<int>(w, 0));

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j == 0 || s[i][j - 1] == '#') {
        l[i][j] = 0;
      } else {
        l[i][j] = l[i][j - 1] + 1;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = w - 1; j >= 0; j--) {
      if (j == w - 1 || s[i][j + 1] == '#') {
        r[i][j] = 0;
      } else {
        r[i][j] = r[i][j + 1] + 1;
      }
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (j == 0 || s[j - 1][i] == '#') {
        u[j][i] = 0;
      } else {
        u[j][i] = u[j - 1][i] + 1;
      }
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = h - 1; j >= 0; j--) {
      if (j == h - 1 || s[j + 1][i] == '#') {
        d[j][i] = 0;
      } else {
        d[j][i] = d[j + 1][i] + 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] != '#') {
        int tt;
        tt = u[i][j] + d[i][j] + l[i][j] + r[i][j];
        tt++;
        ans = max(tt, ans);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  rep(i, h) rep(j, w) cin >> s[i][j];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }
  rep(j, w) {
    vector<int> done(w);
    rep(i, h) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] - 1);
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  rep(i, h) rep(j, w) cin >> s[i][j];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }
  rep(j, w) {
    vector<int> done(h);
    rep(i, h) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] - 1);
  cout << ans << 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 (int i = 0; i < (n); i++)

int L[2010][2010];
int R[2010][2010];
int U[2010][2010];
int D[2010][2010];

int main(int argc, char const *argv[]) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '.')
        L[i + 1][j + 1] = L[i + 1][j] + 1;
      else
        L[i + 1][j + 1] = 0;
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = w - 1; j >= 0; --j) {
      if (s[i][j] == '.')
        R[i + 1][j + 1] = R[i + 1][j + 2] + 1;
      else
        R[i + 1][j + 1] = 0;
    }
  }

  for (int j = 0; j < w; ++j) {
    for (int i = 0; i < h; ++i) {
      if (s[i][j] == '.')
        U[i + 1][j + 1] = U[i][j + 1] + 1;
      else
        U[i + 1][j + 1] = 0;
    }
  }
  for (int j = 0; j < w; ++j) {
    for (int i = h - 1; i >= 0; --i) {
      if (s[i][j] == '.')
        D[i + 1][j + 1] = D[i + 2][j + 1] + 1;
      else
        D[i - 1][j + 1] = 0;
    }
  }

  int ans = 0;
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#')
      continue;
    int y = U[i + 1][j + 1] + D[i + 1][j + 1] - 1;
    int x = L[i + 1][j + 1] + R[i + 1][j + 1] - 1;
    ans = max(ans, x + y - 1);
  }
  printf("%d\n", ans);

  return 0;
}


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

int L[2010][2010];
int R[2010][2010];
int U[2010][2010];
int D[2010][2010];

int main(int argc, char const *argv[]) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '.')
        L[i + 1][j + 1] = L[i + 1][j] + 1;
      else
        L[i + 1][j + 1] = 0;
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = w - 1; j >= 0; --j) {
      if (s[i][j] == '.')
        R[i + 1][j + 1] = R[i + 1][j + 2] + 1;
      else
        R[i + 1][j + 1] = 0;
    }
  }

  for (int j = 0; j < w; ++j) {
    for (int i = 0; i < h; ++i) {
      if (s[i][j] == '.')
        U[i + 1][j + 1] = U[i][j + 1] + 1;
      else
        U[i + 1][j + 1] = 0;
    }
  }
  for (int j = 0; j < w; ++j) {
    for (int i = h - 1; i >= 0; --i) {
      if (s[i][j] == '.')
        D[i + 1][j + 1] = D[i + 2][j + 1] + 1;
      else
        D[i + 1][j + 1] = 0;
    }
  }

  int ans = 0;
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#')
      continue;
    int y = U[i + 1][j + 1] + D[i + 1][j + 1] - 1;
    int x = L[i + 1][j + 1] + R[i + 1][j + 1] - 1;
    ans = max(ans, x + y - 1);
  }
  printf("%d\n", ans);

  return 0;
}
Problem p03014 (C++)

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

using namespace std;

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

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

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;

      if (c == '.')
        ;
      else if (c == '#')
        s[i][j] = -1;
    }
  }

  for (int i = 0; i < h; i++) {
    vector<int> done(w, 0);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == -1)
        continue;
      if (done[j])
        continue;

      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == -1)
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  for (int j = 0; j < w; j++) {
    vector<int> done(h, 0);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == -1)
        continue;
      if (done[i])
        continue;

      int l = 0;
      while (i + l < h) {
        if (s[i + 1][j] == -1)
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }

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

  cout << ans << endl;
}

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

using namespace std;

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

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

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;

      if (c == '.')
        ;
      else if (c == '#')
        s[i][j] = -1;
    }
  }

  for (int i = 0; i < h; i++) {
    vector<int> done(w, 0);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == -1)
        continue;
      if (done[j])
        continue;

      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == -1)
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  for (int j = 0; j < w; j++) {
    vector<int> done(h, 0);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == -1)
        continue;
      if (done[i])
        continue;

      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == -1)
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
static const uint64_t MOD = 1000000007LL;
// uint64_t dp[100005][13];

char grid[2000][2000];
int64_t wc[2000][2000];
int64_t hc[2000][2000];

/* yoko */
void updatewc(int i, int j) {
  if (wc[i][j])
    return;

  int k = 0;
  while (grid[i + k][j] == '.') {
    k++;
  }

  for (int l = 0; l < k; l++) {
    wc[i + l][j] = k;
  }
}

/* tate */
void updatehc(int i, int j) {
  if (hc[i][j])
    return;

  int k = 0;
  while (grid[i][j + k] == '.') {
    k++;
  }

  for (int l = 0; l < k; l++) {
    hc[i][j + l] = k;
  }
}

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

  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '.')
        grid[j][i] = '.';
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (grid[i][j] == '.') {
        updatewc(i, j);
        updatehc(i, j);
      }
    }
  }

  long cnt = 0;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      cnt = max(wc[i][j] + hc[i][j] - 1, cnt);
    }
  }

  cout << cnt << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
static const uint64_t MOD = 1000000007LL;
// uint64_t dp[100005][13];

char grid[2005][2005];
int64_t wc[2000][2000];
int64_t hc[2000][2000];

/* yoko */
void updatewc(int i, int j) {
  if (wc[i][j])
    return;

  int k = 0;
  while (grid[i + k][j] == '.') {
    k++;
  }

  for (int l = 0; l < k; l++) {
    wc[i + l][j] = k;
  }
}

/* tate */
void updatehc(int i, int j) {
  if (hc[i][j])
    return;

  int k = 0;
  while (grid[i][j + k] == '.') {
    k++;
  }

  for (int l = 0; l < k; l++) {
    hc[i][j + l] = k;
  }
}

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

  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '.')
        grid[j][i] = '.';
    }
  }

  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (grid[i][j] == '.') {
        updatewc(i, j);
        updatehc(i, j);
      }
    }
  }

  long cnt = 0;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      cnt = max(wc[i][j] + hc[i][j] - 1, cnt);
    }
  }

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

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

using namespace std;

using ll = long long;

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

  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (auto &x : g)
    cin >> x;

  vector<vector<int>> x(h, vector<int>(w, 0)), y(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    int j = 0;
    while (j < w) {
      if (g[i][j] == '#') {
        j++;
        continue;
      }

      int q = j;
      while (q < w && g[i][q] == '.')
        q++;
      int l = q - j;
      for (int k = j; k < q; k++)
        x[i][k] = l;
      j = q;
    }
  }

  for (int i = 0; i < w; i++) {
    int j = 0;
    while (j < h) {
      if (g[j][i] == '#') {
        j++;
        continue;
      }

      int q = j;
      while (q < w && g[q][i] == '.')
        q++;
      int l = q - j;
      for (int k = j; k < q; k++)
        y[k][i] = l;
      j = q;
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, x[i][j] + y[i][j] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

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

  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (auto &x : g)
    cin >> x;

  vector<vector<int>> x(h, vector<int>(w, 0)), y(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    int j = 0;
    while (j < w) {
      if (g[i][j] == '#') {
        j++;
        continue;
      }

      int q = j;
      while (q < w && g[i][q] == '.')
        q++;
      int l = q - j;
      for (int k = j; k < q; k++)
        x[i][k] = l;
      j = q;
    }
  }

  for (int i = 0; i < w; i++) {
    int j = 0;
    while (j < h) {
      if (g[j][i] == '#') {
        j++;
        continue;
      }

      int q = j;
      while (q < h && g[q][i] == '.')
        q++;
      int l = q - j;
      for (int k = j; k < q; k++)
        y[k][i] = l;
      j = q;
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, x[i][j] + y[i][j] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h + 2, vector<char>(w + 2));
  rep(i, w + 2) {
    a[0][i] = '#';
    a[h + 1][i] = '#';
  }
  rep(i, h + 2) {
    a[i][0] = '#';
    a[i][w + 1] = '#';
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }
  int cnt;
  int ii, jj;
  int mx = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (a[i][j] == '#')
        continue;
      cnt = 1;
      ii = i;
      while (a[ii + 1][j] == '.') {
        cnt++;
        ii++;
      }
      ii = i;
      while (a[ii - 1][j] == '.') {
        cnt++;
        ii--;
      }
      jj = j;
      while (a[i][jj + 1] == '.') {
        cnt++;
        jj++;
      }
      jj = j;
      while (a[i][jj - 1] == '.') {
        cnt++;
        jj--;
      }
      mx = max(mx, cnt);
    }
  }
  cout << mx << endl;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h + 2, vector<char>(w + 2));
  rep(i, w + 2) {
    a[0][i] = '#';
    a[h + 1][i] = '#';
  }
  rep(i, h + 2) {
    a[i][0] = '#';
    a[i][w + 1] = '#';
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }
  int cnt;
  int ii, jj;
  int mx = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (a[i][j] == '#')
        continue;
      cnt = 1;
      ii = i;
      while (a[ii + 1][j] == '.') {
        cnt++;
        ii++;
      }
      ii = i;
      while (a[ii - 1][j] == '.') {
        cnt++;
        ii--;
      }
      jj = j;
      while (a[i][jj + 1] == '.') {
        cnt++;
        jj++;
      }
      jj = j;
      while (a[i][jj - 1] == '.') {
        cnt++;
        jj--;
      }
      mx = max(mx, cnt);
      if (mx == h + w - 1) {
        cout << mx << endl;
        return 0;
      }
    }
  }
  cout << mx << endl;
}
Problem p03014 (C++)

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

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

  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;

      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }

      rep(k, l) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  rep(i, w) {
    vector<int> done(h);
    rep(j, h) {
      if (s[j][i] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;

      while (j + l < h) {
        if (s[j + l][i] == '#')
          continue;
        l++;
      }

      rep(k, l) {
        cnt[j + k][i] += l;
        done[j + k] = 1;
      }
    }
  }
  int ans = 0;

  rep(i, h) {
    rep(j, w) { ans = max(ans, cnt[i][j] - 1); }
  }
  cout << ans << endl;
}

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

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

  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;

      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }

      rep(k, l) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  rep(i, w) {
    vector<int> done(h);
    rep(j, h) {
      if (s[j][i] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;

      while (j + l < h) {
        if (s[j + l][i] == '#')
          break;
        l++;
      }

      rep(k, l) {
        cnt[j + k][i] += l;
        done[j + k] = 1;
      }
    }
  }
  int ans = 0;

  rep(i, h) {
    rep(j, w) { ans = max(ans, cnt[i][j] - 1); }
  }
  cout << ans << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
// QWsin
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define rep(i, x, y) for (int i = x; i <= y; ++i)
#define out(i, u) for (int i = first[u]; i != -1; i = next[i])
#define repvc(i, vc) for (int i = 0, _sz = vc.size(); i < _sz; ++i)
using namespace std;

const int INF = 1 << 30;
typedef long long ll;

inline int read() {
  int ret = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    ret = ret * 10 + ch - '0';
  return ret * f;
}

const int maxn = 1000 + 10;

char s[maxn][maxn];
int up[maxn][maxn], dn[maxn][maxn], l[maxn][maxn], r[maxn][maxn];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, 1, n) scanf("%s", s[i] + 1);
  rep(i, 1, n) {
    rep(j, 1, m) if (s[i][j] == '.') l[i][j] = l[i][j - 1] + 1;
    else l[i][j] = 0;
    for (int j = m; j >= 1; --j)
      if (s[i][j] == '.')
        r[i][j] = r[i][j + 1] + 1;
      else
        r[i][j] = 0;
  }
  rep(j, 1, m) {
    rep(i, 1, n) if (s[i][j] == '.') up[i][j] = up[i - 1][j] + 1;
    else up[i][j] = 0;
    for (int i = n; i >= 1; --i)
      if (s[i][j] == '.')
        dn[i][j] = dn[i + 1][j] + 1;
      else
        dn[i][j] = 0;
  }

  int ans = 0;
  rep(i, 1, n) rep(j, 1, m) ans =
      max(ans, up[i][j] - 1 + dn[i][j] - 1 + l[i][j] - 1 + r[i][j] - 1 + 1);
  cout << ans << endl;
  return 0;
}


Fixed submission:
// QWsin
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define rep(i, x, y) for (int i = x; i <= y; ++i)
#define out(i, u) for (int i = first[u]; i != -1; i = next[i])
#define repvc(i, vc) for (int i = 0, _sz = vc.size(); i < _sz; ++i)
using namespace std;

const int INF = 1 << 30;
typedef long long ll;

inline int read() {
  int ret = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    ret = ret * 10 + ch - '0';
  return ret * f;
}

const int maxn = 2000 + 10;

char s[maxn][maxn];
int up[maxn][maxn], dn[maxn][maxn], l[maxn][maxn], r[maxn][maxn];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, 1, n) scanf("%s", s[i] + 1);
  rep(i, 1, n) {
    rep(j, 1, m) if (s[i][j] == '.') l[i][j] = l[i][j - 1] + 1;
    else l[i][j] = 0;
    for (int j = m; j >= 1; --j)
      if (s[i][j] == '.')
        r[i][j] = r[i][j + 1] + 1;
      else
        r[i][j] = 0;
  }
  rep(j, 1, m) {
    rep(i, 1, n) if (s[i][j] == '.') up[i][j] = up[i - 1][j] + 1;
    else up[i][j] = 0;
    for (int i = n; i >= 1; --i)
      if (s[i][j] == '.')
        dn[i][j] = dn[i + 1][j] + 1;
      else
        dn[i][j] = 0;
  }

  int ans = 0;
  rep(i, 1, n) rep(j, 1, m) ans =
      max(ans, up[i][j] - 1 + dn[i][j] - 1 + l[i][j] - 1 + r[i][j] - 1 + 1);
  cout << ans << endl;
  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
ll a[2002][2002], b[2002][2002];
string s[2002];
int main() {
  ll h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    ll cnt = 0;
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '#') {
        cnt++;
        a[i][j] = cnt;
      } else {
        cnt = 0;
      }
    }
  }
  for (int i = 0; i < w; i++) {
    ll cnt = 0;
    for (int j = 0; j < h; j++) {
      if (s[j][i] != '#') {
        cnt++;
        b[j][i] = cnt;
      } else {
        cnt = 0;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = w - 2; j >= 0; j--) {
      if (a[i][j] == 0) {
        continue;
      }
      a[i][j] = max(a[i][j], a[i][j + 1]);
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = h - 2; j >= 0; j--) {
      if (b[j][i] == 0) {
        continue;
      }
      b[j][i] = max(b[j][i], b[j + 1][i]);
    }
  }
  ll ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ll now = a[i][j] + b[i][j] - 1;
      ans = max(now, ans);
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
ll a[2002][2002], b[2002][2002];
string s[2002];
int main() {
  ll h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    ll cnt = 0;
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '#') {
        cnt++;
        a[i][j] = cnt;
      } else {
        cnt = 0;
      }
    }
  }
  for (int i = 0; i < w; i++) {
    ll cnt = 0;
    for (int j = 0; j < h; j++) {
      if (s[j][i] != '#') {
        cnt++;
        b[j][i] = cnt;
      } else {
        cnt = 0;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = w - 2; j >= 0; j--) {
      if (a[i][j] == 0) {
        continue;
      }
      a[i][j] = max(a[i][j], a[i][j + 1]);
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = h - 2; j >= 0; j--) {
      if (b[j][i] == 0) {
        continue;
      }
      b[j][i] = max(b[j][i], b[j + 1][i]);
    }
  }
  ll ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ll now = a[i][j] + b[i][j] - 1;
      ans = max(now, ans);
    }
  }
  cout << ans;
}
Problem p03014 (C++)

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

int H, W, res = 0;         // 縦・横・結果
vector<string> Mass(1010); // マス状態
vector<vector<int>> range_Mass(1010, vector<int>(1010, -1)); // 照らされるマス数

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++)
    cin >> Mass[i];

  /*以下, 横連続マス数を調査  計算量O(HW)*/
  int j = 0;
  for (int i = 0; i < H; i++) {
    int j = 0;
    while (j < W) {
      int k = 0;
      while (j + k < W && Mass[i][j + k] != '#')
        k++; // マス連続数取得
      for (int l = 0; l < k; l++)
        range_Mass[i][j + l] += k; // 連続数を加える
      j += k + 1;
    }
  }

  /*以下,縦連続マス数を調査  計算量O(HW)*/
  for (int i = 0; i < W; i++) {
    int j = 0;
    while (j < H) {
      int k = 0;
      while (j + k < H && Mass[j + k][i] != '#')
        k++; // マス連続数取得
      for (int l = 0; l < k; l++)
        range_Mass[j + l][i] += k; // 連続数を加える
      j += k + 1;
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++)
      res = max(res, range_Mass[i][j]);
  }

  cout << res << endl;
  return 0;
}


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

int H, W, res = 0;         // 縦・横・結果
vector<string> Mass(2010); // マス状態
vector<vector<int>> range_Mass(2010, vector<int>(2010, -1)); // 照らされるマス数

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++)
    cin >> Mass[i];

  /*以下, 横連続マス数を調査  計算量O(HW)*/
  int j = 0;
  for (int i = 0; i < H; i++) {
    int j = 0;
    while (j < W) {
      int k = 0;
      while (j + k < W && Mass[i][j + k] != '#')
        k++; // マス連続数取得
      for (int l = 0; l < k; l++)
        range_Mass[i][j + l] += k; // 連続数を加える
      j += k + 1;
    }
  }

  /*以下,縦連続マス数を調査  計算量O(HW)*/
  for (int i = 0; i < W; i++) {
    int j = 0;
    while (j < H) {
      int k = 0;
      while (j + k < H && Mass[j + k][i] != '#')
        k++; // マス連続数取得
      for (int l = 0; l < k; l++)
        range_Mass[j + l][i] += k; // 連続数を加える
      j += k + 1;
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++)
      res = max(res, range_Mass[i][j]);
  }

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

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

struct wawa {
  char a;
  int yoko, tate;
};
wawa s[2000][2000];

int main() {
  int mini = 0;
  int h, w;
  cin >> 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)
        s[i][j].a = '#';
      else
        cin >> s[i][j].a;
    }
  }
  for (int i = 0; i <= h + 1; i++) {
    for (int j = 0; j <= w + 1; j++) {
      if (s[i][j].a == '#') {
        s[i][j].yoko = 0;
        s[i][j].tate = 0;
      } else {
        if (s[i - 1][j].a == '#') {
          int k = 0;
          while (s[i + k][j].a == '.') {
            k++;
          }
          s[i][j].yoko = k;
        } else
          s[i][j].yoko = s[i - 1][j].yoko;

        if (s[i][j - 1].a == '#') {
          int k = 0;
          while (s[i][j + k].a == '.') {
            k++;
          }
          s[i][j].tate = k;
        } else
          s[i][j].tate = s[i][j - 1].tate;
      }
      mini = max(mini, s[i][j].yoko + s[i][j].tate - 1);
    }
  }
  cout << mini << endl;
  return 0;
}


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

struct wawa {
  char a;
  int yoko, tate;
};
wawa s[2005][2005];

int main() {
  int mini = 0;
  int h, w;
  cin >> 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)
        s[i][j].a = '#';
      else
        cin >> s[i][j].a;
    }
  }
  for (int i = 0; i <= h + 1; i++) {
    for (int j = 0; j <= w + 1; j++) {
      if (s[i][j].a == '#') {
        s[i][j].yoko = 0;
        s[i][j].tate = 0;
      } else {
        if (s[i - 1][j].a == '#') {
          int k = 0;
          while (s[i + k][j].a == '.') {
            k++;
          }
          s[i][j].yoko = k;
        } else
          s[i][j].yoko = s[i - 1][j].yoko;

        if (s[i][j - 1].a == '#') {
          int k = 0;
          while (s[i][j + k].a == '.') {
            k++;
          }
          s[i][j].tate = k;
        } else
          s[i][j].tate = s[i][j - 1].tate;
      }
      mini = max(mini, s[i][j].yoko + s[i][j].tate - 1);
    }
  }
  cout << mini << endl;
  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, m;
char c[1003][1003], tmtmp;
int l[1003][1003], r[1003][1003];
int main() {
  cin >> n >> m;
  tmtmp = getchar();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      c[i][j] = getchar();
    tmtmp = getchar();
  }
  for (int i = 0; i < n; i++) {
    int x = (c[i][0] != '#');
    for (int j = 1; j < m; j++)
      if (c[i][j] == '.')
        x++;
      else {
        for (int k = 0; k < x; k++)
          l[i][j - k - 1] = x;
        x = 0;
      }
    for (int j = 0; j < x; j++)
      l[i][m - 1 - j] = x;
    x = 0;
  }
  for (int i = 0; i < m; i++) {
    int x = (c[0][i] != '#');
    for (int j = 1; j < n; j++)
      if (c[j][i] == '.')
        x++;
      else {
        for (int k = 0; k < x; k++)
          r[j - k - 1][i] = x;
        x = 0;
      }
    for (int j = 0; j < x; j++)
      r[n - 1 - j][i] = x;
    x = 0;
  }
  int ans = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      ans = max(ans, l[i][j] + r[i][j] - 1);
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m;
char c[2003][2003], tmtmp;
int l[2003][2003], r[2003][2003];
int main() {
  cin >> n >> m;
  tmtmp = getchar();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      c[i][j] = getchar();
    tmtmp = getchar();
  }
  for (int i = 0; i < n; i++) {
    int x = (c[i][0] != '#');
    for (int j = 1; j < m; j++)
      if (c[i][j] == '.')
        x++;
      else {
        for (int k = 0; k < x; k++)
          l[i][j - k - 1] = x;
        x = 0;
      }
    for (int j = 0; j < x; j++)
      l[i][m - 1 - j] = x;
    x = 0;
  }
  for (int i = 0; i < m; i++) {
    int x = (c[0][i] != '#');
    for (int j = 1; j < n; j++)
      if (c[j][i] == '.')
        x++;
      else {
        for (int k = 0; k < x; k++)
          r[j - k - 1][i] = x;
        x = 0;
      }
    for (int j = 0; j < x; j++)
      r[n - 1 - j][i] = x;
    x = 0;
  }
  int ans = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      ans = max(ans, l[i][j] + r[i][j] - 1);
  cout << ans;
}
Problem p03014 (C++)

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

int l[210][2100], r[2100][2100], u[2100][2100], d[2100][2100];

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

  for (int i = 0; i < h; i++) {
    int c = 0;
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#')
        c = 0;
      else
        c++;
      l[i][j] = c;
    }
  }
  for (int i = 0; i < h; i++) {
    int c = 0;
    for (int j = w - 1; j >= 0; j--) {
      if (board[i][j] == '#')
        c = 0;
      else
        c++;
      r[i][j] = c;
    }
  }
  for (int i = 0; i < w; i++) {
    int c = 0;
    for (int j = 0; j < h; j++) {
      if (board[j][i] == '#')
        c = 0;
      else
        c++;
      u[j][i] = c;
    }
  }
  for (int i = 0; i < w; i++) {
    int c = 0;
    for (int j = h - 1; j >= 0; j--) {
      if (board[j][i] == '#')
        c = 0;
      else
        c++;
      d[j][i] = c;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, (l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3));
    }
  }
  cout << ans << endl;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

int l[2100][2100], r[2100][2100], u[2100][2100], d[2100][2100];

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

  for (int i = 0; i < h; i++) {
    int c = 0;
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#')
        c = 0;
      else
        c++;
      l[i][j] = c;
    }
  }
  for (int i = 0; i < h; i++) {
    int c = 0;
    for (int j = w - 1; j >= 0; j--) {
      if (board[i][j] == '#')
        c = 0;
      else
        c++;
      r[i][j] = c;
    }
  }
  for (int i = 0; i < w; i++) {
    int c = 0;
    for (int j = 0; j < h; j++) {
      if (board[j][i] == '#')
        c = 0;
      else
        c++;
      u[j][i] = c;
    }
  }
  for (int i = 0; i < w; i++) {
    int c = 0;
    for (int j = h - 1; j >= 0; j--) {
      if (board[j][i] == '#')
        c = 0;
      else
        c++;
      d[j][i] = c;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, (l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3));
    }
  }
  cout << ans << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#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>> 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[i][j] == '#')
        continue;
      if (done[j])
        continue;

      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; ++k) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  for (int j = 0; j < h; ++j) {
    vector<int> done(h);
    for (int i = 0; i < h; ++i) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;

      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; ++k) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      ans = max(ans, cnt[i][j] - 1);
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#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>> 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[i][j] == '#')
        continue;
      if (done[j])
        continue;

      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; ++k) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  for (int j = 0; j < w; ++j) {
    vector<int> done(h);
    for (int i = 0; i < h; ++i) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;

      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; ++k) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      ans = max(ans, cnt[i][j] - 1);
  cout << ans << endl;

  return 0;
}
Problem p03014 (C++)

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

using namespace std;

const int maxn = 1e3 + 5;
int preC[maxn][maxn], preR[maxn][maxn];

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] != '#')
        preR[i][j + 1] = preR[i][j] + 1;
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (a[j][i] != '#') {
        preC[j + 1][i] = preC[j][i] + 1;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = w; j > 1; j--) {
      if (preR[i][j] != 0) {
        if (a[i][j - 2] != '#')
          preR[i][j - 1] = preR[i][j];
      }
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = h; j > 1; j--) {
      if (preC[j][i] != 0) {
        if (a[j - 2][i] != '#') {
          preC[j - 1][i] = preC[j][i];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, preR[i][j + 1] + preC[i + 1][j] - 1);
    }
  }
  cout << ans;
  return 0;
}


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

using namespace std;

const int maxn = 2e3 + 5;
int preC[maxn][maxn], preR[maxn][maxn];

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] != '#')
        preR[i][j + 1] = preR[i][j] + 1;
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (a[j][i] != '#') {
        preC[j + 1][i] = preC[j][i] + 1;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = w; j > 1; j--) {
      if (preR[i][j] != 0) {
        if (a[i][j - 2] != '#')
          preR[i][j - 1] = preR[i][j];
      }
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = h; j > 1; j--) {
      if (preC[j][i] != 0) {
        if (a[j - 2][i] != '#') {
          preC[j - 1][i] = preC[j][i];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, preR[i][j + 1] + preC[i + 1][j] - 1);
    }
  }
  cout << ans;
  return 0;
}
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);
  int light[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      light[i][j] = 0;
    }
  }

  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    vector<int> memo(w);
    int cnt = 0;
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        memo[j] = cnt;
        cnt = 0;
      }
    }
    for (int j = w - 1; j >= 0; j--) {
      if (memo[j] == 0 && s[i][j] != '#') {
        light[i][j] += cnt;
      } else {
        cnt = memo[j];
      }
    }
  }
  for (int j = 0; j < h; j++) {
    vector<int> memo(h);
    int cnt = 0;
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        memo[i] = cnt;
        cnt = 0;
      }
    }
    for (int i = h - 1; i >= 0; i--) {
      if (memo[i] == 0 && s[i][j] != '#') {
        light[i][j] += cnt;
      } else {
        cnt = memo[i];
      }
    }
  }
  // for (int i=0; i<h; i++) {
  //     for (int j=0; j<w; j++) {
  //         cout << light[i][j] << " ";
  //     }
  //     cout << endl;
  // }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, light[i][j]);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  int light[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      light[i][j] = 0;
    }
  }

  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    vector<int> memo(w);
    int cnt = 0;
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        memo[j] = cnt;
        cnt = 0;
      }
    }
    for (int j = w - 1; j >= 0; j--) {
      if (memo[j] == 0 && s[i][j] != '#') {
        light[i][j] += cnt;
      } else {
        cnt = memo[j];
      }
    }
  }
  for (int j = 0; j < w; j++) {
    vector<int> memo(h);
    int cnt = 0;
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        memo[i] = cnt;
        cnt = 0;
      }
    }
    for (int i = h - 1; i >= 0; i--) {
      if (memo[i] == 0 && s[i][j] != '#') {
        light[i][j] += cnt;
      } else {
        cnt = memo[i];
      }
    }
  }
  // for (int i=0; i<h; i++) {
  //     for (int j=0; j<w; j++) {
  //         cout << light[i][j] << " ";
  //     }
  //     cout << endl;
  // }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, light[i][j]);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
Problem p03014 (C++)

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

using namespace std;

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

signed main() {
  IOS;
  int h, w, ans = 0;
  cin >> h >> w;
  int hcnt[h + 1][w + 1], wcnt[h + 1][w + 1];
  string s[w];
  FOR(i, 0, h) {
    cin >> s[i];
    int prev = -1, cnt = 0;
    FOR(j, 0, w) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        FOR(k, prev + 1, j) hcnt[i][k] = cnt;
        cnt = 0;
        hcnt[i][j] = 0;
        prev = j;
      }
    }
    FOR(k, prev + 1, w) hcnt[i][k] = cnt;
    //    FOR(j,0,w)
    //      cout << hcnt[i][j] << " ";
    //    cout << endl;
  }

  FOR(j, 0, w) {
    int prev = -1, cnt = 0;
    FOR(i, 0, h) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        FOR(k, prev + 1, i) {
          wcnt[k][j] = cnt;
          ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1);
        }
        cnt = 0;
        wcnt[i][j] = 0;
        prev = i;
      }
    }
    FOR(k, prev + 1, h) {
      wcnt[k][j] = cnt;
      ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1);
    }
  }

  //  cout << endl;
  //  FOR(i,0,h) {
  //    FOR(j,0,w)
  //      cout << wcnt[i][j] << " ";
  //    cout << endl;
  //  }

  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

signed main() {
  IOS;
  int h, w, ans = 0;
  cin >> h >> w;
  int hcnt[h + 1][w + 1], wcnt[h + 1][w + 1];
  string s[h];
  FOR(i, 0, h) {
    cin >> s[i];
    int prev = -1, cnt = 0;
    FOR(j, 0, w) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        FOR(k, prev + 1, j) hcnt[i][k] = cnt;
        cnt = 0;
        hcnt[i][j] = 0;
        prev = j;
      }
    }
    FOR(k, prev + 1, w) hcnt[i][k] = cnt;
    //    FOR(j,0,w)
    //      cout << hcnt[i][j] << " ";
    //    cout << endl;
  }

  FOR(j, 0, w) {
    int prev = -1, cnt = 0;
    FOR(i, 0, h) {
      if (s[i][j] == '.') {
        cnt++;
      } else {
        FOR(k, prev + 1, i) {
          wcnt[k][j] = cnt;
          ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1);
        }
        cnt = 0;
        wcnt[i][j] = 0;
        prev = i;
      }
    }
    FOR(k, prev + 1, h) {
      wcnt[k][j] = cnt;
      ans = max(ans, hcnt[k][j] + wcnt[k][j] - 1);
    }
  }

  //  cout << endl;
  //  FOR(i,0,h) {
  //    FOR(j,0,w)
  //      cout << wcnt[i][j] << " ";
  //    cout << endl;
  //  }

  cout << ans << endl;
  return 0;
}