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

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, M;
  cin >> H >> W >> M;
  vector<pair<int, int>> B(M);
  vector<int> Bomb_Count_W(W, 0);
  vector<int> Bomb_Count_H(H, 0);
  map<pair<int, int>, int> Bomb_Map;

  FOR(m, M) {
    cin >> B[m].first >> B[m].second;
    B[m].first--;
    B[m].second--;
    Bomb_Count_H[B[m].first] += 1;
    Bomb_Count_W[B[m].second] += 1;
    Bomb_Map[{B[m].first, B[m].second}]++;
  }

  int max_H_bomb = 0;
  int max_W_bomb = 0;
  vector<int> W_candidate;
  vector<int> H_candidate;

  FOR(h, H) {
    if (max_H_bomb < Bomb_Count_H[h]) {
      max_H_bomb = Bomb_Count_H[h];
    }
  }

  FOR(w, W) {
    if (max_W_bomb < Bomb_Count_W[w]) {
      max_W_bomb = Bomb_Count_W[w];
    }
  }

  int max_W_columns = 0;
  int max_H_rows = 0;

  FOR(h, H) {
    if (max_H_bomb == Bomb_Count_H[h]) {
      max_H_rows++;
      H_candidate.emplace_back(h);
    }
  }

  FOR(w, W) {
    if (max_W_bomb == Bomb_Count_W[w]) {
      max_W_columns++;
      W_candidate.emplace_back(w);
    }
  }

  if (M < max_W_columns * max_H_rows) {
    cout << max_W_bomb + max_H_bomb << endl;
    return 0;
  } else {
    for (int w : W_candidate) {
      for (int h : H_candidate) {
        if (Bomb_Map[{h, w}] == 0) {
          cout << max_W_bomb + max_H_bomb << endl;
          return 0;
        }
      }
    }

    cout << max_H_bomb + max_W_bomb - 1 << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, M;
  cin >> H >> W >> M;
  vector<pair<int, int>> B(M);
  vector<int> Bomb_Count_W(W, 0);
  vector<int> Bomb_Count_H(H, 0);
  map<pair<int, int>, int> Bomb_Map;

  FOR(m, M) {
    cin >> B[m].first >> B[m].second;
    B[m].first--;
    B[m].second--;
    Bomb_Count_H[B[m].first] += 1;
    Bomb_Count_W[B[m].second] += 1;
    Bomb_Map[{B[m].first, B[m].second}]++;
  }

  int max_H_bomb = 0;
  int max_W_bomb = 0;

  FOR(h, H) {
    if (max_H_bomb < Bomb_Count_H[h]) {
      max_H_bomb = Bomb_Count_H[h];
    }
  }

  FOR(w, W) {
    if (max_W_bomb < Bomb_Count_W[w]) {
      max_W_bomb = Bomb_Count_W[w];
    }
  }

  int max_W_columns = 0;
  int max_H_rows = 0;

  FOR(h, H) {
    if (max_H_bomb == Bomb_Count_H[h]) {
      max_H_rows++;
    }
  }

  FOR(w, W) {
    if (max_W_bomb == Bomb_Count_W[w]) {
      max_W_columns++;
    }
  }

  if (M < max_W_columns * max_H_rows) {
    cout << max_W_bomb + max_H_bomb << endl;
    return 0;
  } else {
    FOR(w, W) {
      if (Bomb_Count_W[w] != max_W_bomb) {
        continue;
      }
      FOR(h, H) {
        if (Bomb_Count_H[h] != max_H_bomb) {
          continue;
        }
        if (Bomb_Map[{h, w}] == 0) {
          cout << max_W_bomb + max_H_bomb << endl;
          return 0;
        }
      }
    }

    cout << max_H_bomb + max_W_bomb - 1 << endl;
  }

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

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

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

  map<int, int> Hcnt;
  map<int, int> Wcnt;
  set<pair<int, int>> num;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    num.insert({h, w});
    Hcnt[h]++;
    Wcnt[w]++;
  }

  // HとWの最大値をそれぞれ調べる
  int Hmax = 0;
  for (auto p : Hcnt) {
    if (p.second > Hmax)
      Hmax = p.second;
  }
  int Wmax = 0;
  for (auto p : Wcnt) {
    if (p.second > Wmax)
      Wmax = p.second;
  }

  vector<int> H_kouho;
  for (auto p : Hcnt) {
    if (p.second == Hmax)
      H_kouho.push_back(p.first);
  }
  vector<int> W_kouho;
  for (auto p : Wcnt) {
    if (p.second == Wmax)
      W_kouho.push_back(p.first);
  }

  for (int i = 0; i < H_kouho.size(); i++) {
    for (int j = 0; j < W_kouho.size(); j++) {
      if (!num.count({H_kouho[i], W_kouho[j]})) {
        cout << Hmax + Wmax << endl;
        return 0;
      }
    }
  }
  cout << Hmax + Wmax - 1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

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

  map<int, int> Hcnt;
  map<int, int> Wcnt;
  set<pair<int, int>> num;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    num.insert({h, w});
    Hcnt[h]++;
    Wcnt[w]++;
  }

  // HとWの最大値をそれぞれ調べる
  int Hmax = 0;
  for (auto p : Hcnt) {
    if (p.second > Hmax)
      Hmax = p.second;
  }
  int Wmax = 0;
  for (auto p : Wcnt) {
    if (p.second > Wmax)
      Wmax = p.second;
  }

  vector<int> H_kouho;
  for (auto p : Hcnt) {
    if (p.second == Hmax)
      H_kouho.push_back(p.first);
  }
  vector<int> W_kouho;
  for (auto p : Wcnt) {
    if (p.second == Wmax)
      W_kouho.push_back(p.first);
  }

  bool fg = 0;
  for (int i = 0; i < H_kouho.size(); i++) {
    for (int j = 0; j < W_kouho.size(); j++) {
      if (!num.count({H_kouho[i], W_kouho[j]}))
        fg = 1;
    }
  }
  if (fg)
    cout << Hmax + Wmax << endl;
  else
    cout << Hmax + Wmax - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> rows(H, 0);
  vector<int> cols(W, 0);
  // vector<vector<bool> > exist(H, vector<bool>(W, false));
  set<pair<int, int>> st;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    rows[h]++;
    cols[w]++;
    st.insert({h, w});
  }
  int max_row = *max_element(rows.begin(), rows.end());
  int max_col = *max_element(cols.begin(), cols.end());
  vector<int> hr(0);
  vector<int> hc(0);
  for (int i = 0; i < H; i++) {
    if (rows[i] == max_row)
      hr.push_back(i);
  }
  for (int i = 0; i < W; i++) {
    if (cols[i] == max_col)
      hc.push_back(i);
  }
  int ans = max_row + max_col - 1;
  for (int i = 0; i < hr.size(); i++) {
    for (int j = 0; j < hc.size(); j++) {
      if (st.find({hr[i], hc[j]}) == st.end()) {
        ans++;
        break;
      }
    }
    if (ans == max_row + max_col)
      break;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> rows(H, 0);
  vector<int> cols(W, 0);
  vector<vector<bool>> exist(H, vector<bool>(W, false));
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    rows[h]++;
    cols[w]++;
    exist[h][w] = true;
  }
  int max_row = *max_element(rows.begin(), rows.end());
  int max_col = *max_element(cols.begin(), cols.end());
  vector<int> hr(0);
  vector<int> hc(0);
  for (int i = 0; i < H; i++) {
    if (rows[i] == max_row)
      hr.push_back(i);
  }
  for (int i = 0; i < W; i++) {
    if (cols[i] == max_col)
      hc.push_back(i);
  }
  int ans = max_row + max_col - 1;
  for (int i = 0; i < hr.size(); i++) {
    for (int j = 0; j < hc.size(); j++) {
      if (exist[hr[i]][hc[j]])
        continue;
      else {
        ans++;
        break;
      }
    }
    if (ans == max_row + max_col)
      break;
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> X(W, 0), Y(H, 0);
  unordered_map<int, vector<int>> S, T;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> y >> x;
    x--;
    y--;
    X[x]++;
    Y[y]++;
    S[x].push_back(y);
    T[y].push_back(x);
  }

  int maxBombsX = 0;
  int maxBombsY = 0;
  for (int i = 0; i < W; i++)
    maxBombsX = max(maxBombsX, X[i]);
  for (int i = 0; i < H; i++)
    maxBombsY = max(maxBombsY, Y[i]);

  unordered_set<int> candX, candY;
  for (int i = 0; i < W; i++)
    if (X[i] == maxBombsX)
      candX.insert(i);
  for (int i = 0; i < H; i++)
    if (Y[i] == maxBombsY)
      candY.insert(i);

  int answer = maxBombsX + maxBombsY;
  for (int x : candX) {
    int attackY = 0;
    for (int y : S[x]) {
      if (candY.count(y))
        attackY++;
    }
    if (attackY < candY.size()) {
      cout << answer << endl;
      return 0;
    }
  }
  for (int y : candY) {
    int attackX = 0;
    for (int x : T[y]) {
      if (candX.count(x))
        attackX++;
    }
    if (attackX < candX.size()) {
      cout << answer << endl;
      return 0;
    }
  }
  cout << answer - 1 << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> X(W, 0), Y(H, 0);
  unordered_map<int, vector<int>> S;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    X[x]++;
    Y[y]++;
    S[x].push_back(y);
  }

  int maxBombsX = 0;
  int maxBombsY = 0;
  for (int i = 0; i < W; i++)
    maxBombsX = max(maxBombsX, X[i]);
  for (int i = 0; i < W; i++)
    maxBombsY = max(maxBombsY, Y[i]);

  unordered_set<int> candX, candY;
  for (int i = 0; i < W; i++)
    if (X[i] == maxBombsX)
      candX.insert(i);
  for (int i = 0; i < H; i++)
    if (Y[i] == maxBombsY)
      candY.insert(i);

  int answer = maxBombsX + maxBombsY;
  for (int x : candX) {
    int attackY = 0;
    for (int y : S[x]) {
      if (candY.count(y))
        attackY++;
    }
    if (attackY < candY.size()) {
      cout << answer << endl;
      return 0;
    }
  }
  cout << answer - 1 << endl;

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

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto &&v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int hn[300100], wn[300100];
set<int> ms[300100];
random_device _rnd;
int rnd(int n) { return ((double)_rnd() / UINT_MAX) * n; }
int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  repi(M) {
    int h, w;
    cin >> h >> w;
    --h;
    --w;
    ++hn[h];
    ++wn[w];
    ms[h].insert(w);
  }
  int hnmax = -1, wnmax = -1;
  repi(H) updatemax(hnmax, hn[i]);
  repi(W) updatemax(wnmax, wn[i]);
  vector<int> hms, wms;
  repi(H) if (hn[i] == hnmax) hms.push_back(i);
  repi(W) if (wn[i] == wnmax) wms.push_back(i);
  int result = hnmax + wnmax - 1;
  if (M < H * W) {
    ll hmsl = hms.size(), wmsl = wms.size();
    if (hmsl * wmsl <= 1e5 * 3) {
      repi(hmsl) repj(wmsl) {
        int h = hms[i], w = wms[j];
        if (ms[h].find(w) == ms[h].end()) {
          ++result;
          goto end;
        }
      }
    } else {
      repi(1e5) {
        int h = hms[rnd(hmsl)], w = wms[rnd(wmsl)];
        if (ms[h].find(w) == ms[h].end()) {
          ++result;
          goto end;
        }
      }
    }
  }
end:
  cout << result << endl;
}


Error: TLE

Fixed submission:

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto &&v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int hn[300100], wn[300100];
set<int> ms[300100];
random_device _rnd;
int rnd(int n) { return ((double)_rnd() / UINT_MAX) * n; }
int main() {
  int H, W, M;
  cin >> H >> W >> M;
  repi(M) {
    int h, w;
    cin >> h >> w;
    --h;
    --w;
    ++hn[h];
    ++wn[w];
    ms[h].insert(w);
  }
  int hnmax = -1, wnmax = -1;
  repi(H) updatemax(hnmax, hn[i]);
  repi(W) updatemax(wnmax, wn[i]);
  vector<int> hms, wms;
  repi(H) if (hn[i] == hnmax) hms.push_back(i);
  repi(W) if (wn[i] == wnmax) wms.push_back(i);
  int result = 0;
  int hmsl = hms.size(), wmsl = wms.size();
  if (hmsl * wmsl <= 1e5 * 3) {
    repi(hmsl) repj(wmsl) {
      int h = hms[i], w = wms[j];
      updatemax(result, hn[h] + wn[w] - (ms[h].find(w) != ms[h].end()));
    }
  } else {
    repi(1e4) {
      int h = hms[rnd(hmsl)], w = wms[rnd(wmsl)];
      updatemax(result, hn[h] + wn[w] - (ms[h].find(w) != ms[h].end()));
    }
  }
  cout << result << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;

int main() {
  int H, W, m;
  cin >> H >> W >> m;
  int mxh = 0, mxw = 0;
  ll MX = 300010;
  vector<int> ch(MX, 0);
  vector<int> cw(MX, 0);
  map<P, bool> mp;
  for (int i = 0; i < m; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    ch[h]++;
    cw[w]++;
    mxh = max(mxh, ch[h]);
    mxw = max(mxw, cw[w]);
    mp[{h, w}] = true;
  }
  vector<int> x;
  vector<int> y;
  for (int i = 0; i <= H; ++i) {
    if (mxh == ch[i])
      x.push_back(i);
  }
  for (int j = 0; j <= W; ++j) {
    if (mxw == cw[j])
      y.push_back(j);
  }
  ll ans = mxh + mxw;
  bool exist = false;
  ll k = x.size() * y.size(); // 交点の数
  if (k > m) {
    cout << ans << endl;
    return 0;
  }
  for (auto i : x) {
    for (auto j : y) {
      if (!mp[{i, j}])
        exist = true;
    }
  }
  if (!exist)
    ans--;
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;

int main() {
  int H, W, m;
  cin >> H >> W >> m;
  int mxh = 0, mxw = 0;
  ll MX = 300010;
  vector<int> ch(MX, 0);
  vector<int> cw(MX, 0);
  map<P, bool> mp;
  for (int i = 0; i < m; ++i) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    ch[h]++;
    cw[w]++;
    mxh = max(mxh, ch[h]);
    mxw = max(mxw, cw[w]);
    mp[{h, w}] = true;
  }
  vector<int> x;
  vector<int> y;
  for (int i = 0; i <= H; ++i) {
    if (mxh == ch[i])
      x.push_back(i);
  }
  for (int j = 0; j <= W; ++j) {
    if (mxw == cw[j])
      y.push_back(j);
  }
  ll ans = mxh + mxw;
  bool exist = false;
  for (auto i : x) {
    for (auto j : y) {
      if (!mp[{i, j}])
        exist = true;
    }
  }
  if (!exist)
    ans--;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

/*********************
 * @author: I_Love_Thuy_Linh
 *
 *********************/

#include <bits/stdc++.h>
#define all(s) (s).begin(), (s).end()
using namespace std;
int H, W, M;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> H >> W >> M;
  // vector<vector<int>> grid(H,vector<int> (W,0));
  vector<int> row(H);
  vector<int> col(W);
  map<pair<int, int>, int> grid;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    grid.insert(pair<pair<int, int>, int>({x, y}, 1));
    row[x]++;
    col[y]++;
  }

  int max_row = *max_element(all(row));
  int max_col = *max_element(all(col));

  vector<int> row_idx;
  vector<int> col_idx;

  for (int i = 0; i < H; i++)
    if (row[i] == max_row)
      row_idx.emplace_back(i);

  for (int i = 0; i < W; i++)
    if (col[i] == max_col)
      col_idx.emplace_back(i);

  for (int r : row_idx)
    for (int c : col_idx)
      if (grid.find(pair<int, int>(r, c)) == grid.end()) {
        cout << max_row + max_col;
        return 0;
      }
  cout << max_row + max_col - 1;
  return 0;
}


Error: WA

Fixed submission:

/*********************
 * @author: I_Love_Thuy_Linh
 *
 *********************/

#include <bits/stdc++.h>
using namespace std;
int H, W, M;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> H >> W >> M;
  vector<vector<int>> grid(H, vector<int>(W, 0));
  vector<int> row(H);
  vector<int> col(W);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    grid[x][y] = 1;
    row[x]++;
    col[y]++;
  }

  int ans = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      ans = max(ans, row[i] + col[j] - grid[i][j]);

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

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 300001;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  vector<int> cntx(MAX), cnty(MAX);
  map<pii, int> mp;
  int H, W, N;
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    cntx[x]++;
    cnty[y]++;
    mp[pii(x, y)]++;
  }
  int mx = *max_element(cntx.begin(), cntx.end());
  int my = *max_element(cnty.begin(), cnty.end());
  vector<int> X, Y;
  for (int i = 1; i < MAX; i++) {
    if (cntx[i] == mx)
      X.push_back(i);
    if (cnty[i] == my)
      Y.push_back(i);
  }
  for (int x : X) {
    for (int y : Y) {
      if (mp.count(pii(x, y)) == 0) {
        cout << mx + my << '\\n';
        return 0;
      }
    }
  }
  cout << mx + my - 1 << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
// const int MAX = 300001;
const int MAX = 10;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  vector<int> cntx(MAX), cnty(MAX);
  map<pii, int> mp;
  int H, W, N;
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    cntx[x]++;
    cnty[y]++;
    mp[pii(x, y)]++;
  }
  int mx = *max_element(cntx.begin(), cntx.end());
  int my = *max_element(cnty.begin(), cnty.end());
  vector<int> X, Y;
  for (int i = 1; i < MAX; i++) {
    if (cntx[i] == mx)
      X.push_back(i);
    if (cnty[i] == my)
      Y.push_back(i);
  }
  for (int x : X) {
    for (int y : Y) {
      if (mp.count(pii(x, y)) == 0) {
        cout << mx + my << '\\n';
        return 0;
      }
    }
  }
  cout << mx + my - 1 << '\\n';
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int n, m, k;
int r[300005], c[300005];
vector<pair<int, int>> v;
int pos;
vector<int> lot1, lot2;
int mx1, mx2;
signed main() {
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    r[a]++;
    c[b]++;
    v.pb(mp(a, b));
  }
  sort(all(v));
  for (int i = 0; i < max(n, m); i++) {
    if (mx1 == r[i]) {
      lot1.pb(i);
    }
    if (mx1 < r[i]) {
      lot1.resize(0);
      lot1.pb(i);
      mx1 = r[i];
    }
    if (mx2 == c[i]) {
      lot2.pb(i);
    }
    if (mx2 < c[i]) {
      lot2.resize(0);
      lot2.pb(i);
      mx2 = c[i];
    }
  }
  if (sz(lot1) * sz(lot2) > k) {
    cout << mx1 + mx2;
    re 0;
  }
  for (int i = 0; i < sz(lot1); i++) {
    for (int j = 0; j < sz(lot2); j++) {
      while (mp(lot1[i], lot2[j]) > v[pos] && pos < sz(v))
        pos++;
      if (pos == sz(v) || v[pos] != mp(lot1[i], lot2[j])) {
        cout << mx1 + mx2;
        re 0;
      }
    }
  }
  cout << mx1 + mx2 - 1;
  re 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int r[300005], c[300005];
vector<pair<int, int>> v;
signed main() {
  int n, m, k;
  cin >> n >> m >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    r[a]++;
    c[b]++;
    v.pb(mp(a, b));
  }
  sort(all(v));
  int pos = 0;
  vector<int> mmx, mxx;
  int mx1 = 0, mx2 = 0;
  for (int i = 0; i <= n; i++) {
    if (mx1 == r[i]) {
      mmx.pb(i);
    }
    if (mx1 < r[i]) {
      mmx.resize(0);
      mx1 = max(mx1, r[i]);
      mmx.pb(i);
    }
    if (mx2 == c[i]) {
      mxx.pb(i);
    }
    if (mx2 < c[i]) {
      mxx.resize(0);
      mx2 = max(mx2, c[i]);
      mxx.pb(i);
    }
    //	cout<<r[i]<<' '<<c[i]<<'\\n';
  }
  // cout<<sz(mmx)<<' '<<sz(mxx)<<'\\n';
  if (sz(mmx) * sz(mxx) > 3 * 1e5 + 7)
    cout << mx1 + mx2;
  else {
    for (int i = 0; i < sz(mmx); i++) {
      for (int j = 0; j < sz(mxx); j++) {
        while (v[pos] < mp(mmx[i], mxx[j]))
          pos++;
        //			cout<<i<<' '<<j<<' '<<pos<<'\\n';
        if (v[pos] != mp(mmx[i], mxx[j])) {
          cout << mx1 + mx2;
          re 0;
        }
      }
    }
    cout << mx1 + mx2 - 1;
  }
  re 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define linf (1ll << 60)
#define all(x) (x).begin(), (x).end()

// -------- Main Code -------- //
void runcase() {
  ll row, col, M;
  cin >> row >> col >> M;

  vector<ll> cnt_row(row, 0);
  vector<ll> cnt_col(col, 0);
  unordered_map<ll, ll> map;

  for (int i = 0; i < M; i++) {
    int r, c;
    cin >> r >> c;
    cnt_row[r - 1]++;
    cnt_col[c - 1]++;
    ll idx = col * (r - 1) + (c - 1);
    map[idx] = 1;
  }

  ll res = 0;

  ll a, b;
  a = *max_element(all(cnt_row));
  b = *max_element(all(cnt_col));

  res = a + b - 1;

  vector<ll> va, vb;
  for (int i = 0; i < row; i++)
    if (cnt_row[i] == a)
      va.emplace_back(i);
  for (int i = 0; i < col; i++)
    if (cnt_col[i] == b)
      vb.emplace_back(i);

  for (int i = 0; i < va.size(); i++)
    for (int j = 0; j < vb.size(); j++) {
      if (map[col * va[i] + vb[j]] == 0) {
        cout << res + 1 << "\\n";
        return;
      }
    }

  cout << res << "\\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // int t;
  // cin >> t;
  // while (t-- > 0)
  runcase();
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define linf (1ll << 60)
#define all(x) (x).begin(), (x).end()

// -------- Main Code -------- //
void runcase() {
  int row, col, M;
  cin >> row >> col >> M;

  vector<int> cnt_row(row, 0);
  vector<int> cnt_col(col, 0);
  unordered_map<ll, ll> map;

  for (int i = 0; i < M; i++) {
    int r, c;
    cin >> r >> c;
    cnt_row[r - 1]++;
    cnt_col[c - 1]++;
    ll idx = col * (r - 1) + (c - 1);
    map[idx] = 1;
  }

  int res = 0;
  for (int i = 0; i < row; i++) {
    for (int j = 0; j < col; j++) {
      res = max(res, cnt_row[i] + cnt_col[j] - (int)map[col * i + j]);
    }
  }

  cout << res << "\\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // int t;
  // cin >> t;
  // while (t-- > 0)
  runcase();
  return 0;
}