alexjercan/bugnet huggingface dataset:
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <deque>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<pair<int, int>> point;
  set<long long> pointPos;

  vector<int> h(H);
  vector<int> w(W);
  for (int i = 0; i < M; i++) {
    int x = 0;
    int y = 0;
    cin >> y >> x;
    x--;
    y--;
    point.push_back({x, y});
    pointPos.insert(x * (long long)H + y);
    w[x]++;
    h[y]++;
  }

  int ymax = 0;
  vector<int> ypos;
  int xmax = 0;
  vector<int> xpos;

  for (int i = 0; i < H; i++) {
    if (ymax == h[i]) {
      ypos.push_back(i);
    }
    if (ymax < h[i]) {
      ypos.clear();
      ypos.push_back(i);
      ymax = h[i];
    }
  }
  for (int i = 0; i < W; i++) {
    if (xmax == w[i]) {
      xpos.push_back(i);
    }
    if (xmax < w[i]) {
      xpos.clear();
      xpos.push_back(i);
      xmax = w[i];
    }
  }
  int a = 0;
  if (xpos.size() * ypos.size() <= M) {
    for (int x = 0; x < xpos.size(); x++) {
      for (int y = 0; y < ypos.size(); y++) {
        long long b = xpos[x] * (long long)H + ypos[y];
        if (pointPos.erase(b) == 1) {
          a++;
        }
      }
    }
  }
  if (a == (xpos.size() * ypos.size())) {
    cout << xmax + ymax - 1;

  } else {
    cout << xmax + ymax;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<pair<int, int>> point;
  vector<int> h(H);
  vector<int> w(W);
  for (int i = 0; i < M; i++) {
    int x = 0;
    int y = 0;
    cin >> y >> x;
    x--;
    y--;
    point.push_back({x, y});
    w[x]++;
    h[y]++;
  }

  int ymax = 0;
  vector<int> ypos;
  int xmax = 0;
  vector<int> xpos;

  for (int i = 0; i < H; i++) {
    if (ymax == h[i]) {
      ypos.push_back(i);
    }
    if (ymax < h[i]) {
      ypos.clear();
      ypos.push_back(i);
      ymax = h[i];
    }
  }
  for (int i = 0; i < W; i++) {
    if (xmax == w[i]) {
      xpos.push_back(i);
    }
    if (xmax < w[i]) {
      xpos.clear();
      xpos.push_back(i);
      xmax = w[i];
    }
  }
  int a = 0;
  if (xpos.size() * ypos.size() <= M) {
    for (int i = 0; i < point.size(); i++) {
      for (int x = 0; x < xpos.size(); x++) {
        if (xpos[x] == point[i].first) {
          for (int y = 0; y < ypos.size(); y++) {
            if (ypos[y] == point[i].second) {
              a++;
            }
          }
        }
      }
    }
  }
  if (a == (xpos.size() * ypos.size())) {
    cout << xmax + ymax - 1;

  } else {
    cout << xmax + ymax;
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

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

  std::vector<std::pair<int, int>> pos;
  std::vector<int> hist_h(H, 0), hist_w(W, 0);

  for (int i = 0; i < M; i++) {
    int h, w;
    std::cin >> h >> w;
    h--;
    w--;
    hist_h[h] += 1;
    hist_w[w] += 1;
    pos.emplace_back(h, w);
  }

  int max = 0;
  long long int count = 0;
  for (auto p : pos) {
    int val = hist_h[p.first] + hist_w[p.second] - 1;
    if (val > max) {
      max = val;
      count = 1;
    } else if (val == max) {
      count++;
    }
  }

  int max_h = hist_h[0];
  long long int count_h = 1;
  for (int i = 1; i < H; i++) {
    if (hist_h[i] == max_h) {
      count_h++;
    } else if (hist_h[i] > max_h) {
      max_h = hist_h[i];
      count_h = 1;
    }
  }

  int max_w = hist_w[0];
  long long int count_w = 1;
  for (int i = 1; i < W; i++) {
    if (hist_w[i] == max_w) {
      count_w++;
    } else if (hist_w[i] > max_w) {
      max_w = hist_w[i];
      count_w = 1;
    }
  }

  if (max == max_h + max_w - 1 && count_h * count_w <= count) {
    std::cout << max_h + max_w - 1 << std::endl;
  } else {
    std::cout << max_h + max_w << std::endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

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

  std::vector<std::vector<int>> pos(H, std::vector<int>(W, 0));
  std::vector<int> hist_h(H, 0), hist_w(W, 0);

  for (int i = 0; i < M; i++) {
    int h, w;
    std::cin >> h >> w;
    h--;
    w--;
    hist_h[h] += 1;
    hist_w[w] += 1;
    pos.emplace_back(h, w);
    pos[h][w] = 1;
  }

  // int max = 0;
  // for (auto p : pos) {
  //     max = std::max(max, hist_h[p.first] + hist_w[p.second] - 1);
  // }
  // std::cout << max << std::endl;
  int max = 0;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      max = std::max(max, hist_h[y] + hist_w[x] - pos[y][x]);
    }
  }
  std::cout << max << std::endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> ver(w), hol(h);
  set<pair<int, int>> bombs;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    hol[hi]++;
    ver[wi]++;
    bombs.insert({hi, wi});
  }
  vector<int> hs, ws;
  int hM = 0, wM = 0;
  rep(i, h) {
    if (hol[i] > hM) {
      hM = hol[i];
      hs = {i};
    } else if (hol[i] == hM) {
      hs.push_back(i);
    }
  }
  rep(i, w) {
    if (ver[i] > wM) {
      wM = ver[i];
      ws = {i};
    } else if (ver[i] == wM) {
      ws.push_back(i);
    }
  }
  int ans = hM + wM - 1;
  for (int i : hs) {
    for (int j : ws) {
      if (!bombs.count({i, j})) {
        ans = hM + wM;
        goto output;
      }
    }
  }
output:
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> ver(w), hol(h);
  set<pair<int, int>> bombs;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    hol[hi]++;
    ver[wi]++;
    bombs.insert({hi, wi});
  }
  vector<int> hs, ws;
  int hM = 0, wM = 0;
  rep(i, h) {
    if (hol[i] > hM) {
      hM = hol[i];
      hs = {i};
    } else if (hol[i] == hM) {
      hs.push_back(i);
    }
  }
  rep(i, w) {
    if (ver[i] > wM) {
      wM = ver[i];
      ws = {i};
    } else if (ver[i] == wM) {
      ws.push_back(i);
    }
  }
  int ans = hM + wM - 1;
  for (int i : hs) {
    for (int j : ws) {
      if (!bombs.count({i, j}))
        ans = hM + wM;
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<set<ll>> g(h);
  vl nh(h, 0), nw(w, 0);
  rep(i, m) {
    ll u, v;
    cin >> u >> v;
    u--, v--;
    g[u].insert(v);
    nh[u]++;
    nw[v]++;
  }
  set<P, greater<P>> st;
  rep(j, w) st.insert({nw[j], j});
  P mx = *st.begin();
  ll ans = 0;
  rep(i, h) {
    ll now = mx.first;
    if (g[i].count(mx.second))
      now--;
    for (auto v : st) {
      if (g[i].count(v.second))
        continue;
      now = max(now, v.first);
      break;
    }
    now += nh[i];
    ans = max(ans, now);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  set<P> st;
  vl nh(h, 0), nw(w, 0);
  rep(i, m) {
    ll u, v;
    cin >> u >> v;
    u--, v--;
    st.insert({u, v});
    nh[u]++;
    nw[v]++;
  }
  ll ans = 0;
  rep(i, h) rep(j, w) {
    ll now = nh[i] + nw[j];
    if (st.count({i, j}))
      now--;
    ans = max(ans, now);
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &x) {
  int f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 3) + (x << 1) + (c ^ 48);
  x *= f;
}
const int N = 3e5 + 5;
int n, m, p, x[N], y[N];
pair<int, int> rsum[N], csum[N];
map<pair<int, int>, bool> H;
int main() {
  read(n);
  read(m);
  read(p);

  for (int i = 1; i <= n; i++)
    rsum[i].second = i;
  for (int i = 1; i <= m; i++)
    csum[i].second = i;

  for (int i = 1; i <= p; i++) {
    read(x[i]);
    read(y[i]);
    rsum[x[i]].first++;
    csum[y[i]].first++;
  }
  sort(rsum + 1, rsum + n + 1);
  sort(csum + 1, csum + m + 1);

  int Rpos = n, Cpos = m;
  int sum = rsum[n].first + csum[m].first;
  while (Rpos > 1 && rsum[Rpos - 1].first == rsum[n].first)
    Rpos--;
  while (Cpos > 1 && csum[Cpos - 1].first == csum[m].first)
    Cpos--;

  if ((LL)(n - Rpos + 1) * (m - Cpos + 1) <= p) {
    bool flag = 1;
    for (int i = 1; i <= p; i++)
      H[make_pair(x[i], y[i])] = 1;
    for (int i = Rpos; i <= n; i++)
      for (int j = Cpos; j <= m; j++)
        if (!H[make_pair(rsum[i].second, csum[j].second)]) {
          flag = 0;
          break;
        }
    sum -= flag;
  }

  printf("%d\\n", sum);
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, pair<int, int>> node;
template <typename T> inline void read(T &x) {
  int f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 3) + (x << 1) + (c ^ 48);
  x *= f;
}
const int N = 3e5 + 5;
int n, m, p, x[N], y[N];
pair<int, int> rsum[N], csum[N];
map<pair<int, int>, bool> H;
priority_queue<node> q;
int main() {
  read(n);
  read(m);
  read(p);

  for (int i = 1; i <= n; i++)
    rsum[i].second = i;
  for (int i = 1; i <= m; i++)
    csum[i].second = i;

  for (int i = 1; i <= p; i++) {
    read(x[i]);
    read(y[i]);
    rsum[x[i]].first++;
    csum[y[i]].first++;
    H[make_pair(x[i], y[i])] = 1;
  }
  sort(rsum + 1, rsum + n + 1);
  sort(csum + 1, csum + m + 1);

  int ans = 0;
  q.push(make_pair(rsum[n].first + csum[m].first, make_pair(n, m)));

  while (!q.empty()) {
    int val = q.top().first, rpos = q.top().second.first,
        cpos = q.top().second.second;
    q.pop();

    if (H[make_pair(rsum[rpos].second, csum[cpos].second)])
      val--;

    if (val < ans)
      break;
    ans = max(ans, val);
    if (rpos > 1)
      q.push(make_pair(rsum[rpos - 1].first + csum[cpos].first,
                       make_pair(rpos - 1, cpos)));
    if (cpos > 1)
      q.push(make_pair(rsum[rpos].first + csum[cpos - 1].first,
                       make_pair(rpos, cpos - 1)));
  }

  printf("%d\\n", ans);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long int
#define all(v) v.begin(), v.end()
#define ov(v)                                                                  \\
  for (int i = 0; i < (v).size(); i++)                                         \\
    cout << v[i] << " ";                                                       \\
  cout << endl;
#define N 1001
using namespace std;
void solve() {
  int n, m, t;
  cin >> n >> m >> t;
  vector<int> row(n, 0), col(m, 0);
  vector<pair<int, int>> cor(t);
  multiset<int> se;
  set<int> rc[n];
  int ans = 0;
  for (int i = 0; i < t; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    cor[i] = {u, v};
    row[u]++;
    rc[u].insert(v);
    col[v]++;
  }
  for (int i = 0; i < t; i++) {
    int x = cor[i].first;
    int y = cor[i].second;
    ans = max(ans, row[x] + col[y] - 1);
  }
  for (int i = 0; i < m; i++)
    se.insert(col[i]);

  for (int i = 0; i < n; i++) {
    for (auto j : rc[i]) {
      auto it = se.find(col[j]);
      se.erase(it);
    }
    if (!se.empty()) {
      int mx = *se.rbegin();
      ans = max(ans, mx + row[i]);
    }
    for (auto j : rc[i]) {
      se.insert(col[j]);
    }
  }
  cout << ans << endl;
}
signed main() {
  // int t;
  // cin>>t;
  // while(t--)
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long int
#define all(v) v.begin(), v.end()
#define ov(v)                                                                  \\
  for (int i = 0; i < (v).size(); i++)                                         \\
    cout << v[i] << " ";                                                       \\
  cout << endl;
#define N 1001
using namespace std;
void solve() {
  int n, m, t;
  cin >> n >> m >> t;
  vector<int> row(n, 0), col(m, 0);
  vector<pair<int, int>> cor(t);
  multiset<int> se;
  set<int> rc[n];
  int ans = 0;
  for (int i = 0; i < t; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    cor[i] = {u, v};
    row[u]++;
    rc[u].insert(v);
    col[v]++;
  }
  for (int i = 0; i < t; i++) {
    int x = cor[i].first;
    int y = cor[i].second;
    ans = max(ans, row[x] + col[y] - 1);
  }
  for (int i = 0; i < m; i++)
    se.insert(col[i]);
  for (int i = 0; i < n; i++) {
    for (auto j : rc[i]) {
      auto it = se.find(col[j]);
      se.erase(it);
    }
    int mx = *se.rbegin();
    ans = max(ans, mx + row[i]);
    for (auto j : rc[i]) {
      se.insert(col[j]);
    }
  }
  cout << ans << endl;
}
signed main() {

  // int t;
  // cin>>t;
  // while(t--)
  solve();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  const int SIZE = 300010;
  int H, W, M, h[SIZE], w[SIZE], x[SIZE], y[SIZE];
  cin >> H >> W >> M;
  for (int i = 1; i <= H; ++i) {
    x[i] = 0;
  }
  for (int i = 1; i <= W; ++i) {
    y[i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    cin >> h[i] >> w[i];
    x[h[i]]++;
    y[w[i]]++;
  }

  int x_max = 0;
  for (int i = 1; i <= H; ++i) {
    x_max = max(x_max, x[i]);
  }

  int x_sum = 0;
  for (int i = 1; i <= H; ++i) {
    if (x[i] == x_max)
      x_sum++;
  }

  int y_max = 0;
  for (int i = 1; i <= W; ++i) {
    y_max = max(y_max, y[i]);
  }

  int y_sum = 0;
  for (int i = 1; i <= W; ++i) {
    if (y[i] == y_max)
      y_sum++;
  }

  int m_sum = 0;
  for (int i = 0; i < M; ++i) {
    if (x[h[i]] == x_max && y[w[i]] == y_max)
      m_sum++;
  }

  if (m_sum == x_sum * y_sum) {
    cout << x_max + y_max - 1 << endl;
  } else {
    cout << x_max + y_max << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  const int SIZE = 30010;
  int H, W, M, h[SIZE], w[SIZE], x[SIZE], y[SIZE];
  cin >> H >> W >> M;
  for (int i = 1; i <= H; ++i) {
    x[i] = 0;
  }
  for (int i = 1; i <= W; ++i) {
    y[i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    cin >> h[i] >> w[i];
    x[h[i]]++;
    y[w[i]]++;
  }

  int x_max = 0;
  for (int i = 1; i <= H; ++i) {
    x_max = max(x_max, x[i]);
  }

  int x_sum = 0;
  for (int i = 1; i <= H; ++i) {
    if (x[i] == x_max)
      x_sum++;
  }

  int y_max = 0;
  for (int i = 1; i <= W; ++i) {
    y_max = max(y_max, y[i]);
  }

  int y_sum = 0;
  for (int i = 1; i <= W; ++i) {
    if (y[i] == y_max)
      y_sum++;
  }

  int m_sum = 0;
  for (int i = 0; i < M; ++i) {
    if (x[h[i]] == x_max && y[w[i]] == y_max)
      m_sum++;
  }

  if (m_sum == x_sum * y_sum) {
    cout << x_max + y_max - 1 << endl;
  } else {
    cout << x_max + y_max << endl;
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>
using namespace std;
const int N = 3e5 + 7;
vector<int> vecc, vecr;
int mxr, mxc, row[N], col[N];
set<pair<int, int>> st;

int32_t main() {
  int h, w, m;
  scanf("%d%d%d", &h, &w, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[x]++;
    col[y]++;
    if (mxr < row[x]) {
      mxr = row[x];
      vecr.clear();
    }
    if (mxr == row[x])
      vecr.push_back(x);

    if (mxc < col[y]) {
      mxc = col[y];
      vecc.clear();
    }
    if (mxc == col[y])
      vecc.push_back(y);
    st.insert({x, y});
  }
  int _is = 1;
  for (int i = 0; i < vecr.size(); i++) {
    int x = vecr[i];
    for (int j = 0; j < vecc.size(); j++) {
      int y = vecc[j];
      if (st.count({x, y}) == 0) {
        _is = 0;
        break;
      }
    }
    if (_is == 0)
      break;
  }
  printf("%d\\n", mxr + mxc - _is);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
vector<int> vecc, vecr;
int mxr, mxc, row[N], col[N];
set<pair<int, int>> st;

int main() {
  int h, w, m;
  scanf("%d%d%d", &h, &w, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[x]++;
    col[y]++;
    if (mxr < row[x]) {
      mxr = row[x];
      vecr.clear();
    }
    if (mxr == row[x])
      vecr.push_back(x);

    if (mxc < col[y]) {
      mxc = col[y];
      vecc.clear();
    }
    if (mxc == col[y])
      vecc.push_back(y);
    st.insert({x, y});
  }
  int _is = 1;
  for (int i : vecr)
    for (int j : vecc)
      if (_is == 1 && st.find({i, j}) == st.end()) {
        _is = 0;
        break;
      }
  printf("%d\\n", mxr + mxc - _is);
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

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

  vector<int> Hi(H, 0);
  vector<int> Wi(W, 0);
  set<pair<int, int>> bom;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    Hi[h - 1]++;
    Wi[w - 1]++;
    bom.insert(make_pair(h - 1, w - 1));
  }

  int max_h = 0;
  int max_w = 0;

  for (int i = 0; i < H; i++) {
    max_h = max(max_h, Hi[i]);
  }
  for (int i = 0; i < W; i++) {
    max_w = max(max_w, Wi[i]);
  }

  vector<int> X(0);
  vector<int> Y(0);

  for (int i = 0; i < H; i++) {
    if (Hi[i] == max_h) {
      X.push_back(i);
    }
  }
  for (int i = 0; i < W; i++) {
    if (Wi[i] == max_w) {
      Y.push_back(i);
    }
  }

  for (auto p : X) {
    for (auto q : Y) {
      if (bom.find(make_pair(p, q)) == bom.end()) {
        cout << max_h + max_w << endl;
        return 0;
      }
    }
  }

  cout << max_h + max_w - 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

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

  vector<int> Hi(H, 0);
  vector<int> Wi(W, 0);
  vector<vector<bool>> judge(H, vector<bool>(W, false));
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    Hi[h - 1]++;
    Wi[w - 1]++;
    judge[h - 1][w - 1] = true;
  }

  int max_h = 0;
  int max_w = 0;

  for (int i = 0; i < H; i++) {
    max_h = max(max_h, Hi[i]);
  }
  for (int i = 0; i < W; i++) {
    max_w = max(max_w, Wi[i]);
  }

  vector<int> X(0);
  vector<int> Y(0);

  for (int i = 0; i < H; i++) {
    if (Hi[i] == max_h) {
      X.push_back(i);
    }
  }
  for (int i = 0; i < W; i++) {
    if (Wi[i] == max_w) {
      Y.push_back(i);
    }
  }

  const int xx = X.size();
  const int yy = Y.size();

  if (xx * yy > M) {
    cout << max_h + max_w << endl;
  } else {
    for (auto p : X) {
      for (auto q : Y) {
        if (!judge[p][q]) {
          cout << max_h + max_w << endl;
          return 0;
        }
      }
    }
  }
  cout << max_h + max_w - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> ob_r(H, 0), ob_c(W, 0);
  map<Pll, ll> p;

  rep(0, i, M) {
    ll h, w;
    cin >> h >> w;
    h--;
    w--;
    p[make_pair(h, w)]++;
    ob_r.at(h)++;
    ob_c.at(w)++;
  }

  ll max_r = 0, max_c = 0;
  rep(0, i, H) { max_r = max(max_r, ob_r.at(i)); }
  rep(0, i, W) { max_c = max(max_c, ob_c.at(i)); }

  vector<ll> r_i, c_i;
  rep(0, i, H) {
    if (max_r == ob_r.at(i)) {
      r_i.push_back(i);
    }
  }
  rep(0, i, W) {
    if (max_c == ob_c.at(i)) {
      c_i.push_back(i);
    }
  }

  ll ans = max_r + max_c;

  for (auto r : r_i) {
    for (auto c : c_i) {
      if (p[make_pair(r, c)] == 0) {
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << ans - 1 << endl;
}

Error: WA

Fixed submission:

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<vector<ll>> grid(H, vector<ll>(W, 0));
  vector<ll> ob_r(H, 0), ob_c(W, 0);

  rep(0, i, M) {
    ll h, w;
    cin >> h >> w;
    h--;
    w--;
    ob_r.at(h)++;
    ob_c.at(w)++;
    grid.at(h).at(w) = 1;
  }

  ll max_r = 0, max_c = 0;
  rep(0, i, H) { max_r = max(max_r, ob_r.at(i)); }
  rep(0, i, W) { max_c = max(max_c, ob_c.at(i)); }

  /*

  vector<ll> r_i, c_i;
  rep(0, i, H)
  {
      if (max_r == ob_r.at(i))
      {
          r_i.push_back(i);
      }
  }
  rep(0, i, W)
  {
      if (max_c == ob_c.at(i))
      {
          c_i.push_back(i);
      }
  }

  */

  ll ans = max_r + max_c;

  cout << ans - 1 << endl;
}