Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template <class T> void print1d(T x, ll n = -1) {
  if (n == -1)
    n = x.size();
  rep(i, 0, n) { cout << x[i] << ' '; }
  cout << '\\n';
}
template <class T> void print2d(T x, ll r = -1, ll c = -1) {
  if (r == -1)
    r = x.size();
  if (c == -1)
    c = x[0].size();
  rep(i, 0, r) print1d(x[i], c);
}
template <class T, class U> bool haskey(T mp, U key) {
  return mp.find(key) != mp.end();
}
template <class T, class U> bool isin(T el, U container) {
  return find(all(container), el) != container.end();
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool even(T n) { return !(n & 1); }
template <class T> bool odd(T n) { return n & 1; }
template <class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template <class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a, ll n) {
  ll p = 1;
  while (n) {
    if (n & 1)
      p *= a;
    a *= a;
    n >>= 1;
  }
  return p;
}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vll hcnt(H + 1);
  vll wcnt(W + 1);
  map<pll, ll> mp;

  rep(i, 0, M) {
    ll h, w;
    cin >> h >> w;
    hcnt[h]++;
    wcnt[w]++;
    mp[pll{h, w}] = 1;
  }

  ll mxpos = max_element(all(hcnt)) - hcnt.begin();
  ll mxval = hcnt[mxpos];

  ll ans = -inf;
  rep(i, 1, W + 1) {
    if (mp[pll{mxpos, i}] == 0) {
      chmax(ans, mxval + wcnt[i]);
    } else {
      chmax(ans, mxval + wcnt[i] - 1);
    }
  }

  mxpos = max_element(all(wcnt)) - wcnt.begin();
  mxval = wcnt[mxpos];
  rep(i, 1, H + 1) {
    if (mp[pll{i, mxpos}] == 0) {
      chmax(ans, mxval + hcnt[i]);
    } else {
      chmax(ans, mxval + hcnt[i] - 1);
    }
  }

  cout << ans << endl;

  // rep(i, 0, H+1) {
  //         rep(j, 0, W+1) {
  //                 acc[i][j+1] += acc[i][j];
  //         }
  // }

  // rep(i, 0, W+1) {
  //         rep(j, 0, H+1) {
  //                 acc2[j+1][i] += acc2[j][i];
  //         }
  // }

  // ll ans = -inf;

  // rep(i, 1, H+1) {
  //         rep(j, 1, W+1) {
  //                 //if (mp[pll{i, j}] == 0) {
  //                         ll tmp = 0;
  //                         if (mp[pll{i, j}] == 1) tmp = -1;
  //                         chmax(ans, acc[i][j]+acc2[i][j]+tmp);
  //                 //}
  //         }
  // }

  // //print2d(acc);
  // //print2d(acc2);
  // cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template <class T> void print1d(T x, ll n = -1) {
  if (n == -1)
    n = x.size();
  rep(i, 0, n) { cout << x[i] << ' '; }
  cout << '\\n';
}
template <class T> void print2d(T x, ll r = -1, ll c = -1) {
  if (r == -1)
    r = x.size();
  if (c == -1)
    c = x[0].size();
  rep(i, 0, r) print1d(x[i], c);
}
template <class T, class U> bool haskey(T mp, U key) {
  return mp.find(key) != mp.end();
}
template <class T, class U> bool isin(T el, U container) {
  return find(all(container), el) != container.end();
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool even(T n) { return !(n & 1); }
template <class T> bool odd(T n) { return n & 1; }
template <class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template <class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a, ll n) {
  ll p = 1;
  while (n) {
    if (n & 1)
      p *= a;
    a *= a;
    n >>= 1;
  }
  return p;
}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vllvll acc(H + 2, vll(W + 2, 0));
  vllvll acc2(H + 2, vll(W + 2, 0));
  map<pll, ll> mp;

  rep(i, 0, M) {
    ll h, w;
    cin >> h >> w;
    acc[h][0]++;
    acc2[0][w]++;
    mp[pll{h, w}] = 1;
  }

  rep(i, 0, H + 1) {
    rep(j, 0, W + 1) { acc[i][j + 1] += acc[i][j]; }
  }

  rep(i, 0, W + 1) {
    rep(j, 0, H + 1) { acc2[j + 1][i] += acc2[j][i]; }
  }

  ll ans = -inf;

  rep(i, 1, H + 1) {
    rep(j, 1, W + 1) {
      // if (mp[pll{i, j}] == 0) {
      ll tmp = 0;
      if (mp[pll{i, j}] == 1)
        tmp = -1;
      chmax(ans, acc[i][j] + acc2[i][j] + tmp);
      //}
    }
  }

  // print2d(acc);
  // print2d(acc2);
  cout << ans << endl;
}