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

#ifndef ONLINE_JUDGE
#include "Debug.h"
#else
#define debug(...) 42
#endif
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  map<pair<int, int>, int> maps;
  f(i, 1, m + 1) {
    int x, y;
    cin >> x >> y;
    maps[{x, y}] = 1;
  }
  vector<int> row(h + 1, 0), col(w + 1, 0);
  for (auto s : maps) {
    row[s.first.first]++;
    col[s.first.second]++;
  }
  vector<int> x, y;
  int ans = 0;
  for (auto s : maps) {
    x.push_back(s.first.first);
    y.push_back(s.first.second);
  }
  int a = x.size();
  int b = y.size();
  int ind_x, ind_y;
  int ma_x = 0, ma_y = 0;
  f(i, 1, h + 1) {
    if (row[i] > ma_x) {
      ma_x = row[i];
      ind_x = i;
    }
  }
  f(i, 1, w + 1) { ans = max(ans, col[i] + ma_x - maps[{ind_x, i}]); }
  f(i, 1, w + 1) {
    if (col[i] > ma_y) {
      ma_y = col[i];
      ind_y = i;
    }
  }
  f(i, 1, h + 1) { ans = max(ans, row[i] + ma_y - maps[{i, ind_y}]); }
  cout << ans << "\\n";

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  map<pair<int, int>, int> maps;
  f(i, 1, m + 1) {
    int x, y;
    cin >> x >> y;
    maps[{x, y}] = 1;
  }
  vector<int> row(h + 1, 0), col(w + 1, 0);
  for (auto s : maps) {
    row[s.first.first]++;
    col[s.first.second]++;
  }
  vector<int> x, y;
  int ans = 0;
  for (auto s : maps) {
    x.push_back(s.first.first);
    y.push_back(s.first.second);
    ans = max(ans, row[s.first.first] + col[s.first.second] - 1);
  }
  int a = x.size();
  int b = y.size();
  int c = a * b;
  assert(c <= 1e8);
  for (auto X : x) {
    for (auto Y : y) {
      ans = max(ans, row[X] + col[Y] - maps[{X, Y}]);
    }
  }
  cout << ans;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <memory.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;
int hang[maxn], lie[maxn];

int main() {
  int h, w, m;
  scanf("%d%d%d", &h, &w, &m);
  int mxh = 0, mxl = 0;
  map<pair<int, int>, int> mp;
  vector<int> a, b;
  while (m--) {
    int hi, wi;
    scanf("%d%d", &hi, &wi);
    hang[hi]++;
    lie[wi]++;
    mxh = max(mxh, hang[hi]);
    mxl = max(mxl, lie[wi]);
    mp[make_pair(hi, wi)] = 1;
  }
  for (int i = 1; i <= h; i++)
    if (hang[i] == mxh)
      a.push_back(i);
  for (int i = 1; i <= w; i++)
    if (lie[i] == mxl)
      b.push_back(i);
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      if (mp[make_pair(a[i], b[j])] == 0) {
        printf("%d", hang[a[i]] + lie[b[j]]);
        exit(0);
      }
    }
  }
  printf("%d", mxh + mxl - 1);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <memory.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;
int hang[maxn], lie[maxn];

int main() {
  int h, w, m;
  scanf("%d%d%d", &h, &w, &m);
  int mxh = 0, mxl = 0;
  map<pair<int, int>, int> mp;
  vector<int> a, b;
  while (m--) {
    int hi, wi;
    scanf("%d%d", &hi, &wi);
    hang[hi]++;
    lie[wi]++;
    mxh = max(mxh, hang[hi]);
    mxl = max(mxl, lie[wi]);
    mp[make_pair(hi, wi)] = 1;
  }
  int ans = 0;
  for (int i = 1; i <= h; i++)
    if (hang[i] == mxh)
      a.push_back(i);
  for (int i = 1; i <= w; i++)
    if (lie[i] == mxl)
      b.push_back(i);
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      if (mp[make_pair(a[i], b[j])])
        ans = max(ans, hang[a[i]] + lie[b[j]] - 1);
      else
        ans = max(ans, hang[a[i]] + lie[b[j]]);
    }
  }
  printf("%d", ans);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int h_max = 0;
  int w_max = 0;
  vector<pair<int, int>> target;

  vector<int> mh(h + 10);
  vector<int> mw(w + 10);
  rp(i, 0, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    target.emplace_back(x, y);
    mh[x]++;
    mw[y]++;
    chmax(h_max, mh[x]);
    chmax(w_max, mw[y]);
  }
  ll res_x = 0ll;
  ll res_y = 0ll;
  rp(i, 0, h) {
    if (mh[i] == h_max)
      res_x++;
  }
  rp(i, 0, w) {
    if (mw[i] == w_max)
      res_y++;
  }
  ll d = 0ll;
  for (auto x : target) {
    if (mh[x.first] == h_max && mw[x.second] == w_max)
      d++;
  }

  if (res_x * res_y > d)
    cout << h_max + w_max << endl;
  else
    cout << h_max + w_max - 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int h_max = 0;
  int w_max = 0;
  vector<vector<int>> target(h + 10, vector<int>(w + 10));
  vector<int> mh(h + 10);
  vector<int> mw(w + 10);
  rp(i, 0, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    target[x][y]++;
    mh[x]++;
    mw[y]++;
    chmax(h_max, mh[x]);
    chmax(w_max, mw[y]);
  }
  vector<int> res_x, res_y;
  rp(i, 0, h) {
    if (mh[i] == h_max)
      res_x.emplace_back(mh[i]);
  }
  rp(i, 0, w) {
    if (mw[i] == w_max)
      res_y.emplace_back(mw[i]);
  }
  for (auto x : res_x) {
    for (auto y : res_y) {
      if (target[x][y] == 0) {
        cout << h_max + w_max << endl;
        return 0;
      }
    }
  }
  cout << h_max + w_max - 1 << endl;
  return 0;
}
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>;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> bh(h);
  vector<int> bw(w);

  set<P> b;

  rep(k, m) {
    int i, j;
    cin >> i >> j;
    --i, --j;
    ++bh[i], ++bw[j];
    b.emplace(i, j);
  }

  int max_w = 0;
  int max_h = 0;

  rep(i, h) max_h = max(max_h, bh[i]);
  rep(i, w) max_w = max(max_w, bw[i]);

  vector<int> mh;
  vector<int> mw;

  rep(i, h) {
    if (max_h == bh[i])
      mh.emplace_back(i);
  }
  rep(i, w) {
    if (max_w == bw[i])
      mw.emplace_back(i);
  }

  int ans = max_w + max_h;

  rep(i, mh.size()) {
    P mp;
    mp.first = mh[i];

    rep(j, mw.size()) {
      mp.second = mw[j];

      if (b.count(mp))
        continue;
      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>;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> bh(h);
  vector<int> bw(w);

  vector<P> b;

  rep(k, m) {
    int i, j;
    cin >> i >> j;
    --i, --j;
    ++bh[i], ++bw[j];
    b.emplace_back(i, j);
  }

  int max_w = 0;
  int max_h = 0;

  rep(i, h) max_h = max(max_h, bh[i]);
  rep(i, w) max_w = max(max_w, bw[i]);

  vector<int> mh;
  vector<int> mw;

  rep(i, h) {
    if (max_h == bh[i])
      mh.emplace_back(i);
  }
  rep(i, w) {
    if (max_w == bw[i])
      mw.emplace_back(i);
  }

  int ans = max_w + max_h;

  rep(i, mh.size()) {
    P mp;
    mp.first = mh[i];

    rep(j, mw.size()) {
      mp.second = mw[j];

      if (find(b.begin(), b.end(), mp) != b.end())
        continue;
      cout << ans << endl;
      return 0;
    }
  }

  cout << ans - 1 << endl;

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

#include <bits/stdc++.h>

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

#define int long long
signed main() {
  // int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> rcnt(h, 0);
  vector<int> ccnt(w, 0);
  map<int, int> fld;
  for (int i = 0; i < m; i++) {
    int th, tw;
    cin >> th >> tw;
    th--;
    tw--;
    fld[th * w + tw]++;
    rcnt[th]++;
    ccnt[tw]++;
  }

  vector<pair<int, int>> rst(h);
  vector<pair<int, int>> cst(w);
  for (int i = 0; i < h; i++)
    rst[i] = make_pair(rcnt[i], i);
  for (int i = 0; i < w; i++)
    cst[i] = make_pair(ccnt[i], i);
  sort(rst.rbegin(), rst.rend());
  sort(cst.rbegin(), cst.rend());
  int r = 0;
  while (rst[r].first == rst[0].first) {
    int c = 0;
    while (cst[c].first == cst[0].first) {
      int tr = rst[r].second;
      int tc = cst[c].second;
      if (fld.count(tr * w + tc) == 0) {
        cout << rst[0].first + cst[0].first << "\\n";
        return 0;
      }
      c++;
    }
    r++;
  }
  int ans = rst[0].first + cst[0].first - 1;
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

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

// #define int long long
// signed main(){
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> rcnt(h, 0);
  vector<int> ccnt(w, 0);
  vector<bool> fld(h * w, false);
  for (int i = 0; i < m; i++) {
    int th, tw;
    cin >> th >> tw;
    th--;
    tw--;
    fld[th * w + tw] = true;
    rcnt[th]++;
    ccnt[tw]++;
  }

  vector<pair<int, int>> rst(h);
  vector<pair<int, int>> cst(w);
  for (int i = 0; i < h; i++)
    rst[i] = make_pair(rcnt[i], i);
  for (int i = 0; i < w; i++)
    cst[i] = make_pair(ccnt[i], i);
  sort(rst.rbegin(), rst.rend());
  sort(cst.rbegin(), cst.rend());
  int r = 0;
  int c = 0;
  while (rst[r].first == rst[0].first) {
    while (cst[c].first == cst[0].first) {
      int tr = rst[r].second;
      int tc = cst[c].second;
      if (!fld[tr * w + tc]) {
        cout << rst[0].first + cst[0].first << "\\n";
        return 0;
      }
      c++;
    }
    r++;
  }
  cout << rst[0].first + cst[0].first - 1 << "\\n";
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// #define int long long

int N, M, T;

int main() {
  cin >> N >> M >> T;
  unordered_map<int, int> row, col;
  set<pair<int, int>> loc;
  int rmax = 0, cmax = 0;
  while (T--) {
    int A, B;
    cin >> A >> B;
    A -= 1;
    B -= 1;
    row[A] += 1;
    col[B] += 1;
    loc.insert({A, B});
    if (row[A] > rmax)
      rmax = row[A];
    if (col[B] > cmax)
      cmax = col[B];
  }
  int fr = 0, fc = 0;
  for (auto x : row)
    fr += (x.second == rmax);
  for (auto y : col)
    fc += (y.second == cmax);

  // cout << rmax << " " << cmax;
  // cout  << "\\n\\n";
  // for (auto r : row) cout << r.first << " " << r.second << "\\n";
  // cout << "\\n\\n";
  // for (auto r : col) cout << r.first << " " << r.second << "\\n";
  // cout << "\\n\\n";

  int ct = 0;
  for (auto l : loc) {
    if (row[l.first] == rmax && col[l.second] == cmax) {
      ct += 1;
    }
  }
  // cout << ct << "\\n";

  cout << rmax + cmax - (ct == fr * fc) << "\\n";
}


Error: TLE

Fixed submission:

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

// #define int long long

int N, M, T;

int main() {
  cin >> N >> M >> T;
  map<int, int> row, col;
  set<pair<int, int>> grid;

  while (T--) {
    int A, B;
    cin >> A >> B;
    row[A - 1] += 1;
    col[B - 1] += 1;
    grid.insert({A - 1, B - 1});
  }

  vector<pair<int, int>> scol;
  for (auto c : col) {
    scol.push_back({c.second, c.first});
  }
  sort(scol.begin(), scol.end());
  reverse(scol.begin(), scol.end());

  int res = 0;
  for (auto r : row) {
    int ix = r.first, val = r.second;
    for (int i = 0; i < scol.size(); i++) {
      int curr = val;
      curr += scol[i].first - (grid.find({ix, scol[i].second}) != grid.end());
      if (res - curr >= 1)
        break;
      res = max(res, curr);
    }
  }
  cout << res << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
const int INF = 1e9 + 100;

const int S = 4e5;
int rcnt[S] = {0};
int ccnt[S] = {0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  set<pair<int, int>> m;
  int h, w, n;
  cin >> h >> w >> n;
  int mxr = 0, mxc = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    rcnt[y]++;
    ccnt[x]++;
    mxr = max(rcnt[y], mxr);
    mxc = max(ccnt[x], mxc);
    m.emplace(x, y);
  }
  vector<int> mxRows, mxCols;
  for (int i = 0; i < S; i++) {
    if (rcnt[i] == mxr) {
      mxRows.push_back(i);
    }
    if (ccnt[i] == mxc) {
      mxCols.push_back(i);
    }
  }
  for (auto &it : mxRows) {
    for (auto &itt : mxCols) {
      if (m.count({itt, it}) == 0) {
        cout << mxr + mxc << '\\n';
        return 0;
      }
    }
  }
  cout << mxr + mxc - 1 << '\\n';

  return 0;
}

// bool f = 1;
// for (auto &itt: it.second){
// 	if (p.count(itt) == 0){
// 		cout<<rmax+cmax<<'\\n';
// 		return 0;
// 	}
// }


Error: TLE

Fixed submission:

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

using ll = long long;
const int INF = 1e9 + 100;

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

  int h, w, m;
  cin >> h >> w >> m;
  map<int, set<int>> r, c;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    r[x].insert(y);
    c[y].insert(x);
  }
  int rmax = 0, cmax = 0;
  for (auto &it : r) {
    rmax = max(rmax, (int)it.second.size());
  }
  for (auto &it : c) {
    cmax = max(cmax, (int)it.second.size());
  }
  int p[400000] = {0}; // cols of rows with rmax targets and empty space
  for (auto &it : r) {
    if (rmax == (int)it.second.size()) {
      for (int i = 0; i < 400000; i++) {
        if (it.second.count(i) == 0) {
          p[i] = 1;
        }
      }
    }
  }
  // for (auto &it: p){
  // 	cout<<it<<'\\n';
  // }
  for (auto &it : c) {
    if (cmax == (int)it.second.size() && p[it.first] == 1) {
      cout << rmax + cmax << '\\n';
      return 0;
    }
  }
  cout << rmax + cmax - 1 << '\\n';
  return 0;
}

// bool f = 1;
// for (auto &itt: it.second){
// 	if (p.count(itt) == 0){
// 		cout<<rmax+cmax<<'\\n';
// 		return 0;
// 	}
// }
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int row[300020];
int maxi[300020];
int col[300020];
vector<pii> cols;
map<pii, int> m;
int main() {
  int H, W, M, ans = 0;
  scanf("%d%d%d", &H, &W, &M);
  for (int i = 0, x, y; i < M; i++) {
    scanf("%d%d", &x, &y);
    m[{x, y}] = 1;
    row[x]++;
    col[y]++;
  }
  for (int i = 1; i <= W; i++) {
    cols.push_back({col[i], i});
  }
  sort(cols.begin(), cols.end(), greater<pii>());
  for (int i = 1; i <= H; i++) {
    for (int j = 0; j < W; j++) {
      if (!m.count({i, cols[j].second})) {
        maxi[i] = max(maxi[i], cols[j].first + row[i]);
        break;
      } else {
        maxi[i] = max(maxi[i], cols[j].first + row[i] - 1);
      }
    }
    ans = max(ans, maxi[i]);
  }
  printf("%d", ans);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int row[30020];
int maxi[30020];
int col[30020];
vector<pii> cols;
map<pii, int> m;
int main() {
  int H, W, M, ans = 0;
  scanf("%d%d%d", &H, &W, &M);
  for (int i = 0, x, y; i < M; i++) {
    scanf("%d%d", &x, &y);
    m[{x, y}] = 1;
    row[x]++;
    col[y]++;
  }
  for (int i = 1; i <= W; i++) {
    cols.push_back({col[i], i});
  }
  sort(cols.begin(), cols.end(), greater<pii>());
  for (int i = 1; i <= H; i++) {
    for (int j = 0; j < W; j++) {
      if (!m.count({i, cols[j].second})) {
        maxi[i] = max(maxi[i], cols[j].first + row[i]);
        break;
      } else {
        maxi[i] = max(maxi[i], cols[j].first + row[i] - 1);
      }
    }
    ans = max(ans, maxi[i]);
  }
  printf("%d", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define PI 3.14159265359

int main() {
  ll H, W, M, h, w;
  cin >> H >> W >> M;
  set<pair<ll, ll>> m;
  vector<ll> hh(H, 0);
  vector<ll> ww(W, 0);

  ll h_max = 0, w_max = 0;
  for (auto i = 0; i < M; i++) {
    cin >> h >> w;
    h--;
    w--;
    hh[h]++;
    ww[w]++;
    m.insert(make_pair(h, w));
    h_max = max(hh[h], h_max);
    w_max = max(ww[w], w_max);
  }
  vector<int> w_index;
  w_index.reserve(W);
  for (auto k = 0; k < W; k++) {
    if (ww[k] == w_max) {
      w_index.push_back(k);
    }
  }
  for (auto i = 0; i < H; i++) {
    if (hh[i] != h_max) {
      continue;
    }
    for (auto k = w_index.begin(); k < w_index.end(); k++) {
      if (m.count(make_pair(i, *k)) == 0) {
        cout << h_max + w_max << endl;
        return 0;
      }
    }
  }
  cout << h_max + w_max - 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define PI 3.14159265359

int main() {
  ll H, W, M, h, w;
  cin >> H >> W >> M;
  vector<vector<bool>> m;
  m.reserve(H + 100);
  for (auto i = 0; i < H + 100; i++) {
    m.push_back(vector<bool>(W + 100, false));
  }
  vector<ll> hh(H + 100, 0);
  vector<ll> ww(W + 100, 0);

  ll h_max = 0, w_max = 0;
  for (auto i = 0; i < M; i++) {
    cin >> h >> w;
    h--;
    w--;
    hh[h]++;
    ww[w]++;
    m[h][w] = true;
    h_max = max(hh[h], h_max);
    w_max = max(ww[w], w_max);
  }
  vector<int> w_index;
  w_index.reserve(W);
  for (auto k = 0; k < W; k++) {
    if (ww[k] == w_max) {
      w_index.push_back(k);
    }
  }
  for (auto i = 0; i < H; i++) {
    if (hh[i] != h_max) {
      continue;
    }
    for (auto k = w_index.begin(); k < w_index.end(); k++) {
      if (!m[i][*k]) {
        cout << h_max + w_max << endl;
        return 0;
      }
    }
  }
  cout << h_max + w_max - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define ll long long
#define li long ll
#define pp pair<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr first
#define ss second
#define mod 1000000007
using namespace std;
int main() {
  fast;
  ll h, w, m;
  cin >> h >> w >> m;
  unordered_map<ll, ll> um1, um2;
  unordered_map<string, bool> res;
  while (m--) {
    ll a, b;
    cin >> a >> b;
    string s;
    s += to_string(a);
    s += to_string(b);
    res[s] = true;
    um1[a]++, um2[b]++;
  }
  ll m1 = -1, m2 = -1;
  vector<int> v1, v2;
  for (auto it : um1) {
    m1 = max(m1, it.ss);
  }
  for (auto it : um2) {
    m2 = max(m2, it.ss);
  }
  for (auto it : um1) {
    if (it.ss == m1)
      v1.pb(it.fr);
  }
  for (auto it : um2) {
    if (it.ss == m2)
      v2.pb(it.fr);
  }
  int f = 0;
  for (int i = 0; i < v1.size(); i++) {
    string str;
    for (int j = 0; j < v2.size(); j++) {
      str += to_string(v1[i]);
      str += to_string(v2[j]);
      if (res[str] == false) {
        f = 1;
        break;
      }
      str = "";
    }
    if (f == 1)
      break;
  }
  if (f == 1)
    cout << m1 + m2 << endl;
  else
    cout << m1 + m2 - 1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define ll long long
#define li long ll
#define pp pair<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr first
#define ss second
#define mod 1000000007
using namespace std;
int main() {
  fast;
  ll h, w, m;
  cin >> h >> w >> m;
  unordered_map<ll, ll> um1, um2;
  unordered_map<string, bool> res;
  while (m--) {
    ll a, b;
    cin >> a >> b;
    string s;
    s += to_string(a);
    s += to_string(b);
    res[s] = true;
    um1[a]++, um2[b]++;
  }
  ll mm = INT_MIN, ans;
  for (auto it : um2) {
    if (mm < it.ss) {
      mm = it.ss;
      ans = it.fr;
    }
  }
  vector<ll> v;
  for (auto it : um2) {
    if (it.ss == mm) {
      v.pb(it.fr);
    }
  }
  priority_queue<ll> pq;
  for (ll i = 1; i <= h; i++) {
    for (int j = 0; j < v.size(); j++) {
      string str;
      str += to_string(i);
      str += to_string(v[j]);
      if (res[str] == true)
        pq.push(um1[i] + mm - 1);
      else
        pq.push(um1[i] + mm);
    }
  }
  cout << pq.top() << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int h, w, m;
  cin >> h >> w >> m;
  vector<pair<int, int>> has;
  vector<int> cntX(h), cntY(w);
  int mx = 0, my = 0, cnt = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    has.emplace_back(--x, --y);
    cntX[x]++, cntY[y]++;
    mx = max(mx, cntX[x]);
    my = max(my, cntY[y]);
  }
  for (auto [x, y] : has) {
    if (cntX[x] == mx && cntY[y] == my)
      cnt++;
  }
  cout << mx + my -
              (cnt == count(cntX.begin(), cntX.end(), mx) *
                          count(cntY.begin(), cntY.end(), my));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimization("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;

#define _ << ": " <<
#define watch1(var1) cerr << #var1 _ var1 << '\\n';
#define watch2(var1, var2) cerr << #var1 _ var1 << ", " << #var2 _ var2 << '\\n';
#define watch3(var1, var2, var3)                                               \\
  cerr << #var1 _ var1 << ", " << #var2 _ var2 << ", " << #var3 _ var3 << '\\n';
#define watchLoop(size, arr)                                                   \\
  cerr << #arr << ": ";                                                        \\
  for (int i = 0; i < size; i++)                                               \\
    cerr << arr[i] << " \\n"[i + 1 == size];

const int N = 3e5;

int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> X(N + 1), Y(N + 1);
  map<pair<int, int>, bool> t;
  int mx = 0;
  int mxX = 0, mxY = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    X[x]++, Y[y]++;
    mxX = max(mxX, x);
    mxY = max(mxY, y);
    t[{x, y}] = 1;
  }
  // watch2(mxX, mxY);
  for (int i = 1; i <= mxX; i++) {
    for (int j = 1; j <= mxY; j++) {
      // watch2(i, j);
      // watch3(X[i], Y[j], mx);
      mx = max(mx, X[i] + Y[j] - t[{i, j}]);
    }
  }

  cout << mx;
  return 0;
}