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

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

int main() {
  long long h, w, m;
  scanf("%lld%lld%lld", &h, &w, &m);
  long long row[h], col[w];
  map<pair<long long, long long>, long long> mp;
  for (int i = 0; i < h; ++i)
    row[i] = 0ll;
  for (int i = 0; i < w; ++i)
    col[i] = 0ll;
  for (int i = 0; i < m; ++i) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    --x;
    --y;
    mp[{x, y}]++;
    row[x]++;
    col[y]++;
  }
  vector<pair<long long, long long>> vr, vc;
  for (int i = 0; i < h; ++i)
    vr.push_back({row[i], i});
  for (int j = 0; j < w; ++j)
    vc.push_back({col[j], j});
  sort(vr.begin(), vr.end());
  sort(vc.begin(), vc.end());
  reverse(vr.begin(), vr.end());
  reverse(vc.begin(), vc.end());
  long long ans = 0;
  int counter = 0;
  for (int i = 0; i < vr.size(); ++i) {
    int ok = 0;
    for (int j = 0; j < vc.size(); ++j) {
      long long val = vr[i].first + vc[j].first;
      if (mp[{vr[i].second, vc[j].second}])
        val -= 1;
      ++counter;
      ans = max(ans, val);
      if (counter == 1e6 + 16 + 1e6)
        ok = 1;
      if (ok)
        break;
    }
    if (ok)
      break;
  }
  counter = 0;
  for (int i = 0; i < vc.size(); ++i) {
    int ok = 0;
    for (int j = 0; j < vr.size(); ++j) {
      long long val = vr[j].first + vc[i].first;
      if (mp[{vr[j].second, vc[i].second}])
        val -= 1;
      ++counter;
      ans = max(ans, val);
      if (counter == 1e6 + 16 + 1e6)
        ok = 1;
      if (ok)
        break;
    }
    if (ok)
      break;
  }

  printf("%lld\\n", ans);
}

Error: TLE

Fixed submission:

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

int main() {
  long long h, w, m;
  scanf("%lld%lld%lld", &h, &w, &m);
  long long row[h], col[w];
  map<pair<long long, long long>, long long> mp;
  for (int i = 0; i < h; ++i)
    row[i] = 0ll;
  for (int i = 0; i < w; ++i)
    col[i] = 0ll;
  for (int i = 0; i < m; ++i) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    --x;
    --y;
    mp[{x, y}] = 1;
    row[x]++;
    col[y]++;
  }
  vector<pair<long long, long long>> vr, vc;
  for (int i = 0; i < h; ++i)
    vr.push_back({row[i], i});
  for (int j = 0; j < w; ++j)
    vc.push_back({col[j], j});
  sort(vr.begin(), vr.end());
  sort(vc.begin(), vc.end());
  reverse(vr.begin(), vr.end());
  reverse(vc.begin(), vc.end());
  long long ans = 0;
  for (int i = 0; i < 10000; ++i) {
    for (int j = 0; j < 10000; ++j) {
      if (i > vr.size() || j > vc.size())
        continue;
      long long val = vr[i].first + vc[j].first;
      if (mp[{vr[i].second, vc[j].second}] == 1)
        val -= 1;
      ans = max(ans, val);
    }
  }
  printf("%lld\\n", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007
#define chmax(a, b) a = max(a, b)

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> bomb_cnt_h;
  map<int, int> bomb_cnt_w;
  set<pair<int, int>> bomb_place;
  int max_bomb_h = 0;
  int max_bomb_w = 0;

  REP(i, m) {
    int bh, bw;
    cin >> bh >> bw;
    chmax(max_bomb_h, ++bomb_cnt_h[bh]);
    chmax(max_bomb_w, ++bomb_cnt_w[bw]);
    bomb_place.insert({bh, bw});
  }
  vector<int> candidate_h;
  vector<int> candidate_w;
  for (auto tmp : bomb_cnt_h) {
    if (tmp.second == max_bomb_h)
      candidate_h.push_back(tmp.first);
  }
  for (auto tmp : bomb_cnt_w) {
    if (tmp.second == max_bomb_w)
      candidate_w.push_back(tmp.first);
  }

  for (auto tmp_h : candidate_h) {
    for (auto tmp_w : candidate_w) {
      if (bomb_place.find({tmp_h, tmp_w}) == bomb_place.end()) {
        cout << max_bomb_w + max_bomb_h << endl;
        return 0;
      }
    }
  }
  cout << max_bomb_w + max_bomb_h - 1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007
#define chmax(a, b) a = max(a, b)

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> bomb_cnt_h;
  map<int, int> bomb_cnt_w;
  set<pair<int, int>> bomb_place;
  int max_bomb_h = 0;
  int max_bomb_w = 0;

  REP(i, m) {
    int bh, bw;
    cin >> bh >> bw;
    chmax(max_bomb_h, ++bomb_cnt_h[bh]);
    chmax(max_bomb_w, ++bomb_cnt_w[bw]);
    bomb_place.insert({bh, bw});
  }
  vector<int> candidate_h;
  vector<int> candidate_w;
  for (auto tmp : bomb_cnt_h) {
    if (tmp.second == max_bomb_h)
      candidate_h.push_back(tmp.first);
  }
  for (auto tmp : bomb_cnt_w) {
    if (tmp.second == max_bomb_w)
      candidate_w.push_back(tmp.first);
  }
  int flag = 1;
  for (auto tmp_h : candidate_h) {
    for (auto tmp_w : candidate_w) {
      if (bomb_place.find({tmp_h, tmp_w}) == bomb_place.end()) {
        flag = 0;
      }
    }
  }
  cout << max_bomb_w + max_bomb_h - flag << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
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;
}

int main() {
  ll h, w, m, a, b;
  cin >> h >> w >> m;
  vector<ll> l(h, 0), r(w, 0); // 横列, 縦列
  map<P, ll> t;
  rep1(i, m) {
    cin >> a >> b;
    a--;
    b--;
    l[a]++;
    r[b]++;
    P p = make_pair(a, b);
    t[p]++;
  }
  ll max_l = *max_element(l.begin(), l.end());
  ll max_r = *max_element(r.begin(), r.end());
  vector<ll> ndx_l, ndx_r; // 横列, 縦列
  rep1(i, h) if (l[i] == max_l) ndx_l.push_back(i);
  rep1(i, w) if (r[i] == max_r) ndx_r.push_back(i);
  ll ans = max_l + max_r - 1;
  for (auto x : ndx_l) {
    for (auto y : ndx_r) {
      P p = make_pair(x, y);
      if (t[p] == 0) {
        ans = max_l + max_r;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  // printf("%.12f", ans);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
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;
}

int main() {
  ll h, w, m, a, b;
  cin >> h >> w >> m;
  vector<ll> l(h, 0), r(w, 0); // 横列, 縦列
  vector<vector<ll>> t(h, vector<ll>(w));
  rep1(i, m) {
    cin >> a >> b;
    a--;
    b--;
    l[a]++;
    r[b]++;
    t[a][b]++;
  }
  ll max_l = *max_element(l.begin(), l.end());
  ll max_r = *max_element(r.begin(), r.end());
  vector<ll> ndx_l, ndx_r; // 横列, 縦列
  rep1(i, h) if (l[i] == max_l) ndx_l.push_back(i);
  rep1(i, w) if (r[i] == max_r) ndx_r.push_back(i);
  ll ans = max_l + max_r - 1;
  for (auto x : ndx_l) {
    for (auto y : ndx_r) {
      if (t[x][y] == 0) {
        ans = max_l + max_r;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  // printf("%.12f", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll M = 1e9 + 7, N = 1e6 + 5;

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ll h, w, m;
  cin >> h >> w >> m;
  map<ll, ll> row, col;
  map<pair<ll, ll>, ll> mp;
  for (ll i = 0; i < m; i++) {
    ll u, v;
    cin >> u >> v;
    mp[{u, v}] = 1;
    row[u]++;
    col[v]++;
  }
  ll mxrow = 0, mxcol = 0;
  for (auto i : row)
    mxrow = max(mxrow, i.second);
  for (auto i : col)
    mxcol = max(mxcol, i.second);

  vector<ll> indrow, indcol;

  for (auto i : row) {
    if (i.second == mxrow)
      indrow.push_back(i.first);
  }

  for (auto i : col) {
    if (i.second == mxcol)
      indcol.push_back(i.first);
  }

  ll ans = mxrow + mxcol - 1;

  for (auto i : indrow) {
    for (auto j : indcol) {
      if (mp[{i, j}] == 0)
        cout << ans + 1, exit(0);
    }
  }

  cout << ans;
}

Error: TLE

Fixed submission:

// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll M = 1e9 + 7, N = 1e6 + 5;

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ll h, w, m;
  cin >> h >> w >> m;
  map<ll, ll> row, col;
  map<pair<ll, ll>, ll> mp;
  for (ll i = 0; i < m; i++) {
    ll u, v;
    cin >> u >> v;
    mp[{u, v}] = 1;
    row[u]++;
    col[v]++;
  }
  ll mxrow = 0, mxcol = 0;
  for (auto i : row)
    mxrow = max(mxrow, i.second);
  for (auto i : col)
    mxcol = max(mxcol, i.second);

  vector<ll> indrow, indcol;

  for (auto i : row) {
    if (i.second == mxrow)
      indrow.push_back(i.first);
  }

  ll ans = 0;

  for (auto i : indrow) {
    for (ll j = 1; j <= w; j++) {
      ll tmp = mxrow + col[j] - 1;
      if (mp[{i, j}] == 0)
        tmp++;
      // cout << i << "  " << j << " " << tmp << "\\n";
      ans = max(ans, tmp);
    }
  }
  cout << ans;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _MSC_VER
  freopen("e.in", "r", stdin);
#endif
  std::ios::sync_with_stdio(false);
  int n, m, c;
  cin >> n >> m >> c;
  vector<pair<int, int>> sx(n), sy(m);
  for (int i = 0; i < n; i++) {
    sx[i].second = i;
  }
  for (int i = 0; i < m; i++) {
    sy[i].second = i;
  }
  set<pair<int, int>> a;
  for (int i = 0; i < c; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    ++sx[x].first;
    ++sy[y].first;
    a.insert(make_pair(x, y));
  }
  sort(sx.rbegin(), sx.rend());
  sort(sy.rbegin(), sy.rend());
  int ret = 0;
  for (const auto &gx : sx) {
    for (const auto &gy : sy) {
      int d = a.count(make_pair(gx.second, gy.second));
      ret = max(ret, gx.first + gy.first - d);
      if (d == 0) {
        break;
      }
    }
  }
  cout << ret << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#define max(a, b) a > b ? a : b
using namespace std;

map<pair<long long, long long>, bool> target;

inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}

inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

const int MAXN = 1e5 * 3 + 5;
long long sum1[MAXN], sum2[MAXN], ans = -0x3f3f3f3f;

// priority <pair<> >

int main() {
  long long h = read(), w = read(), m = read();
  for (int i = 1; i <= m; i++) {
    long long x = read(), y = read();
    target[make_pair(x, y)] = true;
    sum1[x]++;
    sum2[y]++;
    // tot[x][y]++;
  }
  // for (int i=1;i<=h;i++) printf("%d\\n",sum1[i]);
  // for (int i=1;i<=w;i++) printf("%d\\n",sum2[i]);
  for (int j = 1; j <= h; j++) {
    for (int k = 1; k <= w; k++) {
      if (target[make_pair(j, k)])
        ans = max(ans, sum1[j] + sum2[k] - 1);
      else
        ans = max(ans, sum1[j] + sum2[k]);
    }
  }
  printf("%lld", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  int h, w;

  cin >> h >> w;

  ll m;
  cin >> m;

  map<ll, ll> r, c;
  map<P, bool> flag;
  ll r_max = 0, c_max = 0;
  ll ri, ci;
  vector<int> a(m), b(m);

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    flag[{a[i], b[i]}] = true;
    r[a[i]]++;
    r_max = max(r_max, r[a[i]]);
    c[b[i]]++;
    c_max = max(c_max, c[b[i]]);
  }

  set<ll> x, y;

  for (int i = 1; i <= h; i++) {
    if (r[i] == r_max) {
      x.insert(i);
    }
  }

  for (int i = 1; i <= w; i++) {
    if (c[i] == c_max) {
      y.insert(i);
    }
  }

  bool z = false;

  for (auto &&i : x) {
    for (auto &&j : y) {
      if (flag[{i, j}] == false) {
        z = true;
        break;
      }
    }
  }

  if (z) {
    cout << r_max + c_max << endl;
  } else {
    cout << r_max + c_max - 1 << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  int h, w;

  cin >> h >> w;

  ll m;
  cin >> m;

  map<ll, ll> r, c;
  map<P, bool> flag;
  ll r_max = 0, c_max = 0;
  ll ri, ci;
  vector<int> a(m), b(m);

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    flag[{a[i], b[i]}] = true;
    r[a[i]]++;
    r_max = max(r_max, r[a[i]]);
    c[b[i]]++;
    c_max = max(c_max, c[b[i]]);
  }

  set<ll> x, y;

  for (int i = 1; i <= h; i++) {
    if (r[i] == r_max) {
      x.insert(i);
    }
  }

  for (int i = 1; i <= w; i++) {
    if (c[i] == c_max) {
      y.insert(i);
    }
  }

  bool z = false;

  for (auto &&i : x) {
    for (auto &&j : y) {
      if (flag[{i, j}] == false) {
        z = true;
      }
    }
  }

  if (z) {
    cout << r_max + c_max << endl;
  } else {
    cout << r_max + c_max - 1 << endl;
  }
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

pair<ll, ll> row[300001], col[300001];

int main() {
  for (int i = 1; i < 300001; i++) {
    row[i].second = i;
    col[i].second = i;
  }
  ll h, w, m, a, b;
  set<pair<ll, ll>> o;
  cin >> h >> w >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    row[a].first++;
    col[b].first++;
    o.insert({a, b});
  }
  sort(row, row + 300001);
  reverse(row, row + 300001);
  sort(col, col + 300001);
  reverse(col, col + 300001);
  ll ans = 0, mxr = row[0].first, mxc = col[0].first, ri = 0, flg = 0;
  while (row[ri].first == mxr) {
    ll ci = 0;
    while (col[ci].first == mxc) {
      ans = max(ans, row[ri].first + col[ci].first -
                         (o.count({row[ri].second, col[ci].second}) ? 1 : 0));
      if (!o.count({row[ri].second, col[ci].second})) {
        flg = 1;
        break;
      }
      ci++;
    }
    if (flg)
      break;
    ri++;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

ll row[300001], col[300001];

int main() {
  ll h, w, m, a, b;
  set<pair<ll, ll>> o;
  cin >> h >> w >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    row[a]++;
    col[b]++;
    o.insert({a, b});
  }
  ll mxr = 0, mxc = 0, flg = 0;
  for (int i = 1; i <= h; i++) {
    mxr = max(mxr, row[i]);
  }
  for (int i = 1; i <= w; i++) {
    mxc = max(mxc, col[i]);
  }
  for (int i = 1; i <= h; i++) {
    if (row[i] != mxr)
      continue;
    for (int j = 1; j <= w; j++) {
      if (col[j] != mxc)
        continue;
      if (!o.count({i, j})) {
        flg = 1;
        break;
      }
    }
    if (flg)
      break;
  }
  cout << mxr + mxc - 1 + flg << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  map<ll, ll> row, col;
  map<pair<ll, ll>, bool> field;
  for (int i = 0; i < m; ++i) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    field[{x, y}] = true;
    row[x]++;
    col[y]++;
  }

  ll max_row = 0;
  ll max_col = 0;
  for (const auto &e : row) {
    max_row = max(max_row, e.second);
  }
  for (const auto &e : col) {
    max_col = max(max_col, e.second);
  }
  ll ans = max_row + max_col;

  vector<ll> row_kouho, col_kouho;
  for (const auto &e : row) {
    if (e.second == max_row)
      row_kouho.push_back(e.first);
  }
  for (const auto &e : col) {
    if (e.second == max_col)
      col_kouho.push_back(e.first);
  }
  for (int i = 0; i < row_kouho.size(); ++i) {
    for (int j = 0; j < col_kouho.size(); ++j) {
      if (!field[{row_kouho[i], col_kouho[j]}]) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
}

Error: 2

Fixed submission:

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

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

  vector<int> cnth(H), cntw(W);
  vector<pair<int, int>> colcount, rowcount;
  set<pair<int, int>> s;

  while (M--) {
    int a, b;
    cin >> a >> b;
    cnth[--a]++;
    cntw[--b]++;
    s.insert(make_pair(a, b));
  }

  for (int i = 0; i < H; i++) {
    colcount.push_back({cnth[i], i});
  }
  for (int i = 0; i < W; i++) {
    rowcount.push_back({cntw[i], i});
  }
  sort(cnth.begin(), cnth.end());
  sort(cntw.begin(), cntw.end());

  int max_targets = colcount[0].first + rowcount[0].first;
  int overcount = 1;

  int col = 0;
  int row = 0;
  while (col + 1 < H && colcount[col].first == colcount[col + 1].first) {
    while (row + 1 < W && rowcount[row].first == rowcount[row + 1].first) {
      if (s.find({col, row}) == s.end()) {
        return max_targets;
      }
      row++;
    }
    col++;
  }
  return max_targets - 1;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define f first
#define s second

using namespace std;
typedef long long ll;

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

  int h, w, m;
  cin >> h >> w >> m;
  vector<int> r(h, 0), c(w, 0);
  vector<pair<int, int>> ls(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    r[a]++;
    c[b]++;
    ls[i] = {a, b};
  }
  set<pair<int, int>> st(all(ls));
  int sz1 = 0, sz2 = 0;
  for (int i = 0; i < h; i++) {
    sz1 = max(sz1, r[i]);
  }
  for (int i = 0; i < w; i++) {
    sz2 = max(sz2, c[i]);
  }
  set<int> ls1, ls2;
  for (int i = 0; i < h; i++) {
    if (r[i] == sz1) {
      ls1.insert(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if (c[i] == sz2) {
      ls2.insert(i);
    }
  }
  int res = sz1 + sz2 - 1;
  ;
  for (int it1 : ls1) {
    for (int it2 : ls2) {
      if (!st.count({it1, it2})) {
        res = sz1 + sz2;
        break;
      }
    }
    if (res == sz1 + sz2) {
      break;
    }
  }
  cout << res << '\\n';

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define f first
#define s second

using namespace std;
typedef long long ll;

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

  int h, w, m;
  cin >> h >> w >> m;
  vector<int> r(w, 0), c(h, 0);
  vector<pair<int, int>> ls(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    r[a]++;
    c[b]++;
    ls[i] = {a, b};
  }
  set<pair<int, int>> st(all(ls));
  int sz1 = 0, sz2 = 0;
  for (int i = 0; i < w; i++) {
    sz1 = max(sz1, r[i]);
  }
  for (int i = 0; i < h; i++) {
    sz2 = max(sz2, c[i]);
  }
  set<int> ls1, ls2;
  for (int i = 0; i < w; i++) {
    if (r[i] == sz1) {
      ls1.insert(i);
    }
  }
  for (int i = 0; i < h; i++) {
    if (c[i] == sz2) {
      ls2.insert(i);
    }
  }
  int res = sz1 + sz2 - 1;
  ;
  for (int it1 : ls1) {
    for (int it2 : ls2) {
      if (!st.count({it1, it2})) {
        res = sz1 + sz2;
        break;
      }
    }
    if (res == sz1 + sz2) {
      break;
    }
  }
  cout << res << '\\n';

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll>;
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>

set<pair<int, int>> bomb;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  map<int, int> row, col;
  ll maxr = 0, maxc = 0;
  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    h--, w--;
    row[h]++;
    col[w]++;
    if (row[h] > maxr)
      maxr = row[h];
    if (col[w] > maxc)
      maxc = col[w];
    bomb.insert({h, w});
  }
  vll vr{}, vc{};
  for (auto r : row) {
    if (r.second == maxr)
      vr.push_back(r.first);
  }
  for (auto c : col) {
    if (c.second == maxc)
      vc.push_back(c.first);
  }
  ll ans = maxr + maxc - 1;
  for (auto r : vr) {
    for (auto c : vc) {
      bool flag = false;
      if (bomb.find({r, c}) == bomb.end()) {
        cout << ans + 1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll>;
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>

set<pair<int, int>> bomb;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<pair<int, int>> row(H), col(W);
  rep(i, H) row[i] = {i, 0};
  rep(i, W) col[i] = {i, 0};
  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    h--, w--;
    row[h].second++;
    col[w].second++;
    bomb.insert({h, w});
  }
  sort(all(row),
       [&](auto const &a, auto const &b) { return a.second > b.second; });
  sort(all(col),
       [&](auto const &a, auto const &b) { return a.second > b.second; });
  ll maxr = row[0].second, maxc = col[0].second;
  vll vr{}, vc{};
  rep(i, H) {
    if (row[i].second == maxr)
      vr.push_back(row[i].first);
  }
  rep(i, W) {
    if (col[i].second == maxc)
      vc.push_back(col[i].first);
  }
  ll ans = maxr + maxc - 1;
  for (auto r : vr) {
    for (auto c : vc) {
      bool flag = false;
      rep(i, bomb.size()) {
        if (bomb.find({r, c}) == bomb.end()) {
          cout << ans + 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << ans << endl;
}