Problem p03014 (C++)

Buggy submission (status: Runtime Error):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x) (x).begin(), (x).end()
#define Sort(x) sort(all((x)))
#define X first
#define Y second
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << " = " << x << endl
#define SZ(x) ll(x.size())
#define fast_io                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define set_random                                                             \
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 2e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n, m, ans;
string s[MAXN];
vector<ll> x[MAXN], y[MAXN];

int main() {
  fast_io;

  cin >> n >> m;
  s[0] = string(m + 2, '#');
  s[n + 1] = s[0];
  for (ll i = 1; i <= n; i++) {
    cin >> s[i];
    s[i] = '#' + s[i] + "#";
  }

  for (ll i = 0; i <= n + 1; i++) {
    for (ll j = 0; j <= m + 1; j++) {
      if (s[i][j] == '#') {
        x[i].push_back(j);
        y[j].push_back(i);
      }
    }
  }

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (s[i][j] == '#')
        continue;
      ll indx = lower_bound(all(x[i]), j) - x[i].begin();
      ll indy = lower_bound(all(y[j]), i) - y[j].begin();
      ans = max(ans,
                x[i][indx] - x[i][indx - 1] + y[j][indy] - y[j][indy - 1] - 3);
    }
  }
  cout << ans << endl;

  return 0;
}
/*

*/


Fixed submission:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x) (x).begin(), (x).end()
#define Sort(x) sort(all((x)))
#define X first
#define Y second
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << " = " << x << endl
#define SZ(x) ll(x.size())
#define fast_io                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define set_random                                                             \
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 2e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n, m, ans;
string s[MAXN];
vector<ll> x[MAXN], y[MAXN];

int main() {
  fast_io;

  cin >> n >> m;
  s[0] = string(m + 2, '#');
  s[n + 1] = s[0];
  for (ll i = 1; i <= n; i++) {
    cin >> s[i];
    s[i] = '#' + s[i] + "#";
  }

  for (ll i = 0; i <= n + 1; i++) {
    for (ll j = 0; j <= m + 1; j++) {
      if (s[i][j] == '#') {
        x[i].push_back(j);
        y[j].push_back(i);
      }
    }
  }

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= m; j++) {
      if (s[i][j] == '#')
        continue;
      ll indx = lower_bound(all(x[i]), j) - x[i].begin();
      ll indy = lower_bound(all(y[j]), i) - y[j].begin();
      ans = max(ans,
                x[i][indx] - x[i][indx - 1] + y[j][indy] - y[j][indy - 1] - 3);
    }
  }
  cout << ans << endl;

  return 0;
}
/*

*/