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

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

const int SIZE = 300000;

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

  int hc[SIZE] = {}, wc[SIZE] = {};
  pii hw[SIZE] = {};
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    hc[h]++;
    wc[w]++;
    hw[i] = {h, w};
  }
  vector<pii> phc, pwc;
  REP(i, SIZE) {
    phc.push_back({hc[i], i});
    pwc.push_back({wc[i], i});
  }
  sort(ALL(phc), greater<pii>());
  sort(ALL(pwc), greater<pii>());

  int hcnt, wcnt;
  vector<int> ht, wt;
  REP(i, SIZE) {
    hcnt = phc[i].first;
    ht.push_back(phc[i].second);
    if (i == SIZE - 1)
      break;
    if (phc[i].first != phc[i + 1].first)
      break;
  }
  REP(i, SIZE) {
    wcnt = pwc[i].first;
    wt.push_back(pwc[i].second);
    if (i == SIZE - 1)
      break;
    if (pwc[i].first != pwc[i + 1].first)
      break;
  }
  sort(ALL(ht));
  sort(ALL(wt));

  int cnt = 0;
  REP(i, M) {
    int h, w;
    h = hw[i].first;
    w = hw[i].second;
    if (binary_search(ALL(ht), h) && binary_search(ALL(wt), w))
      cnt++;
  }
  ll ans = hcnt + wcnt;
  if (cnt == ht.size() * wt.size())
    ans--;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

const int SIZE = 300000;

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

  int hc[SIZE] = {}, wc[SIZE] = {};
  pii hw[SIZE] = {};
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    hc[h]++;
    wc[w]++;
    hw[i] = {h, w};
  }
  vector<pii> phc, pwc;
  REP(i, SIZE) {
    phc.push_back({hc[i], i});
    pwc.push_back({wc[i], i});
  }
  sort(ALL(phc), greater<pii>());
  sort(ALL(pwc), greater<pii>());

  int hcnt, wcnt;
  vector<int> ht, wt;
  REP(i, SIZE) {
    hcnt = phc[i].first;
    ht.push_back(phc[i].second);
    if (i == SIZE - 1)
      break;
    if (phc[i].first != phc[i + 1].first)
      break;
  }
  REP(i, SIZE) {
    wcnt = pwc[i].first;
    wt.push_back(pwc[i].second);
    if (i == SIZE - 1)
      break;
    if (pwc[i].first != pwc[i + 1].first)
      break;
  }
  sort(ALL(ht));
  sort(ALL(wt));

  int cnt = 0;
  REP(i, M) {
    int h, w;
    h = hw[i].first;
    w = hw[i].second;
    if (find(ALL(ht), h) != ht.end() && find(ALL(wt), w) != wt.end())
      cnt++;
  }
  ll ans = hcnt + wcnt;
  if (cnt == ht.size() * wt.size())
    ans--;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  int AH[300100] = {};
  int AW[300100] = {};
  int ans = 0;
  int h, w;
  set<pair<int, int>> s;
  for (int i = 0; i < M; i++) {
    cin >> h >> w;
    AH[h]++;
    AW[w]++;
    s.insert({h, w});
  }
  vector<int> hp, wp;
  int maxh = 0;
  int maxw = 0;
  for (int i = 1; i <= H; i++) {
    if (AH[i] >= maxh) {
      maxh = AH[i];
    }
  }
  for (int i = 1; i <= H; i++) {
    if (AH[i] == maxh) {
      // cout<<"h"<<i<<endl;
      hp.push_back(i);
    }
  }
  for (int i = 1; i <= W; i++) {
    if (AW[i] >= maxw) {
      maxw = AW[i];
    }
  }
  for (int i = 1; i <= W; i++) {
    // cout<<"$"<<i<<" "<<AW[i]<<endl;
    if (AW[i] == maxw) {
      // cout<<"w"<<i<<endl;
      wp.push_back(i);
    }
  }
  // cout<<"maxh"<<maxh<<"maxw"<<maxw<<endl;
  // cout<<hp.size()<<" "<<wp.size()<<endl;
  ans = maxh + maxw;

  int flag = 1;
  for (auto it = hp.begin(); it != hp.end(); it++) {
    for (auto it2 = wp.begin(); it2 != wp.end(); it2++) {
      // cout<<*it<<" "<<*it2<<endl;
      if (s.find({*it, *it2}) != s.end()) {
        continue;
      } else {
        flag = 0;
        break;
      }
    }
    if (flag == 0)
      break;
  }

  if (flag) {
    cout << ans - 1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  int AH[300100] = {};
  int AW[300100] = {};
  int ans = 0;
  int maxans = 0;
  int h, w;
  set<pair<int, int>> s;
  // vector<pair<int,int>>ve(300100);
  for (int i = 0; i < M; i++) {
    cin >> h >> w;
    AH[h]++;
    AW[w]++;
    s.insert({h, w});
  }
  for (int i = 1; i <= H; i++) {
    if (AH[i] == 0)
      continue;
    for (int j = 1; j <= W; j++) {
      ans = AH[i] + AW[j];
      if (ans <= maxans)
        continue;
      if (s.find({i, j}) != s.end())
        ans--;
      maxans = max(maxans, ans);
      // cout<<i<<" "<<j<<" "<<AH[i]<<" "<<AW[j]<<" "<<ans<<endl;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(H), w(W);
  set<P> st;
  rep(i, M) {
    int hh, ww;
    cin >> hh >> ww;
    hh--;
    ww--;
    h[hh]++;
    w[ww]++;
    st.insert({hh, ww});
  }

  int ih = 0, iw = 0;
  vector<int> maxh, maxw;
  repd(i, 1, H) {
    if (h[i] > h[ih]) {
      ih = i;
    }
  }
  // cout << ih << endl;
  rep(i, H) {
    if (h[ih] == h[i])
      maxh.push_back(i);
  }
  repd(i, 1, W) {
    if (w[i] > w[iw]) {
      iw = i;
    }
  }
  rep(i, W) {
    if (w[iw] == w[i])
      maxw.push_back(i);
  }

  int ans = w[maxw[0]] + h[maxh[0]];
  rep(i, maxh.size()) {
    rep(j, maxw.size()) {
      if (st.count({maxh[i], maxw[j]}) == 0) {
        cout << ans << endl;
        return 0;
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(H), w(W);
  set<P> st;
  rep(i, M) {
    int hh, ww;
    cin >> hh >> ww;
    hh--;
    ww--;
    h[hh]++;
    w[ww]++;
    st.insert({hh, ww});
  }

  int ih = 0, iw = 0;
  vector<int> maxh, maxw;
  repd(i, 1, H) {
    if (h[i] > h[ih]) {
      ih = i;
    }
  }
  // cout << ih << endl;
  rep(i, H) {
    if (h[ih] == h[i])
      maxh.push_back(i);
  }
  repd(i, 1, W) {
    if (w[i] > w[iw]) {
      iw = i;
    }
  }
  rep(i, W) {
    if (w[iw] == w[i])
      maxw.push_back(i);
  }

  int ans = 0;
  rep(i, maxh.size()) {
    rep(j, maxw.size()) {
      int cx = 0;
      if (st.count({maxh[i], maxw[j]}) > 0)
        cx = 1;
      // cout << maxw[j] << " " << maxh[i] << endl;
      chmax(ans, w[maxw[j]] + h[maxh[i]] - cx);
    }
  }

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

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) {
  ll n = vec.size();
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
}

void pr2d(vector<vector<ll>> vvec) {
  ll h = vvec.size();
  ll w = vvec.at(0).size();
  rep(i, h) {
    rep(j, w) { cout << vvec.at(i).at(j) << " "; }
    cout << "\\n";
  }
}

ll h, w, m;

int main() {
  cin >> h >> w >> m;
  unordered_set<ll> s;
  vector<ll> row(h, 0), col(w, 0);

  rep(i, m) {
    ll y, x;
    cin >> y >> x;
    y--, x--;
    row.at(y)++, col.at(x)++;
    s.insert(1e6 * y + x);
  }

  vector<ll> row_cand(0), col_cand(0);
  ll row_maxnum = 0, col_maxnum = 0;
  rep(i, h) { row_maxnum = max(row_maxnum, row.at(i)); }
  rep(i, w) { col_maxnum = max(col_maxnum, col.at(i)); }
  rep(i, h) {
    if (row.at(i) == row_maxnum)
      row_cand.emplace_back(i);
  }
  rep(i, w) {
    if (col.at(i) == col_maxnum)
      col_cand.emplace_back(i);
  }

  bool flag = 1;
  for (auto i : row_cand) {
    for (auto j : col_cand) {
      if (!s.count(1e6 * i + j)) {
        flag = 0;
        break;
      }
    }
    if (!flag)
      break;
  }
  cout << row_maxnum + col_maxnum - flag << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) {
  ll n = vec.size();
  rep(i, n) cout << i << " " << vec.at(i) << "\\n";
}

void pr2d(vector<vector<ll>> vvec) {
  ll h = vvec.size();
  ll w = vvec.at(0).size();
  rep(i, h) {
    rep(j, w) { cout << vvec.at(i).at(j) << " "; }
    cout << "\\n";
  }
}

ll h, w, m;

int main() {
  cin >> h >> w >> m;
  unordered_set<ll> s;
  vector<ll> row(h, 0), col(w, 0);

  rep(i, m) {
    ll y, x;
    cin >> y >> x;
    y--, x--;
    row.at(y)++, col.at(x)++;
    s.insert(1e6 * y + x);
  }

  vector<ll> row_cand(0), col_cand(0);
  ll row_maxnum = 0, col_maxnum = 0;
  rep(i, h) { row_maxnum = max(row_maxnum, row.at(i)); }
  rep(i, w) { col_maxnum = max(col_maxnum, col.at(i)); }
  rep(i, h) {
    if (row.at(i) == row_maxnum)
      row_cand.emplace_back(i);
  }
  rep(i, w) {
    if (col.at(i) == col_maxnum)
      col_cand.emplace_back(i);
  }

  bool flag = 1;
  for (auto i : row_cand) {
    for (auto j : col_cand) {
      if (!s.count(1e6 * i + j)) {
        flag = 0;
      }
    }
  }
  cout << row_maxnum + col_maxnum - flag << "\\n";
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 10000000000
#define MAX 500008

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

  set<pair<int, int>> s;

  vector<pair<int, int>> row(H, make_pair(0, 0)), col(W, make_pair(0, 0));
  for (int i = 0; i < M; i++) {
    row[h[i]].first++;
    col[w[i]].first++;
    s.insert(make_pair(h[i], w[i]));
  }
  for (int i = 0; i < H; i++) {
    row[i].second = i;
  }
  for (int j = 0; j < W; j++) {
    col[j].second = j;
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    ans = max(ans, row[h[i]].first + col[w[i]].first - 1);
  }

  sort(row.begin(), row.end());
  sort(col.begin(), col.end());
  int k = lower_bound(row.begin(), row.end(), make_pair(row[H - 1].first, 0)) -
          row.begin();
  int l = lower_bound(col.begin(), col.end(), make_pair(col[W - 1].first, 0)) -
          col.begin();
  if (((ll)H - (ll)k) * ((ll)W - (ll)l) > (ll)M) {
    ans = max(ans, row[H - 1].first + col[W - 1].first);
  } else {
    for (int i = k; i < H; i++) {
      for (int j = l; j < W; j++) {
        if (s.count(make_pair(row[i].second, col[j].second)) == 1) {
          ans = max(ans, row[i].first + col[j].first - 1);
        } else {
          ans = max(ans, row[i].first + col[j].first);
        }
      }
    }
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 10000000000
#define MAX 500008

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

  vector<vector<bool>> have(H, vector<bool>(W, false));
  vector<int> row(H, 0), col(W, 0);
  for (int i = 0; i < M; i++) {
    row[h[i]]++;
    col[w[i]]++;
    have[h[i]][w[i]] = true;
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (have[i][j]) {
        ans = max(ans, row[i] + col[j] - 1);
      } else {
        ans = max(ans, row[i] + col[j]);
      }
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

int r[300010], c[300010];

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<pair<int, int>, int> mp;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    r[x]++, c[y]++;
    mp[{x, y}] = 1;
  }

  int mx = 0, my = 0;
  vector<int> v1, v2;
  rep(i, h) mx = max(mx, r[i]);
  rep(i, h) {
    if (r[i] == mx)
      v1.push_back(i);
  }
  rep(i, w) my = max(my, c[i]);
  rep(i, w) {
    if (c[i] == my)
      v2.push_back(i);
  }

  for (auto i : v1) {
    for (auto j : v2) {
      if (!mp[{i, j}]) {
        cout << mx + my << endl;
        return 0;
      }
    }
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

  vector<vector<pair<int, int>>> vh(H), vw(W);
  set<int> sh, sw;
  vector<int> h(m), w(m);
  set<pair<int, int>> s;
  rep(i, m) {
    cin >> h[i] >> w[i];
    h[i]--, w[i]--;
    sh.insert(h[i]);
    sw.insert(w[i]);
    s.insert({h[i], w[i]});
    vh[h[i]].push_back({h[i], w[i]});
    vw[w[i]].push_back({h[i], w[i]});
  }

  vector<int> sumh(H, 0);
  for (auto eh : sh)
    sumh[eh] = vh[eh].size();
  vector<int> sumw(W, 0);
  for (auto ew : sw)
    sumw[ew] = vw[ew].size();

  int ans = 0;
  for (auto eh : sh) {
    for (auto ew : sw) {
      int tmp = sumh[eh] + sumw[ew];
      if (s.count({eh, ew})) {
        tmp--;
      }
      ans = max(ans, tmp);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int H, W, m;
int r[maxn], c[maxn];
int X[maxn], Y[maxn];
int idc[maxn], idr[maxn];
bool cmpc(int a, int b) { return c[a] > c[b]; }
bool cmpr(int a, int b) { return r[a] > r[b]; }
inline void MAX(int &x, int y) {
  if (y > x)
    x = y;
}
int work() {
  for (int i = 1; i <= W; i++)
    idc[i] = i;
  sort(idc + 1, idc + 1 + W, cmpc);
  for (int i = 1; i <= H; i++)
    idr[i] = i;
  sort(idr + 1, idr + 1 + H, cmpr);
  int tmpx = 0;
  for (int i = 1; i <= H; i++)
    if (r[idr[i]] == r[idr[1]])
      tmpx++;
    else
      break;
  int tmpy = 0;
  for (int j = 1; j <= W; j++)
    if (c[idc[j]] == c[idc[1]])
      tmpy++;
    else
      break;
  int ans = tmpx * tmpy;

  for (int i = 1; i <= m; i++) {
    int rr = r[X[i]];
    int cc = c[Y[i]];
    if (rr == r[idr[1]] && cc == c[idc[1]])
      ans--;
  }
  return r[idr[1]] + c[idc[1]] - (ans == 0);
}
int main() {
  scanf("%d%d%d", &H, &W, &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &X[i], &Y[i]);
    r[X[i]]++;
    c[Y[i]]++;
  }
  printf("%d\\n", work());
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int H, W, m;
int r[maxn], c[maxn];
set<int> node[maxn];
int idc[maxn], idr[maxn];
bool cmpc(int a, int b) { return c[a] > c[b]; }
bool cmpr(int a, int b) { return r[a] > r[b]; }
inline void MAX(int &x, int y) {
  if (y > x)
    x = y;
}
int work() {
  for (int i = 1; i <= W; i++)
    idc[i] = i;
  sort(idc + 1, idc + 1 + W, cmpc);
  for (int i = 1; i <= H; i++)
    idr[i] = i;
  sort(idr + 1, idr + 1 + H, cmpr);
  for (int i = 1; i <= H; i++)
    if (r[idr[i]] == r[idr[1]]) {
      for (int j = 1; j <= W; j++)
        if (c[idc[j]] == c[idc[1]]) {
          if (node[idr[i]].find(idc[j]) == node[idr[i]].end())
            return r[idr[i]] + c[idc[j]];
        }
    }
  return r[idr[1]] + c[idc[1]] - 1;
}
int main() {
  scanf("%d%d%d", &H, &W, &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    r[x]++;
    c[y]++;
    node[x].insert(y);
  }
  printf("%d\\n", work());
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

map<int, int> romp, colmp;
map<pii, int> mp;

vector<int> rec[N];
int ara[N], tree[4 * N];

void build(int node, int l, int r) {
  if (l == r) {
    tree[node] = ara[l];
    return;
  }
  int mid = (l + r) / 2;
  build(node << 1, l, mid);
  build(node << 1 | 1, mid + 1, r);
  tree[node] = max(tree[node << 1], tree[node << 1 | 1]);
}

void update(int node, int l, int r, int id, int val) {
  if (l > r || l > id || r < id)
    return;
  if (l == r) {
    tree[node] += val;
    return;
  }
  int mid = (l + r) / 2;
  update(node << 1, l, mid, id, val);
  update(node << 1 | 1, mid + 1, r, id, val);
  tree[node] = max(tree[node << 1], tree[node << 1 | 1]);
}

int main() {
  fastio;

  int n, m, cnt;
  cin >> n >> m >> cnt;
  while (cnt--) {
    int x, y;
    cin >> x >> y;
    rec[x].push_back(y);
    ara[y]++;
  }

  int nn = 3e5;
  build(1, 1, nn);

  int ans = 0;
  for (int i = 1; i <= nn; i++) {
    for (auto x : rec[i])
      update(1, 1, nn, x, -1);
    ans = max(ans, (int)rec[i].size() + tree[1]);
    for (auto x : rec[i])
      update(1, 1, nn, x, 1);
  }
  cout << ans << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define uu first
#define vv second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e3 + 6;

map<int, int> romp, colmp;
map<pii, int> mp;

int main() {
  fastio;

  int n, m, cnt;
  cin >> n >> m >> cnt;
  while (cnt--) {
    int x, y;
    cin >> x >> y;
    mp[{x, y}] = 1;
    romp[x]++;
    colmp[y]++;
  }
  vector<pii> vec;
  for (auto x : colmp)
    vec.push_back({x.vv, x.uu});
  sort(vec.rbegin(), vec.rend());
  vec.push_back({-1, -1});
  int ans = 0;

  for (int i = 1; i <= n; i++) {

    for (int j = 0; j < vec.size() - 1; j++) {
      int val = vec[j].uu;
      int col = vec[j].vv;
      if (mp[{i, col}])
        val--;

      if (val >= vec[j + 1].uu) {
        ans = max(ans, val + romp[i]);
      }
    }
  }
  cout << ans << '\\n';

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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\\n'
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
ll n, m, m1;
void solve() {
  cin >> n >> m >> m1;
  map<ll, vector<pair<ll, ll>>> mr, mc;
  map<pair<ll, ll>, bool> m2;
  for (ll i = 0; i < m1; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    m2[{x, y}] = true;
    mr[x].push_back({x, y});
    mc[y].push_back({x, y});
  }
  vector<ll> vr, vc;
  ll maxr = 0;
  ll maxc = 0;
  for (auto x : mr) {
    maxr = max(maxr, (ll)x.second.size());
  }
  for (auto x : mc) {
    maxc = max(maxc, (ll)x.second.size());
  }
  for (auto x : mr) {
    if ((ll)x.second.size() == maxr) {
      vr.push_back(x.first);
    }
  }
  for (auto x : mc) {
    if ((ll)x.second.size() == maxc) {
      vc.push_back(x.first);
    }
  }
  bool temp = false;
  for (ll i = 0; i < vr.size(); i++) {
    for (ll j = 0; j < vc.size(); j++) {
      if (m2[{vr[i], vc[j]}] == 0) {
        temp = true;
        break;
      }
    }
  }
  if (temp) {
    cout << maxr + maxc << endl;
  } else {
    cout << maxr + maxc - 1 << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\\n'
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
ll n, m, m1;
ll solve() {
  cin >> n >> m >> m1;
  map<ll, vector<pair<ll, ll>>> mr, mc;
  map<pair<ll, ll>, bool> m2;
  for (ll i = 0; i < m1; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    m2[{x, y}] = true;
    mr[x].push_back({x, y});
    mc[y].push_back({x, y});
  }
  vector<ll> vr, vc;
  ll maxr = 0;
  ll maxc = 0;
  for (auto x : mr) {
    maxr = max(maxr, (ll)x.second.size());
  }
  for (auto x : mc) {
    maxc = max(maxc, (ll)x.second.size());
  }
  for (auto x : mr) {
    if ((ll)x.second.size() == maxr) {
      vr.push_back(x.first);
    }
  }
  for (auto x : mc) {
    if ((ll)x.second.size() == maxc) {
      vc.push_back(x.first);
    }
  }
  bool temp = false;
  for (ll i = 0; i < vr.size(); i++) {
    for (ll j = 0; j < vc.size(); j++) {
      if (m2[{vr[i], vc[j]}] == 0) {
        temp = true;
        break;
      }
    }
  }
  if (temp) {
    cout << maxr + maxc << endl;
  } else {
    cout << maxr + maxc - 1 << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}