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

#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007

int main() {
  ll h, w, m;
  ll hi, wi;
  ll maxh = -1;
  ll maxw = -1;
  ll ans;
  set<pair<int, int>> p;
  cin >> h >> w >> m;
  vector<int> vh(h);
  vector<int> vw(w);
  vector<int> buf1;
  vector<int> buf2;
  vector<pair<int, int>> a;
  rep(i, m) {
    cin >> hi >> wi;
    hi--;
    wi--;
    vh[hi]++;
    vw[wi]++;
    p.emplace(hi, wi);
  }
  rep(i, h) {
    if (maxh < vh[i]) {
      maxh = vh[i];
      buf1.clear();
      buf1.push_back(i);
    }
    if (maxh == vh[i])
      buf1.push_back(i);
  }
  rep(i, w) {
    if (maxw < vw[i]) {
      maxw = vw[i];
      buf2.clear();
      buf2.push_back(i);
    }
    if (maxw == vw[i])
      buf2.push_back(i);
  }
  ans = maxh + maxw;

  bool b = false;
  for (int i : buf1)
    for (int j : buf2) {
      if (p.count(pair<int, int>{i, j}))
        continue;
      cout << ans << endl;
      return 0;
    }
  ans--;

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

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007

int main() {
  ll h, w, m;
  ll hi, wi;
  ll maxh = -1;
  ll maxw = -1;
  ll ans;
  ll buf1, buf2;
  cin >> h >> w >> m;
  vector<int> vh(h);
  vector<int> vw(w);
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, m) {
    cin >> hi >> wi;
    hi--;
    wi--;
    vh[hi]++;
    vw[wi]++;
    a[hi][wi]++;
  }
  rep(i, h) {
    if (maxh < vh[i])
      maxh = vh[i];
    buf1 = i;
  }
  rep(i, w) {
    if (maxw < vw[i])
      maxw = vw[i];
    buf2 = i;
  }
  ans = maxh + maxw;
  if (a[buf1][buf2] != 0)
    ans--;
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> vh(h + 1, 0);
  vector<int> vw(w + 1, 0);
  unordered_map<string, int> u;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    vh[l]++;
    vw[r]++;
    string temp = to_string(l) + " " + to_string(r);
    u[temp]++;
  }
  int m1 = 0;
  int m2 = 0;
  for (int i = 0; i <= h; i++) {
    if (vh[i] > m1) {
      m1 = vh[i];
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] > m2) {
      m2 = vw[i];
    }
  }
  vector<int> l1;
  vector<int> r1;
  for (int i = 0; i <= h; i++) {
    if (vh[i] == m1) {
      l1.push_back(i);
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] == m2) {
      r1.push_back(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < l1.size(); i++) {
    for (int j = 0; j < r1.size(); j++) {

      string temp = to_string(l1[i]) + " " + to_string(r1[j]);
      if (u.find(temp) != u.end()) {
        ans = max(ans, m1 + m2 - 1);
      } else {
        ans = max(ans, m1 + m2);
        break;
      }
    }
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> vh(h + 1, 0);
  vector<int> vw(w + 1, 0);
  unordered_map<string, int> u;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    vh[l]++;
    vw[r]++;
    string temp = to_string(l) + " " + to_string(r);
    u[temp]++;
  }
  int m1 = 0;
  int m2 = 0;
  for (int i = 0; i <= h; i++) {
    if (vh[i] > m1) {
      m1 = vh[i];
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] > m2) {
      m2 = vw[i];
    }
  }
  vector<int> l1;
  vector<int> r1;
  for (int i = 0; i <= h; i++) {
    if (vh[i] == m1) {
      l1.push_back(i);
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] == m2) {
      r1.push_back(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < l1.size(); i++) {
    for (int j = 0; j < r1.size(); j++) {

      string temp = to_string(l1[i]) + " " + to_string(r1[j]);
      if (u.find(temp) != u.end()) {
        ans = max(ans, m1 + m2 - 1);
      } else {
        ans = max(ans, m1 + m2);
      }
    }
  }
  cout << ans << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

// https://atcoder.jp/contests/abc176/tasks/abc176_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> sumh(H), sumw(W), X(M), Y(M);
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    sumh[h]++;
    sumw[w]++;
    X[i] = h;
    Y[i] = w;
  }
  vector<int> idxh, idxw;
  int maxh = 0, maxw = 0;
  REP(i, H) {
    if (maxh < sumh[i]) {
      maxh = sumh[i];
      idxh.clear();
      idxh.emplace_back(i);
    } else if (maxh == sumh[i]) {
      idxh.emplace_back(i);
    }
  }

  REP(i, W) {
    if (maxw < sumw[i]) {
      maxw = sumw[i];
      idxw.clear();
      idxw.emplace_back(i);
    } else if (maxw == sumw[i]) {
      idxw.emplace_back(i);
    }
  }
  bitset<300001> vr, vc;
  for (auto &x : idxh) {
    vr[x] = true;
  }
  for (auto &x : idxw) {
    vc[x] = true;
  }
  int cnt = 0;
  REP(i, M) {
    if (vr[X[i]] && vc[Y[i]]) {
      cnt++;
    }
  }
  // 横軸と縦軸の最大値全てに爆弾がある場合は-1
  if (cnt == idxh.size() * idxw.size()) {
    cout << maxw + maxh - 1 << endl;
  } else {
    cout << maxw + maxh << endl;
  }
}

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  solve();
}


Error: TLE

Fixed submission:

// https://atcoder.jp/contests/abc176/tasks/abc176_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
  int H, W, M;
  cin >> H >> W >> M;
  set<pair<int, int>> st;
  vector<int> sumh(H), sumw(W);
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    st.insert({h, w});
    sumh[h]++;
    sumw[w]++;
  }
  vector<int> idxh, idxw;
  int maxh = 0, maxw = 0;
  REP(i, H) {
    if (maxh < sumh[i]) {
      maxh = sumh[i];
      idxh.clear();
      idxh.emplace_back(i);
    } else if (maxh == sumh[i]) {
      idxh.emplace_back(i);
    }
  }

  REP(i, W) {
    if (maxw < sumw[i]) {
      maxw = sumw[i];
      idxw.clear();
      idxw.emplace_back(i);
    } else if (maxw == sumw[i]) {
      idxw.emplace_back(i);
    }
  }
  int ans = 0;
  for (auto &x : st) {
    int h = x.first;
    int w = x.second;
    ans = max(ans, sumh[h] + sumw[w] - 1);
  }
  for (auto &h : idxh) {
    for (auto &w : idxw) {
      ans = max(ans, sumh[h] + sumw[w] - (int)st.count({h, w}));
    }
  }
  cout << ans << endl;
}

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  solve();
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve() {
  ll h, w, m;
  cin >> h >> w >> m;
  unordered_map<ll, ll> r;
  unordered_map<ll, ll> c;
  map<pair<ll, ll>, ll> g;
  map<ll, bool> mxx, myy;
  for (int i = 0; i < m; ++i) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    g[{x, y}] = 1;
    r[x]++;
    c[y]++;
  }
  ll ans = 0;
  for (auto it : g) {
    ans = max(ans, r[it.first.first] + c[it.first.second] - 1);
  }
  ll xx = 0, yy = 0;
  ll mx = 0, my = 0;
  for (int i = 0; i < h; ++i) {
    mx = max(mx, r[i]);
  }
  for (int i = 0; i < w; ++i) {
    my = max(my, c[i]);
  }
  for (int i = 0; i < h; ++i) {
    if (mx == r[i])
      mxx[i] = true;
  }
  for (int i = 0; i < w; ++i) {
    if (c[i] == my)
      myy[i] = true;
  }
  for (auto it : mxx)
    for (auto it2 : myy) {
      if (g[{it.first, it2.first}] != 1) {
        ans = max(ans, mx + my);
        break;
      }
    }
  cout << ans << endl;
}

int32_t main() {
  IOS ll T = 1;
  // cin >> T;
  for (ll i = 1; i <= T; ++i) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve() {
  ll h, w, m;
  cin >> h >> w >> m;
  map<ll, ll> r, c;
  map<pair<ll, ll>, ll> g;
  for (int i = 0; i < m; ++i) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    g[{x, y}] = 1;
    r[x]++;
    c[y]++;
  }
  ll ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans = max(ans, r[i] + c[j] - g[{i, j}]);
    }
  }
  cout << ans << endl;
}

int32_t main() {
  IOS ll T = 1;
  // cin >> T;
  for (ll i = 1; i <= T; ++i) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr << #x << '=' << x << endl;
int h, w, m;
struct uzi {
  int x, y;
  bool operator<(const uzi &t) const {
    if (x == t.x)
      return y < t.y;
    return x < t.x;
  }
} p[N];
int L[N], R[N];
int t[N << 2];
#define mid (l + r >> 1)
#define ls o << 1
#define rs o << 1 | 1
void build(int o, int l, int r) {
  if (l == r) {
    t[o] = R[l];
    return;
  }
  build(ls, l, mid);
  build(rs, mid + 1, r);
  t[o] = max(t[ls], t[rs]);
}
void up(int o, int l, int r, int x, int y) {
  if (l == r) {
    t[o] += y;
    //   cout<<l<<' '<<r<<' '<<t[o]<<endl;
    return;
  }
  if (x <= mid)
    up(ls, l, mid, x, y);
  else
    up(rs, mid + 1, r, x, y);
  t[o] = max(t[ls], t[rs]);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> h >> w >> m;
  for (int i = 1; i <= m; i++) {
    cin >> p[i].x >> p[i].y;
    L[p[i].x]++;
    R[p[i].y]++;
  }
  build(1, 1, w);
  sort(p + 1, p + 1 + m);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, L[p[i].x] + R[p[i].y] - 1);
  }
  int l = 1;
  for (int i = 1; i <= h; i++) {
    int r = l;

    while (r + 1 <= m && p[r + 1].x == i)
      r++;
    if (p[r].x > i)
      continue;

    // cout<<"i=="<<i<<' '<<l<<' '<<r<<endl;
    ///  cout<<i<<' '<<L[i]<<' '<<t[1]<<endl;
    for (int j = l; j <= r; j++) {
      up(1, 1, w, p[j].y, -1);
    }
    // cout<<i<<' '<<L[i]<<' '<<t[1]<<endl;
    ans = max(ans, L[i] + t[1]);
    for (int j = l; j <= r; j++) {
      up(1, 1, w, p[j].y, 1);
    }
    l = r + 1;
  }
  cout << ans << '\\n';
  return 0;
}

Error: WA

Fixed submission:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr << #x << '=' << x << endl;
int h, w, m;
struct uzi {
  int x, y;
} p[N];
int L[N], R[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> h >> w >> m;
  for (int i = 1; i <= m; i++) {
    cin >> p[i].x >> p[i].y;
    L[p[i].x]++;
    R[p[i].y]++;
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, L[p[i].x] + R[p[i].y] - 1);
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

using P = pair<int, int>;

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

  int h, w;
  vector<int> hc(H, 0), wc(W, 0);
  set<pair<int, int>> s;
  int hmax = 0;
  int wmax = 0;
  for (int i = 0; i < M; ++i) {
    cin >> h >> w;
    h--;
    w--;
    hc[h]++;
    wc[w]++;
    s.emplace(P(h, w));
  }

  vector<int> seth, setw;
  for (int i = 0; i < H; i++) {
    if (hmax < hc[i]) {
      hmax = hc[i];
    }
  }
  for (int i = 0; i < W; i++) {
    if (wmax < wc[i]) {
      wmax = wc[i];
    }
  }

  for (int i = 0; i < H; i++) {
    if (hc[i] == hmax) {
      seth.push_back(i);
    }
  }
  for (int i = 0; i < W; i++) {
    if (wc[i] == wmax) {
      setw.push_back(i);
    }
  }

  int ans = wmax + hmax;
  for (int i : seth)
    for (int j : setw) {
      if (s.count(P(i, j)) != 0)
        continue;
      cout << ans << endl;
      return 0;
    }

  ans--;

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

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

  vector<int> s(H, 0);
  int hc[1000000] = {};
  int wc[1000000] = {};

  int h, w;
  int hmax = 0;
  int wmax = 0;
  for (int i = 0; i < M; ++i) {
    cin >> h >> w;
    s[h] = w;
    hc[h]++;
    wc[w]++;
    if (hmax < hc[h])
      hmax = hc[h];
    if (wmax < wc[w])
      wmax = hc[w];
  }

  long long ans = (long long)(hmax + wmax);
  if (s[hmax] == wmax)
    ans--;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

int main() {
  int h, w, m;
  scanf("%d %d %d", &h, &w, &m);
  vector<pair<int, int>> viiMine;
  vector<int> viHeightCount(h + 1, 0);
  vector<int> viWidthCount(w + 1, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    viHeightCount[a]++;
    viWidthCount[b]++;
    viiMine.push_back(make_pair(a, b));
  }

  int hMax = 0;
  long hCount = 0;
  for (int i = 1; i <= h; i++) {
    hMax = max(hMax, viHeightCount[i]);
  }
  set<int> siHeightMaxPoint;
  for (int i = 1; i <= h; i++) {
    if (hMax == viHeightCount[i]) {
      siHeightMaxPoint.insert(i);
      hCount++;
    }
  }

  int wMax = 0;
  long wCount = 0;
  for (int i = 1; i <= w; i++) {
    wMax = max(wMax, viWidthCount[i]);
  }
  set<int> siWidthMaxPoint;
  for (int i = 1; i <= w; i++) {
    if (wMax == viWidthCount[i]) {
      siWidthMaxPoint.insert(i);
      wCount++;
    }
  }

  long iIntersectionCount = 0;
  for (int i = 0; i < m; i++) {
    int a = viiMine[i].first;
    int b = viiMine[i].second;
    if (siHeightMaxPoint.find(a) != siHeightMaxPoint.end() &&
        siWidthMaxPoint.find(b) != siWidthMaxPoint.end()) {
      iIntersectionCount++;
    }
  }

  if (iIntersectionCount == hCount * wCount) {
    printf("%d", hMax + wMax - 1);
  } else {
    printf("%d", hMax + wMax);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

int main() {
  int h, w, m;
  scanf("%d %d %d", &h, &w, &m);
  vector<pair<int, int>> viiMine;
  vector<int> viHeightCount(h + 1, 0);
  vector<int> viWidthCount(w + 1, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    viHeightCount[a]++;
    viWidthCount[b]++;
    viiMine.push_back(make_pair(a, b));
  }

  int hMax = 0;
  int hCount = 0;
  for (int i = 1; i <= h; i++) {
    hMax = max(hMax, viHeightCount[i]);
  }
  set<int> siHeightMaxPoint;
  for (int i = 1; i <= h; i++) {
    if (hMax == viHeightCount[i]) {
      siHeightMaxPoint.insert(i);
      hCount++;
    }
  }

  int wMax = 0;
  int wCount = 0;
  for (int i = 1; i <= w; i++) {
    wMax = max(wMax, viWidthCount[i]);
  }
  set<int> siWidthMaxPoint;
  for (int i = 1; i <= h; i++) {
    if (wMax == viWidthCount[i]) {
      siWidthMaxPoint.insert(i);
      wCount++;
    }
  }

  int iIntersectionCount = 0;
  for (int i = 0; i < m; i++) {
    int a = viiMine[i].first;
    int b = viiMine[i].second;
    if (siHeightMaxPoint.find(a) != siHeightMaxPoint.end() &&
        siWidthMaxPoint.find(b) != siWidthMaxPoint.end()) {
      iIntersectionCount++;
    }
  }

  if (iIntersectionCount == hCount * wCount) {
    printf("%d", hMax + wMax - 1);
  } else {
    printf("%d", hMax + wMax);
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int H, W, M;
set<i_i> st;

void input() {
  cin >> H >> W >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    st.insert({a, b});
  }
}

void solve() {
  map<int, int> mph, mpw;
  int hmaxval = 0;
  int wmaxval = 0;
  vector<int> hmax, wmax;
  for (auto tmp : st) {
    chmax(hmaxval, ++mph[tmp.first]);
    chmax(wmaxval, ++mpw[tmp.second]);
  }
  for (auto tmp : mph) {
    if (hmaxval == tmp.second)
      hmax.push_back(tmp.first);
  }
  for (auto tmp : mpw) {
    if (wmaxval == tmp.second)
      wmax.push_back(tmp.first);
  }
  int ANS = hmaxval + wmaxval - 1;
  for (auto h : hmax) {
    for (auto w : wmax) {
      if (st.find({h, w}) == st.end()) {
        ANS++;
        cout << ANS << endl;
        return;
      }
    }
  }
  cout << ANS << endl;
}

int main() {
  input();
  solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using p = pair<int, int>;
int main() {
  int h, w;
  long long m;
  cin >> h >> w >> m;
  vector<int> xx(h);
  vector<int> yy(w);
  set<p> s;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    xx[x] += 1;
    yy[y] -= 1;
    s.emplace(x, y);
  }
  int mx = 0;
  int my = 0;
  rep(i, h) mx = max(mx, xx[i]);
  rep(i, w) my = max(my, yy[i]);
  int ans = mx + my;
  vector<int> xm, ym;
  rep(i, h) {
    if (xx[i] == mx)
      xm.push_back(i);
  }
  rep(i, w) {
    if (yy[i] == my)
      ym.push_back(i);
  }
  for (int j : xm)
    for (int k : ym) {
      if (s.count(p(j, k))) {
        ans += 1;
        break;
      }
    }
  ans -= 1;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> hmap;
  map<int, int> wmap;
  map<pair<int, int>, int> ma;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    hmap[a]++;
    wmap[b]++;
    ma[{a, b}]++;
  }
  int maxcnt = 0;
  vector<pair<int, int>> hcnts;
  for (auto u : hmap)
    hcnts.push_back({u.second, u.first});
  vector<pair<int, int>> vcnts;
  for (auto u : wmap)
    vcnts.push_back({u.second, u.first});
  sort(hcnts.begin(), hcnts.end());
  reverse(hcnts.begin(), hcnts.end());
  sort(vcnts.begin(), vcnts.end());
  reverse(vcnts.begin(), vcnts.end());
  int bignum = hcnts[0].first;
  int bignum2 = vcnts[0].first;
  int maxnum = 0;
  for (int i = 0; i < hcnts.size(); i++) {
    if (hcnts[i].first < bignum)
      break;
    for (int j = 0; j < vcnts.size(); j++) {
      if (vcnts[j].first < bignum2)
        break;
      int currnum = hcnts[i].first + vcnts[j].first -
                    ma[{hcnts[i].second, vcnts[j].second}];
      maxnum = max(maxnum, currnum);
      if (maxnum == bignum + bignum2)
        break;
    }
    if (maxnum == bignum + bignum2)
      break;
  }
  cout << maxnum << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> hmap;
  map<int, int> wmap;
  map<pair<int, int>, int> ma;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    hmap[a]++;
    wmap[b]++;
    ma[{a, b}]++;
  }
  int maxcnt = 0;
  vector<pair<int, int>> hcnts;
  for (auto u : hmap)
    hcnts.push_back({u.second, u.first});
  vector<pair<int, int>> vcnts;
  for (auto u : wmap)
    vcnts.push_back({u.second, u.first});
  sort(hcnts.begin(), hcnts.end());
  reverse(hcnts.begin(), hcnts.end());
  sort(vcnts.begin(), vcnts.end());
  reverse(vcnts.begin(), vcnts.end());
  int bignum = hcnts[0].first;
  int bignum2 = vcnts[0].first;
  int maxnum = 0;
  for (int i = 0; i < hcnts.size(); i++) {
    if (hcnts[i].first < bignum)
      break;
    for (int j = 0; j < vcnts.size(); j++) {
      if (vcnts[j].first < bignum2)
        break;
      int currnum = hcnts[i].first + vcnts[j].first -
                    ma[{hcnts[i].second, vcnts[j].second}];
      maxnum = max(maxnum, currnum);
    }
  }
  cout << maxnum << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll, ll>;
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <set>

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h(M), w(M);
  set<P> s;
  rep(i, M) {
    cin >> h[i] >> w[i];
    P p = make_pair(h[i] - 1, w[i] - 1);
    s.insert(p);
  }
  vector<ll> cnt1(300010), cnt2(300010);
  ll ans1(0), ans2(0);
  rep(i, M) {
    ll k;
    k = h[i];
    k--;
    cnt1[k]++;
    ans1 = max(ans1, cnt1[k]);
  }
  rep(i, M) {
    int k;
    k = w[i];
    k--;
    cnt2[k]++;
    ans2 = max(ans2, cnt2[k]);
  }

  vector<ll> a, b;
  rep(i, max(W, H)) {
    if (cnt1[i] == ans1) {
      a.push_back(i);
    }
    if (cnt2[i] == ans2) {
      b.push_back(i);
    }
  }

  rep(i, a.size()) {
    rep(j, b.size()) {
      P p = make_pair(a[i], b[j]);
      if (s.count(p) == 0) {
        cout << ans1 + ans2;
        return 0;
      }
    }
  }
  cout << ans1 + ans2 - 1;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll, ll>;
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <set>

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h(M), w(M);
  set<P> s;
  rep(i, M) {
    cin >> h[i] >> w[i];
    P p = make_pair(h[i] - 1, w[i] - 1);
    s.insert(p);
  }
  vector<ll> cnt1(H), cnt2(W);
  ll ans1(0), ans2(0);
  rep(i, M) {
    ll k;
    k = h[i];
    k--;
    cnt1[k]++;
    ans1 = max(ans1, cnt1[k]);
  }
  rep(i, M) {
    int k;
    k = w[i];
    k--;
    cnt2[k]++;
    ans2 = max(ans2, cnt2[k]);
  }

  vector<ll> a, b;
  rep(i, M) {
    if (cnt1[i] == ans1) {
      a.push_back(i);
    }
    if (cnt2[i] == ans2) {
      b.push_back(i);
    }
  }
  rep(i, a.size()) {
    rep(j, b.size()) {
      P p = make_pair(a[i], b[j]);
      if (s.count(p) == 0) {
        cout << ans1 + ans2;
        return 0;
      }
    }
  }
  cout << ans1 + ans2 - 1;
  return 0;
}