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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define INF 1000000000
#define pb push_back
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c), x) != c.end())

ll bigmod(ll a, ll b, ll m) {

  if (b == 0)
    return 1;
  ll x = bigmod(a, b / 2, m);
  x = (x * x) % m;

  if (b % 2)
    x = (x * a) % m;
  return x;
}

ll bigsum(ll a, ll b, ll m) {
  ll s;
  if (b == 0)
    return b;
  if (b == 1)
    return a + 1;
  if (b % 2) {
    b = b / 2;
    s = bigsum(a, b, m) % m;
    s = (s * bigmod(a, b + 1, m)) % m;
    return s;
  } else {
    s = bigsum(a, b - 1, m) % m;
    s = (a * s + 1) % m;
    return s;
  }
}

int main() {
  int h, w, m, i, j, mr = 0, mc = 0, l1, l2, im, a, b, row[300005] = {0},
                     col[300005] = {0};
  vi vr;
  vi vc;
  map<pair<int, int>, int> mp;

  cin >> h >> w >> m;

  for (i = 0; i < m; i++) {
    cin >> a >> b;
    mp[make_pair(a, b)] = 35;
    row[a]++;
    col[b]++;
  }

  for (i = 0; i <= h; i++) {
    mr = max(mr, row[i]);
  }
  for (i = 0; i <= w; i++) {
    mc = max(mc, col[i]);
  }

  for (i = 0; i <= h; i++) {
    if (row[i] == mr)
      vr.pb(i);
  }
  for (i = 0; i <= w; i++) {
    if (col[i] == mc)
      vc.pb(i);
  }

  im = 1;
  l1 = vr.size();
  l2 = vc.size();

  for (i = 0; i < l1; i++) {
    for (j = 0; j < l2; j++) {

      if (mp.find(make_pair(vr[i], vc[j])) != mp.end()) {

        continue;

      }

      else {
        im = 0;
        break;
      }
    }

    if (im == 0)
      break;
  }

  if (im == 0)
    cout << mr + mc << endl;
  else
    cout << mr + mc - 1 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define INF 1000000000
#define pb push_back
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c), x) != c.end())

ll bigmod(ll a, ll b, ll m) {

  if (b == 0)
    return 1;
  ll x = bigmod(a, b / 2, m);
  x = (x * x) % m;

  if (b % 2)
    x = (x * a) % m;
  return x;
}

ll bigsum(ll a, ll b, ll m) {
  ll s;
  if (b == 0)
    return b;
  if (b == 1)
    return a + 1;
  if (b % 2) {
    b = b / 2;
    s = bigsum(a, b, m) % m;
    s = (s * bigmod(a, b + 1, m)) % m;
    return s;
  } else {
    s = bigsum(a, b - 1, m) % m;
    s = (a * s + 1) % m;
    return s;
  }
}

int main() {
  int h, w, m, i, j, mr = 0, mc = 0, l1, l2, im, a, b, row[3005] = {0},
                     col[3005] = {0};
  vi vr;
  vi vc;
  map<pair<int, int>, int> mp;

  cin >> h >> w >> m;

  for (i = 0; i < m; i++) {
    cin >> a >> b;
    mp[make_pair(a, b)] = 35;
    row[a]++;
    col[b]++;
  }

  for (i = 0; i <= h; i++) {
    mr = max(mr, row[i]);
  }
  for (i = 0; i <= w; i++) {
    mc = max(mc, col[i]);
  }

  for (i = 0; i <= h; i++) {
    if (row[i] == mr)
      vr.pb(i);
  }
  for (i = 0; i <= w; i++) {
    if (col[i] == mc)
      vc.pb(i);
  }

  im = 1;
  l1 = vr.size();
  l2 = vc.size();

  for (i = 0; i < l1; i++) {
    for (j = 0; j < l2; j++) {

      if (mp.find(make_pair(vr[i], vc[j])) != mp.end()) {

        continue;

      }

      else {
        im = 0;
        break;
      }
    }

    if (im == 0)
      break;
  }

  if (im == 0)
    cout << mr + mc << endl;
  else
    cout << mr + mc - 1 << endl;

  return 0;
}