alexjercan/bugnet huggingface dataset:
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/* ACL */

// using namespace atcoder;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  // vector<vector<bool>> table(H+1,vector<bool>(W+1,false));
  // map<pair<int,int>,bool> table;
  set<pair<int, int>> table;

  // the number of bombs by h,w
  vector<int> h_cnt(H + 1, 0);
  vector<int> w_cnt(W + 1, 0);

  // max bombs in arrow
  int h_max = 0;
  int w_max = 0;

  rep(i, M) {
    int h, w;
    cin >> h >> w;
    // table[{h,w}] = true;
    table.insert({h, w});
    h_cnt.at(h) += 1;
    w_cnt.at(w) += 1;

    chmax(h_max, h_cnt.at(h));
    chmax(w_max, w_cnt.at(w));
  }

  // kiyasume
  if (H == 1 || W == 1) {
    cout << M << endl;
    return 0;
  }

  // which column or row has max bombs?
  vector<int> maxHs(0);
  vector<int> maxWs(0);

  rep(i, H + 1) {
    if (h_cnt.at(i) == h_max) {
      maxHs.push_back(i);
    }
  }
  rep(i, W + 1) {
    if (w_cnt.at(i) == w_max) {
      maxWs.push_back(i);
    }
  }

  // is there a bomb at hypocenter?
  int ans = h_max + w_max - 1;
  rep(i, maxHs.size()) {
    rep(j, maxWs.size()) {
      if (table.find({maxHs[i], maxWs[j]}) == table.end()) {
        ans += 1;
        cout << ans << endl;
        return 0;
      }
    }
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/* ACL */

// using namespace atcoder;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<vector<bool>> table(H + 1, vector<bool>(W + 1, false));

  vector<int> h_cnt(H + 1, 0);
  vector<int> w_cnt(W + 1, 0);

  int h_max = 0;
  int w_max = 0;
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    table.at(h).at(w) = true;
    h_cnt.at(h) += 1;
    w_cnt.at(w) += 1;

    chmax(h_max, h_cnt.at(h));
    chmax(w_max, w_cnt.at(w));
  }
  vector<int> maxHs(0);
  vector<int> maxWs(0);

  rep(i, H) {
    if (h_cnt.at(i) == h_max) {
      maxHs.push_back(i);
    }
  }
  rep(i, W) {
    if (w_cnt.at(i) == w_max) {
      maxWs.push_back(i);
    }
  }

  bool isThereBomb = true;
  rep(i, maxHs.size()) {
    rep(j, maxWs.size()) {
      isThereBomb &= table.at(maxHs.at(i)).at(maxWs.at(j));
    }
  }

  cout << (h_max + w_max - ((isThereBomb) ? 1 : 0)) << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;
using lld = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  while (b != 0) {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H, W, M;
  cin >> H >> W >> M;

  vector<ll> HA(H);
  vector<ll> WA(W);
  set<pair<int, int>> MA;

  loop(0, M, i) {
    ll x, y;
    cin >> y >> x;
    x--;
    y--;
    HA[y] += 1;
    WA[x] += 1;
    MA.insert(make_pair(y, x));
  }

  ll sw = *max_element(WA.begin(), WA.end());
  ll sh = *max_element(HA.begin(), HA.end());
  vector<int> wls;
  vector<int> hls;
  ll score = 0;

  loop(0, H, i) {
    if (HA[i] == sh) {
      hls.push_back(i);
    }
  }

  loop(0, W, i) {
    if (WA[i] == sw) {
      wls.push_back(i);
    }
  }

  for (auto y : hls) {
    for (auto x : wls) {
      if (MA.count(make_pair(y, x)) == 0) {
        print(sw + sh);
        return 0;
      }
    }
  }
  score = sw + sh - 1;
  print(score);
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;
using lld = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  while (b != 0) {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H, W, M;
  cin >> H >> W >> M;

  vector<ll> HA(H);
  vector<ll> WA(W);
  set<pair<int, int>> MA;

  loop(0, M, i) {
    ll x, y;
    cin >> y >> x;
    x--;
    y--;
    HA[y] += 1;
    WA[x] += 1;
    MA.insert(make_pair(y, x));
  }

  ll sw = *max_element(WA.begin(), WA.end());
  ll sh = *max_element(HA.begin(), HA.end());
  vector<int> wls;
  vector<int> hls;
  ll score = 0;

  loop(0, H, i) {
    if (HA[i] == sh) {
      hls.push_back(i);
    }
  }

  loop(0, W, i) {
    if (WA[i] == sw) {
      wls.push_back(i);
    }
  }

  loop(0, hls.size(), i) {
    loop(0, wls.size(), j) {
      int x = wls[j];
      int y = hls[i];
      ll tmp = WA[x] + HA[y];
      if (MA.count(make_pair(y, x)) != 0) {
        tmp--;
      }
      score = max(tmp, score);
    }
  }
  print(score);
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\\b\\b]\\n"; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cerr << H << ", ";
  dbg_out(T...);
}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

/****************************** CODE IS HERE
 * ***********************************/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m, t;
  cin >> n >> m >> t;
  vector<ll> dpR(n, 0), dpC(m, 0);
  set<pair<int, int>> s;
  vector<int> rows[n], cols[m];
  for (int i = 0, a, b; i < t; ++i) {
    cin >> a >> b;
    a--, b--;
    dpR[a]++;
    dpC[b]++;
    s.insert({a, b});
    rows[a].push_back(b);
    cols[b].push_back(a);
  }

  ll maxr = *max_element(all(dpR));
  ll maxc = *max_element(all(dpC));
  ll ans = maxr + maxc;
  set<int> r, c;
  for (int i = 0; i < n; ++i) {
    if (dpR[i] == maxr)
      r.insert(i);
  }
  for (int i = 0; i < m; ++i) {
    if (dpC[i] == maxc)
      c.insert(i);
  }
  // cout << endl;
  // for (int i: r) cout << i << ' '; cout << endl;
  // for (int j: c) cout << j << ' '; cout << endl;

  bool ok = true;
  // for (int i: r) {
  //     for (int j: rows[i]) {
  //         if (!c.count(j)) ok = false;
  //     }
  // }

  // for (int i: c) {
  //     for (int j: cols[i]) {
  //         if (!r.count(j)) ok = false;
  //     }
  // }

  for (int i : r) {
    for (int j : c) {
      if (!s.count({i, j})) {
        ok = false;
        break;
      }
    }
  }
  cout << (ans - ok);

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\\b\\b]\\n"; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cerr << H << ", ";
  dbg_out(T...);
}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

/****************************** CODE IS HERE
 * ***********************************/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m, t;
  cin >> n >> m >> t;
  vector<vector<int>> A(n, vector<int>(m, 0));
  for (int i = 0, a, b; i < t; ++i) {
    cin >> a >> b;
    a--, b--;
    A[a][b] = 1;
  }

  vector<int> dpR(n, 0), dpC(m, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      dpR[i] += A[i][j];
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i)
      dpC[j] += A[i][j];
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int res = dpR[i] + dpC[j] - A[i][j];
      ans = max(ans, res);
    }
  }

  cout << ans;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000007
using namespace std;

int main() {
  long H, W, m;
  cin >> H >> W >> m;
  vector<pair<long, long>> hw;
  vector<long> hi(H), wi(W);
  rep(i, int(hi.size())) hi[i] = 0;
  rep(i, int(wi.size())) wi[i] = 0;
  long h1, w1;
  rep(i, m) {
    cin >> h1 >> w1;
    h1--;
    w1--;
    hw.push_back({h1, w1});
    hi[h1]++;
    wi[w1]++;
  }
  long maxh = 0, maxw = 0;
  rep(i, int(hi.size())) if (maxh < hi[i]) maxh = hi[i];
  rep(i, int(wi.size())) if (maxw < wi[i]) maxw = wi[i];
  long ans = maxh + maxw;
  vector<int> hcan, wcan;
  rep(i, int(hi.size())) if (maxh == hi[i]) {
    hcan.push_back(i);
    hi[i] = -INF;
  }
  rep(i, int(wi.size())) if (maxw == wi[i]) {
    wcan.push_back(i);
    wi[i] = -INF;
  }
  long tmp = 0;
  rep(i, m) {
    if (hi[hw[i].first] == -INF && wi[hw[i].second] == -INF) {
      tmp++;
    }
  }
  if (tmp == int(hcan.size()) * int(wcan.size()))
    ans--;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000007
using namespace std;

int main() {
  long H, W, m;
  cin >> H >> W >> m;
  vector<pair<long, long>> hw;
  vector<long> hi(H), wi(W);
  rep(i, int(hi.size())) {
    hi[i] = 0;
    wi[i] = 0;
  }
  long h1, w1;
  rep(i, m) {
    cin >> h1 >> w1;
    h1--;
    w1--;
    hw.push_back({h1, w1});
    hi[h1]++;
    wi[w1]++;
  }
  long maxh = 0, maxw = 0;
  rep(i, int(hi.size())) if (maxh < hi[i]) maxh = hi[i];
  rep(i, int(wi.size())) if (maxw < wi[i]) maxw = wi[i];
  long ans = maxh + maxw;
  vector<int> hcan, wcan;
  rep(i, int(hi.size())) if (maxh == hi[i]) {
    hcan.push_back(i);
    hi[i] = -INF;
  }
  rep(i, int(wi.size())) if (maxw == wi[i]) {
    wcan.push_back(i);
    wi[i] = -INF;
  }
  long tmp = 0;
  rep(i, m) {
    if (hi[hw[i].first] == -INF && wi[hw[i].second] == -INF) {
      tmp++;
    }
  }
  if (tmp == int(hcan.size()) * int(wcan.size()))
    ans--;
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <set>
#include <vector>
using namespace std;

void set_reset(set<int> &s) {
  set<int> s2;
  s = s2;
}

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  vector<int> hzt(H), vtc(W);
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
  }
  for (int i = 0; i < M; i++) {
    vtc[w[i]]++;
    hzt[h[i]]++;
  }
  int vtc_max = 0;
  set<int> vtc_n;
  for (int i = 0; i < W; i++) {
    if (vtc_max < vtc[i]) {
      vtc_max = vtc[i];
      set_reset(vtc_n);
      vtc_n.insert(i);
    } else if (vtc_max == vtc[i]) {
      vtc_n.insert(i);
    }
  }
  int hzt_max = 0;
  set<int> hzt_n;
  for (int i = 0; i < H; i++) {
    if (hzt_max < hzt[i]) {
      hzt_max = hzt[i];
      set_reset(hzt_n);
      hzt_n.insert(i);
    } else if (hzt_max == hzt[i]) {
      hzt_n.insert(i);
    }
  }
  int cross_bomb_count = 0;
  for (int i = 0; i < M; i++) {
    if (hzt_n.count(h[i]) && vtc_n.count(w[i])) {
      cross_bomb_count++;
    }
  }
  if (cross_bomb_count == vtc_n.size() * hzt_n.size())
    cout << vtc_max + hzt_max - 1 << endl;
  else
    cout << vtc_max + hzt_max << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

void queue_reset(queue<int> &q) {
  while (!q.empty()) {
    q.pop();
  }
}

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  vector<int> hzt(H), vtc(W);
  vector<vector<int>> map(H, vector<int>(W));
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
    map[h[i]][w[i]] = 1;
  }
  for (int i = 0; i < M; i++) {
    vtc[w[i]]++;
    hzt[h[i]]++;
  }
  int vtc_max = 0;
  queue<int> vtc_n;
  for (int i = 0; i < W; i++) {
    if (vtc_max < vtc[i]) {
      vtc_max = vtc[i];
      queue_reset(vtc_n);
      vtc_n.push(i);
    } else if (vtc_max == vtc[i]) {
      vtc_n.push(i);
    }
  }
  int hzt_max = 0;
  queue<int> hzt_n;
  for (int i = 0; i < H; i++) {
    if (hzt_max < hzt[i]) {
      hzt_max = hzt[i];
      queue_reset(hzt_n);
      hzt_n.push(i);
    } else if (hzt_max == hzt[i]) {
      hzt_n.push(i);
    }
  }
  int bom_h, bom_w;
  bool judge = false;
  while (!vtc_n.empty()) {
    bom_w = vtc_n.front();
    vtc_n.pop();
    queue<int> temp = hzt_n;
    while (!temp.empty()) {
      bom_h = temp.front();
      temp.pop();
      if (map[bom_h][bom_w] == 0) {
        judge = true;
        break;
      }
    }
    if (judge)
      break;
  }
  if (judge)
    cout << vtc_max + hzt_max << endl;
  else
    cout << vtc_max + hzt_max - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;

  vector<ll> h(M), w(M);
  vector<ll> y(H + 10), x(W + 10);
  for (ll i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
    y[h[i]]++;
    x[w[i]]++;
  }

  vector<pair<ll, int>> bom;
  map<pair<ll, int>, int> mp;
  for (int i = 0; i < M; i++) {
    bom.push_back(make_pair(h[i], w[i]));
    mp[make_pair(h[i], w[i])] = 1;
  }
  ll y_max, x_max;
  y_max = 0;
  x_max = 0;

  for (int i = 0; i < H; i++) {
    if (y_max < y[i])
      y_max = y[i];
  }
  vector<ll> y_a, x_a;
  for (int i = 0; i < H; i++) {
    if (y_max == y[i])
      y_a.push_back(i);
  }

  for (int i = 0; i < W; i++) {
    if (x_max < x[i])
      x_max = x[i];
  }
  for (int i = 0; i < W; i++) {
    if (x_max == x[i])
      x_a.push_back(i);
  }

  for (ll i = 0; i < y_a.size(); i++) {
    for (ll j = 0; j < x_a.size(); j++) {
      if (mp.count(make_pair(y_a[i], x_a[j])) == 0) {
        cout << x_max + y_max;
        return 0;
      }
      // if(j == x_a.size() - 1) { cout << x_max + y_max - 1; return 0; }
    }
  }

  cout << x_max + y_max - 1;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;

  vector<ll> h(M), w(M);
  vector<ll> y(H), x(W);
  for (ll i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
    y[h[i]]++;
    x[w[i]]++;
  }

  vector<pair<ll, int>> bom;
  map<pair<ll, int>, int> mp;
  for (int i = 0; i < M; i++) {
    bom.push_back(make_pair(h[i], w[i]));
    mp[make_pair(h[i], w[i])] = 1;
  }
  ll y_max, x_max;
  y_max = 0;
  x_max = 0;

  for (int i = 0; i < H; i++) {
    if (y_max < y[i])
      y_max = y[i];
  }
  vector<ll> y_a, x_a;
  for (int i = 0; i < H; i++) {
    if (y_max == y[i])
      y_a.push_back(i);
  }

  for (int i = 0; i < W; i++) {
    if (x_max < x[i])
      x_max = x[i];
  }
  for (int i = 0; i < W; i++) {
    if (x_max == x[i])
      x_a.push_back(i);
  }

  for (ll i = 0; i < y_a.size(); i++) {
    for (ll j = 0; j < x_a.size(); j++) {
      if (mp.count(make_pair(h[y_a[i]], w[x_a[j]])) == 0) {
        cout << x_max + y_max;
        return 0;
      }
      if (j == x_a.size() - 1) {
        cout << x_max + y_max - 1;
        return 0;
      }
    }
  }

  cout << x_max + y_max - 1;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

  int h, w, m;
  cin >> h >> w >> m;

  vector<int> col(w, 0);
  vector<int> row(h, 0);

  set<pair<int, int>> s;
  rep(i, m) {
    int h, w;
    cin >> h >> w;
    col[--w]++;
    row[--h]++;
    s.insert(make_pair(h, w));
  }
  int max_val = 0;
  rep(i, h) { max_val = max(max_val, row[i]); }
  vector<int> max_idy;
  rep(i, h) {
    if (row[i] == max_val) {
      max_idy.push_back(i);
    }
  }
  int max_val2 = 0;
  rep(i, w) { max_val2 = max(max_val2, col[i]); }
  vector<int> max_idx;
  rep(i, w) {
    if (col[i] == max_val2) {
      max_idx.push_back(i);
    }
  }
  int res = 0;
  for (auto e1 : max_idy)
    for (auto e2 : max_idx) {
      auto it = s.find(make_pair(e1, e2));
      int flag = 0;
      if (it != s.end()) {
        res = max(res, max_val + max_val2 - 1);
      } else {
        res = max(res, max_val + max_val2);
        flag = 1;
        break;
      }
      if (flag)
        break;
    }

  wcout << res << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

  int h, w, m;
  cin >> h >> w >> m;

  vector<int> col(w, 0);
  vector<int> row(h, 0);

  set<pair<int, int>> s;
  rep(i, m) {
    int h, w;
    cin >> h >> w;
    col[--w]++;
    row[--h]++;
    s.insert(make_pair(h, w));
  }
  int max_val = 0;
  rep(i, h) { max_val = max(max_val, row[i]); }
  vector<int> max_idy;
  rep(i, h) {
    if (row[i] == max_val) {
      max_idy.push_back(i);
    }
  }
  int max_val2 = 0;
  rep(i, h) { max_val2 = max(max_val2, col[i]); }
  vector<int> max_idx;
  rep(i, w) {
    if (col[i] == max_val2) {
      max_idx.push_back(i);
    }
  }
  int res = 0;
  for (auto e1 : max_idy)
    for (auto e2 : max_idx) {
      auto it = s.find(make_pair(e1, e2));
      int flag = 0;
      if (it != s.end()) {
        res = max(res, max_val + max_val2 - 1);
      } else {
        res = max(res, max_val + max_val2);
        flag = 1;
        break;
      }
      if (flag)
        break;
    }

  wcout << res << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main() {
  typedef pair<int, int> pair;
  int H, W, M;
  cin >> H >> W >> M;
  map<pair, bool> exist;
  vector<int> Hnum(H, 0);
  vector<int> Wnum(W, 0);
  for (int l = 0; l < M; ++l) {
    int h, w;
    cin >> h >> w;
    --h;
    --w;
    exist[{h, w}] = true;
    ++Hnum[h];
    ++Wnum[w];
  }
  vector<pair> Hpair;
  for (int i = 0; i < H; ++i)
    Hpair.push_back(pair(Hnum[i], i));
  vector<pair> Wpair;
  for (int i = 0; i < W; ++i)
    Wpair.push_back(pair(Wnum[i], i));
  sort(Hpair.rbegin(), Hpair.rend());
  sort(Wpair.rbegin(), Wpair.rend());
  int Hmax = 0;
  int Wmax = 0;
  for (int i = 0; i < H; ++i) {
    if (i == 0)
      Hmax = Hpair[i].first;
    if (Hmax != Hpair[i].first)
      break;
    else {
      for (int j = 0; j < W; ++j) {
        if (j == 0)
          Wmax = Wpair[j].first;
        if (Wmax != Wpair[j].first)
          break;
        else {
          if (!exist[{Hpair[i].second, Wpair[j].second}]) {
            cout << Hmax + Wmax << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << Hmax + Wmax - 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<vector<bool>> exist(H, vector<bool>(W, false));
  vector<int> Hnum(H, 0);
  vector<int> Wnum(W, 0);
  for (int l = 0; l < M; ++l) {
    int h, w;
    cin >> h >> w;
    --h;
    --w;
    exist[h][w] = true;
    ++Hnum[h];
    ++Wnum[w];
  }
  typedef pair<int, int> pair;
  vector<pair> Hpair;
  for (int i = 0; i < H; ++i)
    Hpair.push_back(pair(Hnum[i], i));
  vector<pair> Wpair;
  for (int i = 0; i < W; ++i)
    Wpair.push_back(pair(Wnum[i], i));
  sort(Hpair.rbegin(), Hpair.rend());
  sort(Wpair.rbegin(), Wpair.rend());
  int Hmax = 0;
  int Wmax = 0;
  for (int i = 0; i < H; ++i) {
    if (i == 0)
      Hmax = Hpair[i].first;
    if (Hmax != Hpair[i].first)
      break;
    else {
      for (int j = 0; j < W; ++j) {
        if (j == 0)
          Wmax = Wpair[j].first;
        if (Wmax != Wpair[j].first)
          break;
        else {
          if (exist[Hpair[i].second][Wpair[j].second]) {
            cout << Hmax + Wmax << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << Hmax + Wmax - 1 << endl;
  return 0;
}