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

// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

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

int h, w;
int m;

int mr[300009], mc[300009];
set<pair<int, int>> grid;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  memset(mr, 0, sizeof mr);
  memset(mc, 0, sizeof mc);

  cin >> h >> w >> m;

  for (int i = 0; i < m; i++) {
    int h1, w1;
    cin >> h1 >> w1;
    mr[h1] += 1;
    mc[w1] += 1;
    grid.insert({h1, w1});
  }

  int mmr = 0;
  for (int i = 1; i <= h; i++) {
    mmr = max(mmr, mr[i]);
  }

  int mmc = 0;
  for (int i = 1; i <= w; i++) {
    mmc = max(mmc, mc[i]);
  }

  vector<int> mcv, mrv;

  for (int i = 1; i <= h; i++) {
    if (mr[i] == mmr)
      mrv.push_back(i);
  }

  for (int i = 1; i <= w; i++) {
    if (mc[i] == mmc)
      mcv.push_back(i);
  }

  int ans = mmc + mmr - 1;

  for (auto i : mrv) {
    for (auto j : mcv) {
      if (grid.find({i, j}) == grid.end()) {
        ans++;
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

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

int h, w;
int m;

int mr[300009];
int mc[300009];

// unordered_set<pair<int, int> > grid;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  cin >> h >> w >> m;

  memset(mr, 0, sizeof mr);
  memset(mr, 0, sizeof mc);

  vector<vector<int>> grid(h + 1, vector<int>(w + 1, 0));

  for (int i = 0; i < m; i++) {
    int h1, w1;
    cin >> h1 >> w1;
    mr[h1] += 1;
    mc[w1] += 1;
    grid[h1][w1] = 1;
    // grid.insert({h1, w1});
  }

  int ans = 0;

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      // int val = g;
      // if(grid.find({i, j}) != grid.end()) val += 1;
      ans = max(ans, mr[i] + mc[j] - grid[i][j]);
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl "\\n"
#define mod 1000000007
#define inf 1e12
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

  IOS;

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

  vector<int> row(h, 0), col(w, 0);
  set<pair<int, int>> target;
  int r, c;

  for (int i = 0; i < m; i++) {
    cin >> r >> c;
    r--, c--;

    row[r]++;
    col[c]++;
    target.insert({r, c});
  }

  int maxRow = 0, maxCol = 0;

  for (int x : row)
    maxRow = max(maxRow, x);

  for (int x : col)
    maxCol = max(maxCol, x);

  vector<int> rowCandidate, colCandidate;

  for (int i = 0; i < h; i++)
    if (row[i] == maxRow)
      rowCandidate.push_back(i);

  for (int j = 0; j < w; j++)
    if (col[j] == maxCol)
      colCandidate.push_back(j);

  int ans = maxRow + maxCol - 1;

  for (int r : rowCandidate) {
    for (int c : colCandidate) {
      if (target.find({r, c}) == target.end()) {
        ans++;
        break;
      }
    }
    if (ans == maxRow + maxCol)
      break;
  }

  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

// #define int 		long long
#define endl "\\n"
#define mod 1000000007
#define inf 1e12
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

  IOS;

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

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

  int r, c;

  for (int i = 0; i < m; i++) {
    cin >> r >> c;
    r--, c--;

    v[r][c] = 1;
    row[r]++;
    col[c]++;
  }

  long long int ans = 0;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, (row[i] + col[j] - v[i][j]) * 1ll);
    }
  }

  cout << ans;

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



#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
const double EPS = 1e-9;
const double PI = acos(-1);
const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2},  {1, 2},
                             {2, -1},  {2, 1},  {-1, -2}, {1, -2}};
// const int dx[]={0,0,0,1,1,1,-1,-1,-1};
// const int dy[]={-1,0,1,-1,0,1,-1,0,1};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
// #define MOD         1000000007LL
#define MAX 300005
const ll MOD = 1000000000 + 7;
map<pair<int, int>, int> mp;
int main() {
  FAST int t;
  t = 1;

  while (t--) {
    int h, w, n;
    cin >> h >> w >> n;

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

    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      mp[make_pair(a, b)] = 1;
      row[a]++, col[b]++;
    }
    int mr = 0, mc = 0;

    for (int x : row)
      mr = max(mr, x);
    for (int x : col)
      mc = max(mc, x);

    int mx = mr + mc;

    vector<int> ih, iw;
    for (int i = 0; i < h; i++)
      if (row[i] == mr)
        ih.push_back(i);
    for (int i = 0; i < w; i++)
      if (col[i] == mc)
        iw.push_back(i);

    for (int x : ih) {
      for (int y : iw) {
        if (mp[{x, y}])
          continue;
        else {
          cout << mx << endl;
          return 0;
        }
      }
    }

    cout << mx - 1 << endl;
  }
}


Error: TLE

Fixed submission:



#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
const double EPS = 1e-9;
const double PI = acos(-1);
const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2},  {1, 2},
                             {2, -1},  {2, 1},  {-1, -2}, {1, -2}};
// const int dx[]={0,0,0,1,1,1,-1,-1,-1};
// const int dy[]={-1,0,1,-1,0,1,-1,0,1};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
// #define MOD         1000000007LL
#define MAX 300005
const ll MOD = 1000000000 + 7;
map<pair<int, int>, int> mp;
int main() {
  FAST int t;
  t = 1;

  while (t--) {
    int h, w, n;
    cin >> h >> w >> n;

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

    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      mp[make_pair(a, b)] = 1;
      row[a]++, col[b]++;
    }

    int mx = 0;

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (mp[make_pair(i, j)]) {
          mx = max(mx, row[i] + col[j] - 1);
        } else
          mx = max(mx, row[i] + col[j]);
      }
    }

    cout << mx << endl;
  }
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

  unordered_map<int, int> rowCnt;
  unordered_map<int, int> colCnt;
  unordered_map<long long, int> cell;
  vector<int> rv;
  vector<int> cv;
  vector<int> mrv;
  vector<int> mcv;

  int maxRow = 0;
  int maxCol = 0;
  const long long OFFSET = 10000000LL;

  for (int i = 0; i < M; ++i) {
    int r;
    int c;
    cin >> r >> c;
    maxRow = max(maxRow, ++rowCnt[r]);
    maxCol = max(maxCol, ++colCnt[c]);
    rv.push_back(r);
    cv.push_back(c);
    cell[r * OFFSET + c] = 1;
  }

  int ans = 0;
  sort(rv.begin(), rv.end());
  sort(cv.begin(), cv.end());

  for (int ri = 0; ri < rv.size(); ++ri) {
    if (ri && rv[ri] == rv[ri - 1]) {
      continue;
    }
    if (rowCnt[rv[ri]] == maxRow) {
      mrv.push_back(rv[ri]);
    }
  }

  for (int ci = 0; ci < cv.size(); ++ci) {
    if (ci && cv[ci] == cv[ci - 1]) {
      continue;
    }
    if (colCnt[cv[ci]] == maxCol) {
      mcv.push_back(cv[ci]);
    }
  }

  long long comb = (long long)mrv.size() * mcv.size();

  if (comb > M) {
    // pigeon hole
    ans = maxRow + maxCol;
  } else {
    for (int ri = 0; ri < mrv.size(); ++ri) {
      for (int ci = 0; ci < mcv.size(); ++ci) {
        int r = mrv[ri];
        int c = mcv[ci];

        int sum = rowCnt[r] + colCnt[c] - cell[r * OFFSET + c];
        ans = max(ans, sum);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

  unordered_map<int, int> rowCnt;
  unordered_map<int, int> colCnt;
  unordered_map<long long, int> cell;
  vector<int> rv;
  vector<int> cv;

  int maxRow = 0;
  int maxCol = 0;
  const long long OFFSET = 10000000LL;

  for (int i = 0; i < M; ++i) {
    int r;
    int c;
    cin >> r >> c;
    ++rowCnt[r];
    ++colCnt[c];
    rv.push_back(r);
    cv.push_back(c);
    cell[r * OFFSET + c] = 1;
  }

  int ans = 0;
  sort(rv.begin(), rv.end());
  sort(cv.begin(), cv.end());

  for (int ri = 0; ri < rv.size(); ++ri) {
    if (ri && rv[ri] == rv[ri - 1]) {
      continue;
    }
    for (int ci = 0; ci < cv.size(); ++ci) {
      if (ci && cv[ci] == cv[ci - 1]) {
        continue;
      }

      int r = rv[ri];
      int c = cv[ci];

      int sum = rowCnt[r] + colCnt[c] - cell[r * OFFSET + c];
      ans = max(ans, sum);
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
int h, w, m;
int main(void) {
  cin >> h >> w >> m;
  vector<pair<int, int>> vx, vy;
  for (int i = 0; i < h; ++i)
    vx.push_back(make_pair(0, i));
  for (int i = 0; i < w; ++i)
    vy.push_back(make_pair(0, i));
  set<pair<int, int>> se;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    vx[a].first++;
    vy[b].first++;
    se.insert(make_pair(a, b));
  }
  sort(vx.begin(), vx.end(),
       [](const pair<int, int> a, const pair<int, int> b) {
         return a.first > b.first;
       });
  sort(vy.begin(), vy.end(),
       [](const pair<int, int> a, const pair<int, int> b) {
         return a.first > b.first;
       });
  int ans = 0;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      int c = se.count(make_pair(vx[i].second, vy[j].second));
      ans = max(ans, vx[i].first + vy[j].first - c);
      if (c == 0)
        break;
    }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
int h, w, m;
int main(void) {
  cin >> h >> w >> m;
  unordered_map<int, vector<int>> ma;
  unordered_map<int, int> colsum;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    ma[a].push_back(b);
    colsum[b]++;
  }
  int ans = 0;
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    int tmpmax = 0;
    for (auto x : it->second)
      colsum[x]--;
    for (auto it = colsum.begin(); it != colsum.end(); ++it)
      tmpmax = max(tmpmax, it->second);
    for (auto x : it->second)
      colsum[x]++;
    ans = max(ans, (int)it->second.size() + tmpmax);
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

  ll h, w, m, ans = 0;
  cin >> h >> w >> m;
  vector<ll> r(h, 0), c(w, 0);
  map<ll, set<ll>> mp_c;
  vector<pair<ll, ll>> v(m);
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    r[x]++;
    c[y]++;
    v[i] = {x, y};
    mp_c[y].insert(x);
  }
  map<ll, vector<ll>> mp;
  for (ll i = 0; i < h; i++)
    mp[r[i]].push_back(i);
  vector<ll> mx = mp.rbegin()->second;
  ll total = mp.rbegin()->first;
  for (ll j = 0; j < w; j++) {
    if (mp_c[j].size() == 0)
      ans = max(ans, total);
    else if (mp_c[j].size() == h)
      ans = max(ans, total + h - 1);
    else if (mx.size() == 0)
      ans = max(ans, (ll)mp_c[j].size());
    else {
      ll flag = 0;
      for (ll num : mx) {
        if (mp_c[j].find(num) == mp_c[j].end()) {
          ans = max(ans, (ll)mp_c[j].size() + total);
          flag = 1;
          break;
        }
      }
      if (!flag)
        ans = max(ans, total + (ll)mp_c[j].size() - 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

  ll h, w, m, ans = 0;
  cin >> h >> w >> m;
  vector<ll> r(h, 0), c(w, 0);
  set<pair<ll, ll>> s;
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    s.insert({x, y});
  }
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (s.find({i, j}) != s.end()) {
        r[i]++;
        c[j]++;
      }
    }
  }
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (s.find({i, j}) != s.end()) {
        ans = max(ans, r[i] + c[j] - 1);
      } else {
        ans = max(ans, r[i] + c[j]);
      }
    }
  }
  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);
  long long n, m;
  cin >> n >> m;
  long long pos;
  cin >> pos;
  long long r[n + 5];
  long long c[m + 5];
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < pos; i++) {
    long long x, y;
    cin >> x >> y;
    r[x]++;
    c[y]++;
    mp[{x, y}]++;
  }
  int ans = 0;
  priority_queue<pair<int, int>> pq, pq1;
  for (int i = 1; i <= n; i++) {
    pq.push({r[i], i});
  }
  for (int i = 1; i <= m; i++) {
    pq1.push({c[i], i});
  }
  while (pq.size() && pq1.size()) {
    pair<int, int> p = pq.top();
    pq.pop();
    pair<int, int> p1 = pq1.top();
    pq1.pop();
    /*cout<<p.first<<" "<<p.second<<'\\n';
    cout<<p1.first<<" "<<p1.second<<'\\n';*/
    int curr_ans = p.first + p1.first;
    if (mp.find({p.second, p1.second}) != mp.end())
      curr_ans--;
    if (curr_ans >= ans)
      ans = curr_ans;
    else
      break;
    if (p.first > p1.first)
      pq.push(p);
    else
      pq1.push(p1);
  }
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long pos;
  cin >> pos;
  long long r[n + 5];
  long long c[m + 5];
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < pos; i++) {
    long long x, y;
    cin >> x >> y;
    r[x]++;
    c[y]++;
    mp[{x, y}]++;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int curr_ans = 0;
    for (int j = 1; j <= m; j++) {
      curr_ans = r[i] + j[c];
      if (mp.find({i, j}) != mp.end())
        curr_ans--;
      ans = max(ans, curr_ans);
    }
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define ep emplace_back
#define mp make_pair
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define endl '\\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main() {
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int h, w, m;
  cin >> h >> w >> m;
  vi cnt_x(w + 1), cnt_y(h + 1);
  set<pi> bom;

  rep(i, m) {
    int x, y;
    cin >> y >> x;
    bom.em(x, y);
    ++cnt_x[x], ++cnt_y[y];
  }

  int mx = *max_element(all(cnt_x));
  int my = *max_element(all(cnt_y));

  vi max_x, max_y;

  rep(i, w + 1) if (cnt_x[i] == mx) max_x.ep(i);
  rep(i, h + 1) if (cnt_y[i] == my) max_y.ep(i);

  for (auto x : max_x)
    for (auto y : max_y) {
      int score = mx + my;

      if (!bom.count(mp(x, y))) {
        cout << mx + my << endl;
        return (0);
      }
    }

  cout << mx + my - 1 << endl;

  return (0);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define ep emplace_back
#define mp make_pair
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define endl '\\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main() {
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int h, w, m;
  cin >> h >> w >> m;
  vi cnt_x(w + 1), cnt_y(h + 1);
  set<pi> bom;

  rep(i, m) {
    int x, y;
    cin >> y >> x;
    bom.em(x, y);
    ++cnt_x[x], ++cnt_y[y];
  }

  int mx = *max_element(all(cnt_x));
  int my = *max_element(all(cnt_y));

  vi max_x, max_y;

  rep(i, w + 1) if (cnt_x[i] == mx) max_x.ep(i);
  rep(i, h + 1) if (cnt_y[i] == my) max_y.ep(i);

  int ans = 0;
  for (auto x : max_x)
    for (auto y : max_y) {
      int score = mx + my;

      if (bom.count(mp(x, y)))
        --score;
      chmax(ans, score);
    }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0, m = 0, bombs = 0;
  cin >> n >> m >> bombs;
  vector<ll> row(n, 0);
  vector<ll> col(m, 0);
  set<pair<ll, ll>> s;
  for (ll i = 0; i < bombs; ++i) {
    ll r = 0, c = 0;
    cin >> r >> c;
    --r, --c;
    s.insert({r, c});
    ++row[r], ++col[c];
  }
  ll rmax = *max_element(row.begin(), row.end());
  ll cmax = *max_element(col.begin(), col.end());
  vector<ll> row_ind, col_ind;
  for (ll i = 0; i < n; ++i) {
    if (row[i] == rmax)
      row_ind.pb(i);
  }
  for (ll i = 0; i < m; ++i) {
    if (col[i] == cmax)
      col_ind.pb(i);
  }
  if (row_ind.size() * col_ind.size() > bombs) {
    cout << rmax + cmax;
    return 0;
  }
  ll destroyed = 0;
  for (auto i : row_ind) {
    for (auto j : col_ind) {
      if (s.count({i, j}))
        destroyed = max(destroyed, row[i] + col[j] - 1);
      else
        destroyed = max(destroyed, row[i] + col[j]);
    }
  }
  cout << destroyed;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0, m = 0, bombs = 0;
  cin >> n >> m >> bombs;
  vector<ll> row(n, 0);
  vector<ll> col(m, 0);
  set<pair<ll, ll>> s;
  for (ll i = 0; i < bombs; ++i) {
    ll r = 0, c = 0;
    cin >> r >> c;
    --r, --c;
    s.insert({r, c});
    ++row[r], ++col[c];
  }
  ll rmax = *max_element(row.begin(), row.end());
  ll cmax = *max_element(col.begin(), col.end());
  vector<ll> row_ind, col_ind;
  for (ll i = 0; i < n; ++i) {
    if (row[i] == rmax)
      row_ind.pb(i);
  }
  for (ll i = 0; i < m; ++i) {
    if (col[i] == cmax)
      col_ind.pb(i);
  }
  ll destroyed = 0;
  for (auto i : row_ind) {
    for (auto j : col_ind) {
      if (s.count({i, j}))
        destroyed = max(destroyed, row[i] + col[j] - 1);
      else
        destroyed = max(destroyed, row[i] + col[j]);
    }
  }
  cout << destroyed;
}