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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {
  long long h, w, m;
  cin >> h >> w >> m;

  vector<long long> v1(h, 0);
  vector<long long> v2(w, 0);
  set<pair<long long, long long>> T;

  for (long long i = 0; i < m; i++) {
    long long hm, wm;
    cin >> hm >> wm;
    hm--;
    wm--;
    T.insert(make_pair(hm, wm));
    v1[hm]++;
    v2[wm]++;
  }

  vector<long long> index_h;
  vector<long long> index_w;
  long long maxw = 0, maxh = 0;

  for (long long i = 0; i < h; i++)
    maxh = max(maxh, v1[i]);
  for (long long i = 0; i < w; i++)
    maxw = max(maxw, v2[i]);

  for (long long i = 0; i < h; i++) {
    if (maxh == v1[i])
      index_h.push_back(i);
  }
  for (long long i = 0; i < w; i++) {
    if (maxw == v2[i])
      index_w.push_back(i);
  }

  long long ans = maxh + maxw;

  if (index_h.size() * index_w.size() > m) {
    cout << ans << endl;
    return 0;
  }

  bool find = true;
  for (long long y = 0; y < index_h.size(); y++) {
    for (long long x = 0; x < index_w.size(); x++) {
      if (T.find(make_pair(index_h[y], index_w[x])) == T.end()) {
        find = false;
        break;
      }
    }
  }

  if (find == true)
    ans--;

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

long long h, w, m;
set<pair<long long, long long>> T;

vector<long long> h_cnt(300000, 0);
vector<long long> w_cnt(300000, 0);

long long cnt_bomb(long long y, long long x) {
  long long cnt = 0;

  cnt += h_cnt[y] + w_cnt[x];

  if (T.find(make_pair(y, x)) != T.end())
    cnt--;

  return cnt;
}

int main() {
  cin >> h >> w >> m;

  for (long long i = 0; i < m; i++) {
    long long hm, wm;
    cin >> hm >> wm;
    hm--;
    wm--;
    T.insert(make_pair(hm, wm));
  }

  for (long long y = 0; y < h; y++) {
    for (long long x = 0; x < w; x++) {
      if (T.find(make_pair(y, x)) != T.end())
        h_cnt[y]++;
    }
  }

  for (long long x = 0; x < w; x++) {
    for (long long y = 0; y < h; y++) {
      if (T.find(make_pair(y, x)) != T.end())
        w_cnt[x]++;
    }
  }

  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      ans = max(ans, cnt_bomb(i, j));
    }
  }

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

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

#define ll long long
#define fi first
#define se second
#define inf 1e15

#define N 300005

int row[N];
int col[N];

vector<int> rowv, colv;

set<pair<int, int>> bomb;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t = 1;
  // cin>>t;
  while (t--) {

    int n, m, k;
    cin >> n >> m >> k;

    int rowh = 0, colh = 0;
    for (int i = 0; i < k; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;

      bomb.insert({x, y});

      row[x]++;
      col[y]++;

      rowh = max(rowh, row[x]);
      colh = max(colh, col[y]);
    }

    for (int i = 0; i < n; i++) {
      if (row[i] == rowh) {
        rowv.push_back(i);
      }
    }
    for (int i = 0; i < m; i++) {
      if (col[i] == colh) {
        colv.push_back(i);
      }
    }

    ll ans = rowh + colh - 1;

    for (auto i : rowv) {
      for (auto j : colv) {

        if (bomb.find({i, j}) == bomb.end()) {
          ans++;
          goto end;
        }
      }
    }

  end:
    cout << ans << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

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

#define ll long long
#define fi first
#define se second
#define inf 1e15

#define N 100005

int row[N];
int col[N];

vector<int> rowv, colv;

set<pair<int, int>> bomb;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t = 1;
  // cin>>t;
  while (t--) {

    int n, m, k;
    cin >> n >> m >> k;

    int rowh = 0, colh = 0;
    for (int i = 0; i < k; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;

      bomb.insert({x, y});

      row[x]++;
      col[y]++;

      rowh = max(rowh, row[x]);
      colh = max(colh, col[y]);
    }

    for (int i = 0; i < n; i++) {
      if (row[i] == rowh) {
        rowv.push_back(i);
      }
    }
    for (int i = 0; i < m; i++) {
      if (col[i] == colh) {
        colv.push_back(i);
      }
    }

    ll ans = rowh + colh - 1;

    for (auto i : rowv) {
      for (auto j : colv) {

        if (bomb.find({i, j}) == bomb.end()) {
          ans++;
          goto end;
        }
      }
    }

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

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

const int N = 300004;
int cnth[N], cntw[N], x[N], y[N];
map<int, bool> mp[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    mp[x[i]][y[i]] = true;
    cnth[x[i]]++, cntw[y[i]]++;
  }
  int mxh = 0, mxw = 0;
  for (int i = 0; i < N; i++) {
    mxh = max(mxh, cnth[i]);
    mxw = max(mxw, cntw[i]);
  }
  vector<int> hall, wall;
  for (int i = 0; i < N; i++) {
    if (cnth[i] == mxh) {
      hall.push_back(i);
    }
    if (cntw[i] == mxw) {
      wall.push_back(i);
    }
  }
  int cnt = 0, mx = 0;
  for (int i = 0; i < hall.size(); i++) {
    for (int j = 0; j < wall.size(); j++) {
      cnt++;
      if (cnt > N * 2)
        break;
      mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]);
    }
    if (cnt > N * 2)
      break;
  }
  cout << mx;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define mxn 200005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
#define ld long double
typedef long long int ll;
using namespace std;
int r[mxn], c[mxn];
int main(void) {
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;
  int h, w, m, i, j, ans = 0, a, b, mr = 0, mc = 0;
  set<pair<int, int>> s;
  cin >> h >> w >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    r[a]++;
    c[b]++;
    s.insert({a, b});
  }
  vector<int> mrc;
  vector<int> mcc;
  for (i = 1; i <= h; i++) {
    mr = max(mr, r[i]);
  }
  for (i = 1; i <= w; i++) {
    mc = max(mc, c[i]);
  }
  for (i = 1; i <= h; i++) {
    if (r[i] == mr)
      mrc.pb(i);
  }
  for (i = 1; i <= w; i++) {
    if (c[i] == mc)
      mcc.pb(i);
  }
  ans = mr + mc - 1;
  if (mrc.size() * 1LL * mcc.size() > 300000)
    cout << ans << endl;
  else {
    for (auto x : mrc) {
      for (auto y : mcc) {
        if (s.find({x, y}) == s.end())
          ans = max(ans, mr + mc);
      }
    }
  }
  cout << ans;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> r, c;
  map<pair<int, int>, int> ma;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    ma[{x, y}]++;
    r[x]++;
    c[y]++;
  }

  int maxRow = 0;
  for (auto t : r) {
    maxRow = max(t.second, maxRow);
  }
  int maxCol = 0;
  for (auto t : c) {
    maxCol = max(t.second, maxCol);
  }

  vector<int> row, col;
  for (auto t : r) {
    if (t.second == maxRow)
      row.emplace_back(t.first);
  }
  for (auto t : c) {
    if (t.second == maxCol)
      col.emplace_back(t.first);
  }

  bool f = false;
  for (int i = 0; i < row.size(); i++) {
    // cout<<row[i]<<' ';
    for (int j = 0; j < col.size(); j++) {
      // cout<<col[j]<<' ';
      if (ma.find({row[i], col[j]}) == ma.end()) {
        f = true;
        break;
      }
    }
    // cout<<'\\n';
  }

  f ? cout << maxCol + maxRow : cout << maxCol + maxRow - 1;
  cout << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

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

static bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
vector<pair<int, int>> v;

static bool comp2(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second == b.second)
    return a.first < b.first;
  return a.second < b.second;
}
int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

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

  int x, y;
  map<pair<int, int>, int> ma;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v.push_back({x, y});
    ma[{x, y}]++;
  }

  sort(v.begin(), v.end(), comp);

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

  for (int i = 1; i <= h; i++) {
    int count = 0;
    for (int j = 1; j <= w; j++) {
      if (ma.find({i, j}) != ma.end())
        count++;
    }
    row[i] = count;
  }

  sort(v.begin(), v.end(), comp2);

  for (int j = 1; j <= w; j++) {
    int count = 0;
    for (int i = 1; i <= h; i++) {
      if (ma.find({i, j}) != ma.end())
        count++;
    }
    col[j] = count;
  }

  long long int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      long long int temp = row[i] + col[j];
      if (ma.find({i, j}) != ma.end())
        temp--;
      ans = max(ans, temp);
    }
  }

  cout << ans << '\\n';

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, f) for (int i = (int)s; i < (int)f; i++)
using ll = long long;
using namespace std;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  map<int, int> height;
  map<int, int> width;
  vector<vector<int>> target_h(H);
  vector<vector<int>> target_w(W);
  int max_h = -1;
  int max_w = -1;
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    target_h[h].push_back(w);
    target_w[w].push_back(h);
    height[h]++;
    width[w]++;
    if (height[max_h] < height[h]) {
      max_h = h;
    }
    if (width[max_w] < width[w]) {
      max_w = w;
    }
  }
  map<int, bool> seen_w;
  for (auto p : height) {
    if (height[max_h] == p.second) {
      for (int v : target_h[max_h]) {
        seen_w[v] = true;
      }
    }
  }
  bool is_max = true;
  for (auto p : width) {
    if (width[max_w] == p.second && !seen_w[p.first]) {
      is_max = false;
      break;
    }
  }
  map<int, bool> seen_h;
  for (auto p : width) {
    if (width[max_w] == p.second) {
      for (int v : target_w[max_w]) {
        seen_h[v] = true;
      }
    }
  }
  for (auto p : height) {
    if (height[max_h] == p.second && !seen_h[p.first]) {
      is_max = false;
      break;
    }
  }
  if (is_max) {
    cout << height[max_h] + width[max_w] - 1 << endl;
  } else {
    cout << height[max_h] + width[max_w] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, f) for (int i = (int)s; i < (int)f; i++)
using ll = long long;
using namespace std;

int main() {
  srand(time(NULL));
  int H, W, M;
  cin >> H >> W >> M;
  /*
  H=3*1e5;
  W=3*1e5;
  M=3*1e5;
  */
  vector<vector<int>> grid(H, vector<int>(W, 0));
  vector<int> we(H, 0);
  vector<int> he(W, 0);
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    grid[h][w] = 1;
    we[h]++;
    he[w]++;
  }
  /*
  while(M!=0)
  {
          int h=rand()%H;
          int w=rand()%W;
          if(grid[h][w]==1) continue;
          grid[h][w]=1;
          we[h]++;
          he[w]++;
          M--;
  }*/
  int ans = 0;
  rep(i, H) {
    rep(j, W) {
      int v = we[i] + he[j] - grid[i][j];
      if (ans < v)
        ans = v;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const ll MOD = 1e9 + 7;

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vi h(M), w(M);
  map<int, int> mph, mpw;
  set<pii> st;
  int hmaxval = 0, wmaxval = 0;
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--, w[i]--;
    chmax(hmaxval, ++mph[h[i]]);
    chmax(wmaxval, ++mpw[w[i]]);
    st.insert({h[i], w[i]});
  }

  vi hmax, wmax;
  for (auto p : mph) {
    if (p.second == hmaxval)
      hmax.push_back(p.first);
  }
  for (auto p : mpw) {
    if (p.second == wmaxval)
      wmax.push_back(p.first);
  }
  int ans = hmaxval + wmaxval - 1;
  for (auto h : hmax) {
    for (auto w : wmax) {
      if (!st.count({h, w})) {
        ans++;
        goto FIN;
      }
    }
  }
FIN:
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;

const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const ll MOD = 1e9 + 7;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vi h(M), w(M);
  map<int, int> mph, mpw;
  map<pii, int> mp;
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--, w[i]--;
    mph[h[i]]++;
    mpw[w[i]]++;
    mp[{h[i], w[i]}]++;
  }

  vector<pii> cnth, cntw;
  for (auto p : mph) {
    cnth.push_back({p.second, p.first});
  }
  sort(all(cnth), greater<pii>{});
  for (auto p : mpw) {
    cntw.push_back({p.second, p.first});
  }
  sort(all(cntw), greater<pii>{});
  int ans = 0, k = 0;
  for (int i = 0; i < cnth.size(); i++) {
    for (int j = 0; j < cntw.size(); j++) {
      k++;
      int h, w;
      h = cnth[i].second, w = cntw[j].second;
      ans = max(ans, cnth[i].first + cntw[j].first - mp[{h, w}]);
      if (k > 1e7)
        goto FIN;
    }
  }
FIN:
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int H, W, M;
set<i_i> st;

void input() {
  cin >> H >> W >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    st.insert({a, b});
  }
}

void solve() {
  map<int, int> mph, mpw;
  int hmaxval = 0;
  int wmaxval = 0;
  vector<int> hmax, wmax;
  for (auto tmp : st) {
    chmax(hmaxval, ++mph[tmp.first]);
    chmax(wmaxval, ++mpw[tmp.second]);
  }
  for (auto tmp : mph) {
    if (hmaxval == tmp.second)
      hmax.push_back(tmp.first);
  }
  for (auto tmp : mpw) {
    if (wmaxval == tmp.second)
      wmax.push_back(tmp.first);
  }
  int ANS = hmaxval + wmaxval - 1;
  for (auto h : hmax) {
    for (auto w : wmax) {
      if (st.find({h, w}) == st.end()) {
        ANS++;
        cout << ANS << endl;
        return;
      }
    }
  }
  cout << ANS << endl;
}

int main() {
  input();
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using P = pair<int, int>;

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

  vector<vector<bool>> isExist(H, vector<bool>(W, false));
  vector<int> bombHNums(H, 0);
  vector<int> bombWNums(W, 0);

  vector<P> bombs(M, P(0, 0));
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    bombs.at(i).first = h;
    bombs.at(i).second = w;
    isExist.at(h).at(w) = true;

    bombHNums.at(h) = bombHNums.at(h) + 1;
    bombWNums.at(w) = bombWNums.at(w) + 1;
  }

  // cout << "show bombHNums" << endl;
  // for(int n : bombHNums)cout << n << " ";
  // cout << endl;

  // cout << "show bombWNums" << endl;
  // for(int n : bombWNums)cout << n << " ";
  // cout << endl;

  int hmax = 0;
  for (int h = 0; h < H; h++)
    hmax = max(hmax, bombHNums.at(h));

  vector<int> searchH(0);
  for (int h = 0; h < H; h++)
    if (bombHNums.at(h) == hmax)
      searchH.push_back(h);

  int wmax = 0;
  for (int w = 0; w < W; w++)
    wmax = max(wmax, bombWNums.at(w));

  vector<int> searchW(0);
  for (int w = 0; w < W; w++)
    if (bombWNums.at(w) == wmax)
      searchW.push_back(w);

  for (int h : searchH) {
    for (int w : searchW) {
      if (!(isExist.at(h).at(w))) {
        cout << hmax + wmax << endl;
        return 0;
      }
    }
  }

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// 定数
#define INF 1000000000 // 10^9:極めて大きい値,∞
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素

int h, w, m;

int main() {
  cin >> h >> w >> m;
  vector<int> yv(h), xv(w);
  int x, y;
  set<pair<int, int>> s;
  rep(i, m) {
    cin >> y >> x;
    y--;
    x--;
    s.insert(make_pair(y, x));
    yv[y]++;
    xv[x]++;
  }
  int ymax = *max_element(yv.begin(), yv.end());
  int xmax = *max_element(xv.begin(), xv.end());
  ll ans = xmax + ymax;
  vector<int> yvv, xvv;

  rep(i, h) if (yv[i] == ymax) yvv.push_back(i);
  rep(i, w) if (xv[i] == xmax) xvv.push_back(i);

  for (int y : yvv) {
    for (int x : xvv) {
      if (s.count(make_pair(y, x)) == 0) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// 定数
#define INF 1000000000 // 10^9:極めて大きい値,∞
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素

int h, w, m;

int main() {
  cin >> h >> w >> m;
  vector<int> yv(h), xv(w);
  int x, y;
  set<pair<int, int>> s;
  rep(i, m) {
    cin >> y >> x;
    y--;
    x--;
    s.insert(make_pair(y, x));
    yv[y]++;
    xv[x]++;
  }
  int ymax = 0;
  rep(i, h) { ymax = max(ymax, yv[i]); }
  ll ans = ymax;
  int xmax = 0;
  rep(i, w) { xmax = max(xmax, xv[i]); }
  ans += xmax;
  rep(i, h) {
    if (yv[i] == ymax) {
      rep(j, w) {
        if (xv[j] == xmax) {
          if (s.count(make_pair(i, j)) == 0) {
            cout << ans << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define FASTIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
using ll = long long;

int main() {
  FASTIO
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  vector<int> horizontal(w + 1), vertical(h + 1);
  unordered_map<int, unordered_map<int, bool>> mp;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    mp[a][b] = 1;
    horizontal[b]++;
    vertical[a]++;
  }
  int mx = 0;
  vector<int> u, v;
  mx = *max_element(vertical.begin(), vertical.end());
  for (int i = 0; i <= h; i++) {
    if (mx == vertical[i]) {
      u.push_back(i);
    }
  }
  mx = *max_element(horizontal.begin(), horizontal.end());
  for (int i = 0; i <= w; i++) {
    if (mx == horizontal[i]) {
      v.push_back(i);
    }
  }
  for (int i = 0; i < u.size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      mx = max(mx, horizontal[v[j]] + vertical[u[i]] - mp[u[i]][v[j]]);
      if (!mp[u[i]][v[j]])
        return cout << mx << endl, 0;
    }
  }
  cout << mx << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define FASTIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
using ll = long long;

int main() {
  FASTIO
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  vector<int> horizontal(w + 1), vertical(h + 1);
  unordered_map<int, unordered_map<int, bool>> mp;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    mp[a][b] = 1;
    horizontal[b]++;
    vertical[a]++;
  }
  int mx = 0;
  vector<int> u, v;
  mx = *max_element(vertical.begin(), vertical.end());
  for (int i = 0; i <= h; i++) {
    if (mx == vertical[i]) {
      u.push_back(i);
    }
  }
  mx = *max_element(horizontal.begin(), horizontal.end());
  for (int i = 0; i <= w; i++) {
    if (mx == horizontal[i]) {
      v.push_back(i);
    }
  }
  for (int i = 0; i < u.size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      mx = max(mx, horizontal[v[j]] + vertical[u[i]] - mp[u[i]][v[j]]);
    }
  }
  cout << mx << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

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

  map<int, set<int>> xy, yx;

  rep(i, M) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    xy[x].insert(y);
    yx[y].insert(x);
  }

  int xmax = -1, ymax = -1;
  rep(i, H) { xmax = max(xmax, (int)xy[i].size()); }
  rep(i, W) { ymax = max(ymax, (int)yx[i].size()); }

  vi xx, yy;
  rep(i, H) {
    if ((int)xy[i].size() == xmax) {
      xx.push_back(i);
    }
  }
  rep(i, W) {
    if ((int)yx[i].size() == ymax) {
      yy.push_back(i);
    }
  }

  int ans = xmax + ymax - 1;
  rep(i, xx.size()) {
    bool flg = false;
    rep(j, yy.size()) {
      if (!xy[xx[i]].count(yy[j])) {
        ans++;
        flg = true;
        break;
      }
    }
    if (flg)
      break;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vi h(M), w(M);
  vector<vb> G(H, vb(W, false));
  rep(i, M) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
    G[h[i]][w[i]] = true;
  }

  vi R(H);
  rep(i, M) { R[h[i]]++; }

  int rmax = -1;
  rep(i, H) { rmax = max(rmax, R[i]); }

  vi rr;
  rep(i, H) {
    if (R[i] == rmax)
      rr.push_back(i);
  }

  vi C(W);
  rep(i, M) { C[w[i]]++; }

  int cmax = -1;
  rep(i, W) { cmax = max(cmax, C[i]); }
  vi cc;
  rep(i, W) {
    if (C[i] == cmax)
      cc.push_back(i);
  }

  int ans = rmax + cmax - 1;
  rep(i, rr.size()) {
    rep(j, cc.size()) {
      if (G[rr[i]][cc[j]]) {
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;
}