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

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

typedef struct {
  int h;
  int w;
} grid_struct;

static int h_count[300016], w_count[300016];
grid_struct grid[300016];

int main() {
  int h_max, w_max, m;
  int h_count_max = 0, w_count_max = 0;
  long long h_max_array_count = 0, w_max_array_count = 0, bom_count = 0;

  cin >> h_max >> w_max >> m;

  for (int i = 0; i < m; i++) {
    /* 爆弾座標取り込み */
    cin >> grid[i].h >> grid[i].w;

    /* 爆弾座標それぞれをカウント */
    h_count[grid[i].h]++;
    w_count[grid[i].w]++;
  }

  /* H, Wそれぞれの爆弾の最大個数を求める */
  for (int h = 1; h <= h_max; h++) {
    if (h_count_max < h_count[h]) {
      h_count_max = h_count[h];
    }
  }
  for (int w = 1; w <= w_max; w++) {
    if (w_count_max < w_count[w]) {
      w_count_max = w_count[w];
    }
  }

  /* H, Wそれぞれの爆弾の最大個数のリストを作成 */
  for (int h = 1; h <= h_max; h++) {
    if (h_count_max == h_count[h]) {
      h_max_array_count++;
    }
  }
  for (int w = 1; w <= w_max; w++) {
    if (w_count_max == w_count[w]) {
      w_max_array_count++;
    }
  }

  /* 爆弾リサーチ */
  for (int i = 0; i < m; i++) {
    if (h_count_max == h_count[grid[i].h] &&
        w_count_max == w_count[grid[i].w]) {
      bom_count++;
    }
  }

  if (bom_count < h_max_array_count * w_max_array_count)
    cout << h_count_max + w_count_max << endl;
  else
    cout << h_count_max + w_count_max - 1 << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

typedef struct {
  int h;
  int w;
} grid_struct;

static int h_count[300000], w_count[300000];
static int h_max_array[300000], w_max_array[300000];
grid_struct grid[300000];

int main() {
  int h_max, w_max, m;
  int h_count_max = 0, w_count_max = 0;
  int h_max_array_count = 0, w_max_array_count = 0, bom_count = 0;

  cin >> h_max >> w_max >> m;

  for (int i = 0; i < m; i++) {
    /* 爆弾座標取り込み */
    cin >> grid[i].h >> grid[i].w;

    /* 爆弾座標それぞれをカウント */
    h_count[grid[i].h]++;
    w_count[grid[i].w]++;
  }

  /* H, Wそれぞれの爆弾の最大個数を求める */
  for (int h = 1; h <= h_max; h++) {
    if (h_count_max < h_count[h]) {
      h_count_max = h_count[h];
    }
  }
  for (int w = 1; w <= w_max; w++) {
    if (w_count_max < w_count[w]) {
      w_count_max = w_count[w];
    }
  }

  /* H, Wそれぞれの爆弾の最大個数のリストを作成 */
  for (int h = 1; h <= h_max; h++) {
    if (h_count_max == h_count[h]) {
      h_max_array[h_max_array_count] = h;
      h_max_array_count++;
    }
  }
  for (int w = 1; w <= w_max; w++) {
    if (w_count_max == w_count[w]) {
      w_max_array[w_max_array_count] = w;
      w_max_array_count++;
    }
  }

  /* 爆弾リサーチ */
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < h_max_array_count; j++) {
      if (grid[i].h == h_max_array[j]) {
        for (int k = 0; k < w_max_array_count; k++) {
          if (grid[i].w == w_max_array[k])
            bom_count++;
        }
      }
    }
  }

  if (bom_count < h_max_array_count * w_max_array_count)
    cout << h_count_max + w_count_max << endl;
  else
    cout << h_count_max + w_count_max - 1 << endl;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll, ll>
#define endl "\\n"
#define MAXN 100005
using namespace std;

ll h, w, m, a, b;
vector<ll> v, v1;
unordered_map<ll, ll> r, c;
unordered_map<ll, ll> mm;

void solve() {
  cin >> h >> w >> m;
  ll mr = 0, mc = 0;
  while (m--) {
    cin >> a >> b;
    ll t = a * 1e9 + b;
    mm[t]++;
    r[a]++;
    c[b]++;
    mr = max(mr, r[a]);
    mc = max(mc, c[b]);
  }
  for (ll i = 1; i <= h; i++) {
    if (r[i] == mr)
      v.pb(i);
  }
  for (ll i = 1; i <= w; i++) {
    if (c[i] == mc)
      v1.pb(i);
  }
  ll ans = 0;
  if (v.size() + v1.size() > 3e5) {
    cout << mr + mc << endl;
    return;
  }
  for (ll i = 0; i < v.size(); i++) {
    for (ll j = 0; j < v1.size(); j++) {
      ll t = v[i] * 1e9 + v1[j];
      if (mm[t] == 1)
        ans = max(ans, r[v[i]] + c[v1[j]] - 1);
      else
        ans = max(ans, r[v[i]] + c[v1[j]]);
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll, ll>
#define endl "\\n"
#define MAXN 100005
using namespace std;

ll h, w, m, a, b;
vector<ll> v, v1;
unordered_map<ll, ll> r, c;
unordered_map<ll, ll> mm;

void solve() {
  cin >> h >> w >> m;
  ll mr = 0, mc = 0;
  while (m--) {
    cin >> a >> b;
    ll t = a * 1e9 + b;
    mm[t]++;
    r[a]++;
    c[b]++;
    mr = max(mr, r[a]);
    mc = max(mc, c[b]);
  }
  for (ll i = 1; i <= h; i++) {
    if (r[i] == mr)
      v.pb(i);
  }
  for (ll i = 1; i <= w; i++) {
    if (c[i] == mc)
      v1.pb(i);
  }
  ll ans = 0;
  for (ll i = 0; i < v.size(); i++) {
    for (ll j = 0; j < v1.size(); j++) {
      ll t = v[i] * 1e9 + v1[j];
      if (mm[t] == 1)
        ans = max(ans, r[v[i]] + c[v1[j]] - 1);
      else
        ans = max(ans, r[v[i]] + c[v1[j]]);
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

// E - Bomber
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> s;
  vector<pair<int, int>> r(h), c(w);
  for (int i = 0; i < h; i++)
    r[i].second = i;
  for (int i = 0; i < w; i++)
    c[i].second = i;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    s.insert({x, y});
    r[x].first++;
    c[y].first++;
  }

  sort(r.begin(), r.end(), greater<pair<int, int>>());
  sort(c.begin(), c.end(), greater<pair<int, int>>());

  int ans = 0;
  bool found = true;
  for (int i = 0; i < r.size(); i++) {
    if (i > 0 && r[0].first - r[i].first > 0)
      break;
    for (int j = 0; j < c.size(); j++) {
      if (j > 0 && c[0].first - c[j].first > 0)
        break;
      int n = r[i].first + c[j].first;
      if (s.count({r[i].second, c[j].second}))
        n--;
      else
        found = false;
      ans = max(ans, n);
      if (!found)
        break;
    }
    if (!found)
      break;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

// E - Bomber
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> s;
  vector<pair<int, int>> r(h), c(w);
  for (int i = 0; i < h; i++)
    r[i].second = i;
  for (int i = 0; i < w; i++)
    c[i].second = i;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    s.insert({x, y});
    r[x].first++;
    c[y].first++;
  }

  sort(r.begin(), r.end(), greater<pair<int, int>>());
  sort(c.begin(), c.end(), greater<pair<int, int>>());

  int ans = 0;
  for (int i = 0; i < r.size(); i++) {
    if (i > 0 && r[0].first - r[i].first > 1)
      break;
    for (int j = 0; j < c.size(); j++) {
      if (j > 0 && c[0].first - c[j].first > 1)
        break;
      int n = r[i].first + c[j].first;
      if (s.count({r[i].second, c[j].second}))
        n--;
      ans = max(ans, n);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool bad(const pair<int, int> &p1, const pair<int, int> &p2) {
  return p1.first > p2.first;
}

void solve() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> row(H, 0);
  vector<int> col(W, 0);
  set<pair<int, int>> st;
  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    row[h]++;
    col[w]++;
    st.insert({h, w});
  }
  set<pair<int, int>, greater<pair<int, int>>> st1;
  set<pair<int, int>, greater<pair<int, int>>> st2;
  for (int i = 0; i < H; ++i) {
    if (row[i] == 0)
      continue;
    st1.emplace(row[i], i);
  }
  for (int i = 0; i < W; ++i) {
    if (col[i] == 0)
      continue;
    st2.emplace(col[i], i);
  }

  int ans = 0;
  for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) {
    if (bad(*st1.begin(), *it1))
      break;
    for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) {
      if (bad(*st2.begin(), *it2))
        break;
      int temp = it1->first + it2->first;
      if (st.count({it1->second, it2->second})) {
        temp--;
      }
      if (ans > temp) {
        cout << ans << endl;
        return;
      }
      ans = max(ans, temp);
    }
  }
  cout << ans << endl;
}

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

  int t = 1;
  while (t--) {
    solve();
  }
}


Error: TLE

Fixed submission:

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

bool bad(const pair<int, int> &p1, const pair<int, int> &p2) {
  return p1.first > p2.first;
}

void solve() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> row(H, 0);
  vector<int> col(W, 0);
  set<pair<int, int>> st;
  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    row[h]++;
    col[w]++;
    st.insert({h, w});
  }
  set<pair<int, int>, greater<pair<int, int>>> st1;
  set<pair<int, int>, greater<pair<int, int>>> st2;
  for (int i = 0; i < H; ++i) {
    if (row[i] == 0)
      continue;
    st1.emplace(row[i], i);
  }
  for (int i = 0; i < W; ++i) {
    if (col[i] == 0)
      continue;
    st2.emplace(col[i], i);
  }

  int ans = 0;
  for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) {
    if (bad(*st1.begin(), *it1))
      break;
    for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) {
      if (bad(*st2.begin(), *it2))
        break;
      int temp = it1->first + it2->first;
      if (st.count({it1->second, it2->second})) {
        temp--;
      }
      ans = max(ans, temp);
    }
  }
  cout << ans << endl;
}

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

  int t = 1;
  while (t--) {
    solve();
  }
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool bad(const pair<int, int> &p1, const pair<int, int> &p2) {
  return p1.first > p2.first + 1;
}

void solve() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> row(H, 0);
  vector<int> col(W, 0);
  set<pair<int, int>> st;
  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    row[h]++;
    col[w]++;
    st.insert({h, w});
  }
  set<pair<int, int>, greater<pair<int, int>>> st1;
  set<pair<int, int>, greater<pair<int, int>>> st2;
  for (int i = 0; i < H; ++i) {
    if (row[i] == 0)
      continue;
    st1.emplace(row[i], i);
  }
  for (int i = 0; i < W; ++i) {
    if (col[i] == 0)
      continue;
    st2.emplace(col[i], i);
  }

  int ans = 0;
  for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) {
    bool there = false;
    if (bad(*st1.begin(), *it1))
      break;
    for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) {
      if (bad(*st2.begin(), *it2))
        break;
      int temp = it1->first + it2->first;
      if (st.count({it1->second, it2->second})) {
        there = true;
        temp--;
      }
      ans = max(ans, temp);
      if (!there)
        break;
    }
    if (!there)
      break;
  }
  cout << ans << endl;
}

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

  int t = 1;
  while (t--) {
    solve();
  }
}


Error: TLE

Fixed submission:

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

bool bad(const pair<int, int> &p1, const pair<int, int> &p2) {
  return p1.first > p2.first + 1;
}

void solve() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> row(H, 0);
  vector<int> col(W, 0);
  set<pair<int, int>> st;
  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    row[h]++;
    col[w]++;
    st.insert({h, w});
  }
  set<pair<int, int>, greater<pair<int, int>>> st1;
  set<pair<int, int>, greater<pair<int, int>>> st2;
  for (int i = 0; i < H; ++i) {
    if (row[i] == 0)
      continue;
    st1.emplace(row[i], i);
  }
  for (int i = 0; i < W; ++i) {
    if (col[i] == 0)
      continue;
    st2.emplace(col[i], i);
  }

  int ans = 0;
  for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) {
    if (bad(*st1.begin(), *it1))
      break;
    for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) {
      if (bad(*st2.begin(), *it2))
        break;
      int temp = it1->first + it2->first;
      if (st.count({it1->second, it2->second}))
        temp--;
      ans = max(ans, temp);
    }
  }
  cout << ans << endl;
}

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

  int t = 1;
  while (t--) {
    solve();
  }
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax(_t &a, _t b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class _t> inline bool chmin(_t &a, _t b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = 2147483647;
const int max_N = 1000000000;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int h, w, m;
int main() {
  cin >> h >> w >> m;
  set<P> v;
  vector<int> h_bomb(h, 0), w_bomb(w, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    v.insert(P(a, b));
    h_bomb[a]++;
    w_bomb[b]++;
  }
  int hmax = 0, wmax = 0;
  rep(i, h) { chmax(hmax, h_bomb[i]); }
  rep(i, w) { chmax(wmax, w_bomb[i]); }
  vector<int> hmax_list, wmax_list;
  rep(i, h) {
    if (hmax == h_bomb[i])
      hmax_list.push_back(i);
  }
  rep(i, w) {
    if (wmax == w_bomb[i])
      wmax_list.push_back(i);
  }
  int ans = hmax + wmax;
  bool bomb_is_null = false;
  for (auto i : hmax_list) {
    for (auto j : wmax_list) {
      if (v.find(P(i, j)) == v.end()) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax(_t &a, _t b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class _t> inline bool chmin(_t &a, _t b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = 2147483647;
const int max_N = 1000000000;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int h, w, m;
int main() {
  cin >> h >> w >> m;
  set<P> v;
  vector<int> h_bomb(h, 0), w_bomb(w, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    v.insert(P(a, b));
    h_bomb[a]++;
    w_bomb[b]++;
  }
  int hmax = 0, wmax = 0;
  rep(i, h) { chmax(hmax, h_bomb[i]); }
  rep(i, w) { chmax(wmax, w_bomb[i]); }
  vector<int> hmax_list, wmax_list;
  rep(i, h) {
    if (hmax == h_bomb[i])
      hmax_list.push_back(i);
  }
  rep(i, w) {
    if (wmax == w_bomb[i])
      wmax_list.push_back(i);
  }
  int ans = hmax + wmax;
  bool bomb_is_null = false;
  for (auto i : hmax_list) {
    for (auto j : wmax_list) {
      if (v.find(P(i, j)) == v.end())
        bomb_is_null = true;
    }
  }

  if (bomb_is_null) {
    cout << ans << endl;
  } else {
    cout << ans - 1 << endl;
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define I inline void

using namespace std;

using ll = long long;
using ld = long double;

const int N = 2e6 + 7;

// How interesting!

int n, m, k;

int col[N], row[N];

vector<pair<int, int>> ed;
map<pair<int, int>, int> mp;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in", "r" , stdin) ;
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    ed.push_back({u, v});
    row[u]++;
    col[v]++;
    mp[{u, v}] = 1;
  }

  std::vector<int> vecr, vecc;

  int mxr = 0, mxc = 0;

  for (int i = 1; i <= n; i++) {
    if (row[i] == mxr) {
      vecr.push_back(i);
    } else if (row[i] > mxr)
      vecr = {i}, mxr = row[i];
  }
  for (int i = 1; i <= m; i++) {
    if (col[i] == mxc) {
      vecc.push_back(i);
    } else if (col[i] > mxc)
      vecc = {i}, mxc = col[i];
  }
  int ans = 0;
  for (auto u : vecr) {
    for (auto v : vecc) {
      int k = mp[{u, v}];
      ans = max(row[u] + col[v] - k, ans);
      if (!k) {
        cout << ans;
        return 0;
      }
    }
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define I inline void

using namespace std;

using ll = long long;
using ld = long double;

const int N = 2e6 + 7;

// How interesting!

int n, m, k;

int col[N], row[N];

vector<pair<int, int>> ed;
map<pair<int, int>, int> mp;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in", "r" , stdin) ;
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    ed.push_back({u, v});
    row[u]++;
    col[v]++;
    mp[{u, v}] = 1;
  }

  std::vector<int> vecr, vecc;

  int mxr = 0, mxc = 0;

  for (int i = 1; i <= n; i++) {
    if (row[i] == mxr) {
      vecr.push_back(i);
    } else if (row[i] > mxr)
      vecr = {i}, mxr = row[i];
  }
  for (int i = 1; i <= m; i++) {
    if (col[i] == mxc) {
      vecc.push_back(i);
    } else if (col[i] > mxc)
      vecc = {i}, mxc = col[i];
  }
  int ans = 0;
  for (auto u : vecr) {
    for (auto v : vecc) {
      ans = max(row[u] + col[v] - mp[{u, v}], ans);
    }
  }

  cout << ans;

  return 0;
}
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 endl '\\n'
typedef pair<int, int> P;
typedef long long ll;
set<P> Check;
int H[300005], W[300005];
int main() {
  // cin.tie(0);
  // ios_base::sync_with_stdio(false);
  int h, w, m;
  cin >> h >> w;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    Check.insert(make_pair(x, y));
    H[x]++;
    W[y]++;
  }
  int hmax = 0, wmax = 0;
  for (int x = 1; x <= h; x++) {
    if (H[x] > hmax)
      hmax = H[x];
  }
  for (int y = 1; y <= w; y++) {
    if (W[y] > wmax)
      wmax = W[y];
  }
  // cout << "max " << hmax <<  " " << wmax <<endl;
  int hnum = 0, wnum = 0;
  vector<int> hval, wval;
  for (int x = 1; x <= h; x++) {
    if (H[x] == hmax) {
      hval.push_back(x);
      hnum++;
      // cout << x << " ";
    }
  }
  // cout <<endl;
  for (int y = 1; y <= w; y++) {
    if (W[y] == wmax) {
      wval.push_back(y);
      wnum++;
      // cout << y << " ";
    }
  }
  // cout << endl;
  // cout << "cal" << endl;
  for (int i = 0; i < hnum; i++) {
    for (int j = 0; j < wnum; j++) {
      // cout <<hval[i] << " " << wval[j] <<endl;
      if (Check.count(make_pair(hval[i], wval[j])) == 0) {
        cout << hmax + wmax;
        // cout << "hello";
        return 0;
      }
    }
  }
  cout << hmax + wmax - 1;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\\n'
typedef pair<int, int> P;
typedef long long ll;
set<P> Check;
int H[30005], W[30005];
int main() {
  // cin.tie(0);
  // ios_base::sync_with_stdio(false);
  int h, w, m;
  cin >> h >> w;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    Check.insert(make_pair(x, y));
    H[x]++;
    W[y]++;
  }
  int hmax = 0, wmax = 0;
  for (int x = 1; x <= h; x++) {
    if (H[x] > hmax)
      hmax = H[x];
  }
  for (int y = 1; y <= w; y++) {
    if (W[y] > wmax)
      wmax = W[y];
  }
  // cout << "max " << hmax <<  " " << wmax <<endl;
  int hnum = 0, wnum = 0;
  vector<int> hval, wval;
  for (int x = 1; x <= h; x++) {
    if (H[x] == hmax) {
      hval.push_back(x);
      hnum++;
      // cout << x << " ";
    }
  }
  // cout <<endl;
  for (int y = 1; y <= w; y++) {
    if (W[y] == wmax) {
      wval.push_back(y);
      wnum++;
      // cout << y << " ";
    }
  }
  // cout << endl;
  // cout << "cal" << endl;
  for (int i = 0; i < hnum; i++) {
    for (int j = 0; j < wnum; j++) {
      // cout <<hval[i] << " " << wval[j] <<endl;
      if (Check.count(make_pair(hval[i], wval[j])) == 0) {
        cout << hmax + wmax;
        // cout << "hello";
        return 0;
      }
    }
  }
  cout << hmax + wmax - 1;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // e
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> a(h), b(w);
  vector<vector<int>> aa(h);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x]++;
    b[y]++;
    aa[x].push_back(y);
  }
  set<pair<int, int>> st;
  for (int i = 0; i < w; i++)
    st.emplace(b[i], i);
  int ans = 0;
  for (int i = 0; i < h; i++) {
    set<pair<int, int>> here;
    for (auto &x : aa[i]) {
      here.emplace(b[x], x);
      st.erase(make_pair(b[x], x));
    }
    if (!st.empty())
      ans = max(ans, a[i] + st.rbegin()->first);
    if (!here.empty())
      ans = max(ans, a[i] + here.rbegin()->first - 1);
    for (auto &x : aa[i]) {
      st.emplace(b[x], x);
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // e
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> a(h), b(w);
  vector<vector<int>> g(h, vector<int>(w));
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x]++;
    b[y]++;
    g[x][y]++;
  }
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      ans = max(ans, a[i] + b[j] - g[i][j]);
    }
  cout << ans << endl;
  return 0;
}