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

#include <bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define H 300100
#define W 300100

lli h, w, m;

int main(void) {
  cin >> h >> w >> m;
  vector<lli> a(H);
  vector<lli> b(W);
  map<pair<lli, lli>, bool> e;
  rep(i, m) {
    lli hi, wi;
    cin >> hi >> wi;
    a[hi]++;
    b[wi]++;
    e[{hi, wi}] = true;
  }
  lli am = *max_element(a.begin(), a.end());
  lli bm = *max_element(b.begin(), b.end());
  vector<lli> p;
  vector<lli> q;
  for (int i = 1; i <= h; i++)
    if (a[i] == am)
      p.push_back(i);
  for (int i = 1; i <= w; i++)
    if (b[i] == bm)
      q.push_back(i);
  for (auto i : p) {
    for (auto j : q) {
      if (e[{i, j}] == false) {
        cout << am + bm << endl;
        return 0;
      }
    }
  }
  cout << max(0LL, am + bm - 1) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define H 1010
#define W 1010

lli h, w, m;

int main(void) {
  cin >> h >> w >> m;
  unordered_map<lli, lli> row, col;
  map<pair<lli, lli>, bool> mp;
  rep(i, m) {
    lli hi, wi;
    cin >> hi >> wi;
    mp[{hi, wi}] = true;
    row[hi]++;
    col[wi]++;
  }
  lli ans = 0;
  for (auto i : row) {
    for (auto j : col) {
      lli v = i.second + j.second;
      if (mp[{i.first, j.first}] == true)
        v--;
      ans = max(ans, v);
    }
  }
  cout << ans << endl;

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

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

int n, m, k, x, y;
vector<pair<int, int>> p;
vector<int> col, row;

int main() {
  cin >> n >> m >> k;
  row.assign(n + 1, 0);
  col.assign(m + 1, 0);

  int mxr = 0, mxc = 0;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    p.push_back({x, y});
    row[x]++;
    col[y]++;
    mxr = max(row[x], mxr);
    mxc = max(col[y], mxc);
  }

  int qtd = 0, qtdr = 0, qtdc = 0;
  for (int i = 0; i <= n; i++)
    if (row[i] == mxr)
      qtdr++;

  for (int i = 0; i <= m; i++)
    if (col[i] == mxc)
      qtdc++;

  for (auto par : p) {
    if (row[par.first] == mxr && col[par.second] == mxc) {
      qtd++;
    }
  }

  if (qtd == qtdr * qtdc)
    cout << mxr + mxc - 1 << '\\n';
  else
    cout << mxr + mxc << '\\n';

  return 0;
}


Error: 0

Fixed submission:

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

int n, m, k, x, y;
vector<pair<int, int>> p;
vector<int> col, row;

int main() {
  cin >> n >> m >> k;
  row.assign(n + 1, 0);
  col.assign(m + 1, 0);

  int mxr = 0, mxc = 0;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    p.push_back({x, y});
    row[x]++;
    col[y]++;
    mxr = max(row[x], mxr);
    mxc = max(col[x], mxc);
  }

  int qtd = 0, qtdr = 0, qtdc = 0;
  for (int i = 0; i <= n; i++)
    if (row[i] == mxr)
      qtdr++;

  for (int i = 0; i <= m; i++)
    if (col[i] == mxc)
      qtdc++;

  for (auto par : p) {
    if (row[par.first] == mxr && col[par.second] == mxc) {
      qtd++;
    }
  }

  if (qtd == qtdr * qtdc)
    cout << mxr + mxc - 1 << '\\n';
  else
    cout << mxr + mxc << '\\n';

  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;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> mpw(w);
  vector<ll> mph(h);
  map<pair<int, int>, int> mp;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    mph[a]++;
    mpw[b]++;
    mp[make_pair(a, b)]++;
  }
  ll ans = 0;
  vector<int> idh;
  rep(i, h) {
    if (ans <= mph[i]) {
      ans = max(ans, mph[i]);
      idh.push_back(i);
    }
  }
  vector<int> idh2;
  rep(i, idh.size()) {
    if (mph[idh[i]] == ans) {
      idh2.push_back(idh[i]);
    }
  }
  ll ans2 = 0;
  vector<int> idw;
  rep(i, w) {
    if (ans2 <= mpw[i]) {
      ans2 = max(ans2, mpw[i]);
      idw.push_back(i);
    }
  }
  vector<int> idw2;
  rep(i, idw.size()) {
    if (mpw[idw[i]] == ans2) {
      idw2.push_back(idw[i]);
    }
  }
  ans += ans2;
  bool flag = false;
  rep(i, idh2.size()) {
    rep(j, idw2.size()) {
      if (mp[make_pair(idh2[i], idw2[j])] == 0) {
        flag = true;
        break;
      }
    }
  }
  if (!flag)
    ans--;
  cout << ans << 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;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> mpw(w);
  vector<ll> mph(h);
  map<pair<int, int>, int> mp;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    mph[a]++;
    mpw[b]++;
    mp[make_pair(a, b)]++;
  }
  ll ans = 0;
  vector<int> idh;
  rep(i, h) {
    if (ans <= mph[i]) {
      ans = max(ans, mph[i]);
      idh.push_back(i);
    }
  }
  vector<int> idh2;
  rep(i, idh.size()) {
    if (mph[idh[i]] == ans) {
      idh2.push_back(idh[i]);
    }
  }
  ll ans2 = 0;
  vector<int> idw;
  rep(i, w) {
    if (ans2 <= mpw[i]) {
      ans2 = max(ans2, mpw[i]);
      idw.push_back(i);
    }
  }
  vector<int> idw2;
  rep(i, idw.size()) {
    if (mpw[idw[i]] == ans2) {
      idw2.push_back(idw[i]);
    }
  }
  ans += ans2;
  bool flag = false;
  rep(i, idh2.size()) {
    rep(j, idw2.size()) {
      if (mp[make_pair(idh2[i], idw2[j])] == 0)
        flag = true;
    }
  }
  if (!flag)
    ans--;
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

  set<pair<u64, u64>> B;
  vector<u64> BH(H);
  vector<u64> BW(W);

  u64 max_h = 0;
  u64 max_w = 0;

  for (u64 i = 0; i < M; i++) {
    u64 h, w;
    cin >> h >> w;
    h--;
    w--;
    B.insert(make_pair(h, w));
    BH[h]++;
    BW[w]++;
    max_h = max(max_h, BH[h]);
    max_w = max(max_w, BW[w]);
  }

  vector<pair<u64, u64>> hb_p;
  vector<pair<u64, u64>> wb_p;

  for (u64 i = 0; i < H; i++)
    if (BH[i] == max_h)
      hb_p.push_back(make_pair(BH[i], i));
  for (u64 i = 0; i < W; i++)
    if (BW[i] == max_w)
      wb_p.push_back(make_pair(BW[i], i));

  for (const auto &ph : hb_p) {
    for (const auto &pw : wb_p) {
      if (B.find(make_pair(ph.second, pw.second)) == B.end()) {
        cout << max_h + max_w << endl;
        return 0;
      }
    }
  }

  cout << max_h + max_w - 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

  vector<vector<bool>> B(H, vector<bool>(W));
  vector<u64> BH(H);
  vector<u64> BW(W);

  u64 max_h = 0;
  u64 max_w = 0;

  for (u64 i = 0; i < M; i++) {
    u64 h, w;
    cin >> h >> w;
    h--;
    w--;
    B[h][w] = true;
    BH[h]++;
    BW[w]++;
    max_h = max(max_h, BH[h]);
    max_w = max(max_w, BW[w]);
  }

  vector<pair<u64, u64>> hb_p;
  vector<pair<u64, u64>> wb_p;

  for (u64 i = 0; i < H; i++)
    if (BH[i] == max_h)
      hb_p.push_back(make_pair(BH[i], i));
  for (u64 i = 0; i < W; i++)
    if (BW[i] == max_w)
      wb_p.push_back(make_pair(BW[i], i));

  for (const auto &ph : hb_p) {
    for (const auto &pw : wb_p) {
      if (!B[ph.second][pw.second]) {
        cout << max_h + max_w << endl;
        return 0;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll, ll>;
constexpr ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> y(H);
  vector<ll> x(W);
  map<P, ll> A;
  REP(i, M) {
    P pair;
    cin >> pair.F >> pair.S;
    pair.F--;
    pair.S--;
    A[pair] = 1;
    y[pair.F]++;
    x[pair.S]++;
  }
  ll my = 0;
  ll mx = 0;
  REP(i, H) { chmax(my, y[i]); }
  REP(i, W) { chmax(mx, x[i]); }
  map<int, bool> ym;
  ll yy = 0;
  ll xx = 0;
  map<int, bool> xm;
  REP(i, H) {
    if (y[i] == my) {
      ym[i] = 1;
      yy++;
    }
  }
  REP(i, W) {
    if (x[i] == mx) {
      xm[i] = 1;
      xx++;
    }
  }
  bool non = 0;
  ll count = 0;
  for (auto itr = A.begin(); itr != A.end(); itr++) {
    if (ym[(*itr).F.F] == 1 && xm[(*itr).F.S] == 1) {
      count++;
    }
  }
  if (xx * yy != count)
    non = 1;
  cout << mx + my - 1 + non << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll, ll>;
constexpr ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> y(H);
  vector<ll> x(W);
  map<P, ll> A;
  REP(i, M) {
    P pair;
    cin >> pair.F >> pair.S;
    pair.F--;
    pair.S--;
    A[pair] = 1;
    y[pair.F]++;
    x[pair.S]++;
  }
  ll my = 0;
  ll mx = 0;
  REP(i, H) { chmax(my, y[i]); }
  REP(i, W) { chmax(mx, x[i]); }
  vector<ll> ym(0);
  vector<ll> xm(0);
  REP(i, H) {
    if (y[i] == my)
      ym.eb(i);
  }
  REP(i, W) {
    if (x[i] == mx)
      xm.eb(i);
  }
  bool non = 0;
  REP(i, ym.size()) {
    REP(l, xm.size()) {
      if (A[mp(ym[i], xm[l])] == 0)
        non = 1;
    }
  }
  cout << mx + my - 1 + non << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> s;
  vi ycnt(h);
  vi xcnt(w);
  int ymx = 0, xmx = 0;
  rep(i, m) {
    int y, x;
    cin >> y >> x;
    y--;
    x--;
    s.insert({y, x});
    ycnt[y]++;
    xcnt[x]++;
    ymx = max(ymx, ycnt[y]);
    xmx = max(xmx, xcnt[x]);
  }
  vi ym, xm;
  rep(i, h) {
    if (ycnt[i] == ymx)
      ym.push_back(i);
  }
  rep(i, w) {
    if (xcnt[i] == xmx)
      xm.push_back(i);
  }
  int ans = ymx + xmx - 1;
  for (auto i : ym) {
    for (auto j : xm) {
      if (!s.count({i, j})) {
        ans++;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vvi g(h, vi(w));
  vi ycnt(h);
  vi xcnt(w);
  int ymx = 0, xmx = 0;
  rep(i, m) {
    int y, x;
    cin >> y >> x;
    y--;
    x--;
    g[y][x] = 1;
    ycnt[y]++;
    xcnt[x]++;
    ymx = max(ymx, ycnt[y]);
    xmx = max(xmx, xcnt[x]);
  }
  vi ym, xm;
  rep(i, h) {
    if (ycnt[i] == ymx)
      ym.push_back(i);
  }
  rep(i, w) {
    if (xcnt[i] == xmx)
      xm.push_back(i);
  }
  int ans = ymx + xmx - 1;
  for (auto i : ym) {
    for (auto j : xm) {
      if (g[i][j] == 0) {
        ans++;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

set<int> existBomb;
const int WMAX = 300000;
int NY[300300], NX[300300];

signed main() {
  int H, W, M;
  cin >> H >> W >> M;
  int maxrow = -1, maxcol = -1;
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    --h, --w;
    int idx = h * WMAX + w;
    existBomb.insert(idx);
    ++NY[h], ++NX[w];
    if (maxrow == -1 || NY[h] > NY[maxrow])
      maxrow = h;
    if (maxcol == -1 || NX[w] > NX[maxcol])
      maxcol = w;
  }
  vector<pii> NNY, NNX;
  rep(i, 300000) {
    if (NY[i] == NY[maxrow]) {
      NNY.emplace_back(NY[i], i);
    }
    if (NX[i] == NX[maxcol]) {
      NNX.emplace_back(NX[i], i);
    }
  }
  uniform_int_distribution<> dy(0, NNY.size() - 1);
  uniform_int_distribution<> dx(0, NNX.size() - 1);
  random_device rnd;
  mt19937 mt(rnd());
  bool ans = false;
  rep(i, 3000000) {
    int y = dy(mt);
    int x = dx(mt);
    int h = NNY[y].second;
    int w = NNX[x].second;
    ans |= !existBomb.count(h * WMAX + w);
  }
  cout << NY[maxrow] + NX[maxcol] - (ans ? 0 : 1) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

set<int> existBomb;
const int WMAX = 300000;
int NY[300300], NX[300300];

signed main() {
  int H, W, M;
  cin >> H >> W >> M;
  int maxrow = -1, maxcol = -1;
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    --h, --w;
    int idx = h * WMAX + w;
    existBomb.insert(idx);
    ++NY[h], ++NX[w];
    if (maxrow == -1 || NY[h] > NY[maxrow])
      maxrow = h;
    if (maxcol == -1 || NX[w] > NX[maxcol])
      maxcol = w;
  }
  vector<pair<int, int>> NNY, NNX;
  rep(i, 300000) {
    if (NY[i] >= NY[maxrow] - 1 && NY[i] != 0) {
      NNY.emplace_back(NY[i], i);
    }
    if (NX[i] >= NX[maxcol] - 1 && NX[i] != 0) {
      NNX.emplace_back(NX[i], i);
    }
  }
  uniform_int_distribution<> dy(0, NNY.size() - 1);
  uniform_int_distribution<> dx(0, NNX.size() - 1);
  random_device rnd;
  mt19937 mt(rnd());
  int ans = 0;
  rep(i, 5000000) {
    int y = dy(mt);
    int x = dx(mt);
    int h = NNY[y].second;
    int w = NNX[x].second;
    ans = max(ans,
              NNY[h].first + NNX[w].first - (int)existBomb.count(h * WMAX + w));
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for (ll i = 0; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main() {
  std::cout << std::fixed << std::setprecision(10);

  ll H, W, M;

  cin >> H >> W >> M;
  vector<ll> horizon(H, 0);
  vector<ll> virtical(W, 0);
  set<pair<ll, ll>> bombs;

  REP(i, M) {
    ll h, w;
    cin >> h >> w;
    horizon[h - 1]++;
    virtical[w - 1]++;
    bombs.insert(make_pair(h - 1, w - 1));
  }

  ll h_max = 0;
  vector<size_t> h_indexes;
  REP(i, H) {
    if (h_max == horizon[i]) {
      h_indexes.push_back(i);
    }
    if (h_max < horizon[i]) {
      h_indexes.clear();
      h_max = horizon[i];
      h_indexes.push_back(i);
    }
  }

  ll w_max = 0;
  vector<size_t> w_indexes;
  REP(i, W) {
    if (w_max == virtical[i]) {
      w_indexes.push_back(i);
    }
    if (w_max < virtical[i]) {
      w_indexes.clear();
      w_max = virtical[i];
      w_indexes.push_back(i);
    }
  }

  if (w_indexes.size() * h_indexes.size() > M) {
    cout << h_max + w_max << endl;
    return 0;
  } else {
    REP(i, h_indexes.size()) {
      REP(j, w_indexes.size()) {
        if (bombs.find(make_pair(h_indexes[i], w_indexes[j])) == bombs.end()) {
          cout << h_max + w_max << endl;
          return 0;
        }
      }
    }
  }

  cout << h_max + w_max - 1 << endl;
}


Error: 0

Fixed submission:

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for (ll i = 0; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main() {
  std::cout << std::fixed << std::setprecision(10);

  ll H, W, M;

  cin >> H >> W >> M;
  vector<ll> horizon(H, 0);
  vector<ll> virtical(W, 0);
  vector<vector<ll>> bombs(H, vector<ll>(W, 0));

  REP(i, M) {
    ll h, w;
    cin >> h >> w;
    horizon[h - 1]++;
    virtical[w - 1]++;
    bombs[h - 1][w - 1]++;
  }

  ll h_max = 0;
  vector<size_t> h_indexes;
  REP(i, H) {
    if (h_max == horizon[i]) {
      h_indexes.push_back(i);
    }
    if (h_max < horizon[i]) {
      h_indexes.clear();
      h_max = horizon[i];
      h_indexes.push_back(i);
    }
  }

  ll w_max = 0;
  vector<size_t> w_indexes;
  REP(i, W) {
    if (w_max == virtical[i]) {
      w_indexes.push_back(i);
    }
    if (w_max < virtical[i]) {
      w_indexes.clear();
      w_max = virtical[i];
      w_indexes.push_back(i);
    }
  }

  ll m = 0;
  if (w_indexes.size() * h_indexes.size() > M) {
    m = max(m, h_max + w_max);
  } else {
    REP(i, h_indexes.size()) {
      REP(j, w_indexes.size()) {
        m = max(m, horizon[h_indexes[i]] + virtical[w_indexes[j]] -
                       bombs[h_indexes[i]][w_indexes[j]]);
        if (bombs[h_indexes[i]][w_indexes[j]] == 0) {
          cout << m << endl;
          return 0;
        }
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\\n"

int main() {
  faster;
  ll h, w, m;

  cin >> h >> w >> m;

  ll limit = 1e6;

  vector<ll> hs(limit, 0), ws(limit, 0);

  map<pair<ll, ll>, ll> both;

  for (ll i = 0; i < m; i++) {
    ll h1, w1;
    cin >> h1 >> w1;
    both[{h1, w1}]++;
    hs[h1]++;
    ws[w1]++;
  }

  ll mxh = *max_element(all(hs)), mxw = *max_element(all(ws));
  set<ll> vx, vy;
  for (ll i = 0; i < limit; i++)
    if (hs[i] == mxh)
      vx.insert(i);
  for (ll i = 0; i < limit; i++)
    if (ws[i] == mxw)
      vy.insert(i);

  ll ans = mxh + mxw - 1;

  for (auto x : vx) {
    for (auto y : vy) {
      if (!both.count({x, y})) {
        cout << ans + 1 << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\\n"

int main() {
  faster;
  ll h, w, m;

  cin >> h >> w >> m;

  map<ll, ll> hs, ws;

  set<pair<ll, ll>> both;

  for (ll i = 0; i < m; i++) {
    ll h1, w1;
    cin >> h1 >> w1;
    both.insert({h1, w1});
    hs[h1]++;
    ws[w1]++;
  }

  ll mxh = -1;

  for (auto x : hs) {
    for (auto y : ws) {
      ll cnt = x.second + y.second;
      if (both.find({x.first, y.first}) != both.end())
        cnt--;
      mxh = max(mxh, cnt);
    }
  }

  cout << mxh << endl;

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

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, int>
const int MOD = 1e9 + 7;
const int INF = 2e9;
const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(false);

  int h, w, m;
  cin >> h >> w >> m;
  map<P, int> mp;
  vector<P> icnt(h), jcnt(w);
  rep(k, m) {
    int i, j;
    cin >> i >> j;
    --i;
    --j;
    ++icnt[i].first;
    ++jcnt[j].first;
    ++mp[{i, j}];
  }
  rep(i, h) icnt[i].second = i;
  rep(j, w) jcnt[j].second = j;

  sort(icnt.begin(), icnt.end(), greater<>());
  sort(jcnt.begin(), jcnt.end(), greater<>());
  int im = icnt[0].first;
  int jm = jcnt[0].first;
  int ans = im + jm;
  vector<int> ii, jj;
  rep(i, h) {
    if (icnt[i].first == im)
      ii.push_back(icnt[i].second);
  }
  rep(j, w) {
    if (jcnt[j].first == jm)
      jj.push_back(jcnt[j].second);
  }
  ll ni = ii.size(), nj = jj.size();
  ll sum = ni * nj;
  if (sum <= m) {
    bool flag = 0;
    rep(i, ni) {
      rep(j, nj) {
        if (mp.find({ii[i], jj[j]}) == mp.end())
          flag = 1;
      }
    }
    if (!flag)
      --ans;
  }

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
#define repitr(itr, a) for (auto itr = a.begin(); itr != a.end(); ++itr)
#define P pair<int, int>
const int MOD = 1e9 + 7;
const int INF = 2e9;
const double PI = acos(-1);

int main() {
  ios_base::sync_with_stdio(false);

  int h, w, m;
  cin >> h >> w >> m;
  map<P, int> mp;
  vector<P> icnt(h), jcnt(w);
  rep(k, m) {
    int i, j;
    cin >> i >> j;
    --i;
    --j;
    ++icnt[i].first;
    ++jcnt[j].first;
    ++mp[{i, j}];
  }
  rep(i, h) icnt[i].second = i;
  rep(j, w) jcnt[j].second = j;

  sort(icnt.begin(), icnt.end(), greater<>());
  sort(jcnt.begin(), jcnt.end(), greater<>());
  vector<int> ii, jj;
  int im = icnt[0].first;
  int jm = jcnt[0].first;
  int ans = im + jm;
  rep(i, h) {
    if (icnt[i].first == im)
      ii.push_back(icnt[i].second);
  }
  rep(j, h) {
    if (jcnt[j].first == jm)
      jj.push_back(jcnt[j].second);
  }
  ll ni = ii.size(), nj = jj.size();

  if (ni * nj < m) {
    bool flag = 0;
    rep(i, ni) {
      rep(j, nj) {
        if (mp.find({ii[i], jj[j]}) == mp.end())
          flag = 1;
      }
    }
    if (!flag)
      --ans;
  }

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