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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> row(N, 0), col(N, 0);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    ++row[x];
    ++col[y];
    ++mp[{x, y}];
  }
  int maxx = 0, maxy = 0;
  for (int i = 1; i < N; ++i) {
    maxx = max(maxx, row[i]);
    maxy = max(maxy, col[i]);
  }
  int ans = maxx + maxy - 1;
  vector<int> r, c;
  for (int i = 1; i < N; ++i) {
    if (maxx == row[i])
      r.push_back(i);
    if (maxy == col[i])
      c.push_back(i);
  }
  for (int i = 0; i < (int)r.size(); ++i) {
    for (int j = 0; j < (int)c.size(); ++j) {
      if (mp[{r[i], c[j]}] == 0) {
        cout << ans + 1 << "\\n";
        return 0;
      }
    }
  }
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> row(N, 0), col(N, 0);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    ++row[x];
    ++col[y];
    ++mp[{x, y}];
  }
  int maxx = 0, maxy = 0;
  for (int i = 1; i < N; ++i) {
    maxx = max(maxx, row[i]);
    maxy = max(maxy, col[i]);
  }
  int ans = maxx + maxy - 1;
  vector<int> r, c;
  for (int i = 1; i < N; ++i) {
    if (maxx == row[i])
      r.push_back(i);
    if (maxy == col[i])
      c.push_back(i);
  }
  int flag = 0;
  for (int i = 0; i < (int)r.size(); ++i) {
    for (int j = 0; j < (int)c.size(); ++j) {
      if (mp[{r[i], c[j]}] == 0) {
        flag = 1;
      }
    }
  }
  if (flag)
    ++ans;
  cout << ans << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> row(N, 0), col(N, 0);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    ++row[x];
    ++col[y];
    ++mp[{x, y}];
  }
  int maxx = 0, maxy = 0;
  for (int i = 1; i < N; ++i) {
    maxx = max(maxx, row[i]);
    maxy = max(maxy, col[i]);
  }
  int ans = maxx + maxy - 1;
  vector<int> r, c;
  for (int i = 1; i < N; ++i) {
    if (maxx == row[i])
      r.push_back(i);
    if (maxy == col[i])
      c.push_back(i);
  }
  for (int i = 0; i < (int)r.size(); ++i) {
    for (int j = 0; j < (int)c.size(); ++j) {
      if (mp[{r[i], c[j]}] == 0) {
        cout << ans + 1 << "\\n";
        return 0;
      }
    }
  }
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> row(N, 0), col(N, 0);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    ++row[x];
    ++col[y];
    ++mp[{x, y}];
  }
  int maxx = 0, maxy = 0;
  for (int i = 1; i < N; ++i) {
    maxx = max(maxx, row[i]);
    maxy = max(maxy, col[i]);
  }
  int ans = maxx + maxy - 1;
  for (int i = 1; i < N; ++i) {
    if (row[i] == maxx) {
      for (int j = 1; j < N; ++j) {
        if (col[j] == maxy && mp[{i, j}] == 0) {
          ++ans;
          cout << ans << "\\n";
          return 0;
        }
      }
    }
  }
  cout << ans << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int INF = 1e16 + 7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  int H, W, M;
  cin >> H >> W >> M;
  map<P, int> Mp;
  vector<P> tate(H), yoko(W);
  vector<int> h(M), w(M);
  for (int i = 0; i < M; i++) {
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
    Mp[{h[i], w[i]}]++;
    tate[h[i]].first++;
    yoko[w[i]].first++;
  }
  for (int i = 0; i < H; i++) {
    tate[i].second = i;
  }
  for (int i = 0; i < W; i++) {
    yoko[i].second = i;
  }
  sort(tate.rbegin(), tate.rend());
  sort(yoko.rbegin(), yoko.rend());
  int ans = 0;
  int h2 = H - 1, w2 = W - 1;
  for (int i = 1; i < H; i++) {
    if (tate[i].first < tate[i - 1].first) {
      h2 = i - 1;
      break;
    }
  }
  for (int i = 1; i < W; i++) {
    if (yoko[i].first < yoko[i - 1].first) {
      w2 = i - 1;
      break;
    }
  }
  for (int i = 0; i <= h2; i++) {
    for (int j = 0; j <= w2; j++) {
      if (!Mp.count({tate[i].second, yoko[j].second})) {
        ans = max(ans, tate[i].first + yoko[j].first);
        cout << ans << endl;
        return 0;
      } else {
        ans = max(ans, tate[i].first + yoko[j].first - 1);
      }
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int INF = 1e16 + 7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<vector<int>> cnt(H, vector<int>(W));
  vector<int> tate(H);
  vector<int> yoko(W);
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    cnt[h][w]++;
    tate[h]++;
    yoko[w]++;
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int res = tate[i] + yoko[j];
      res -= cnt[i][j];
      ans = max(ans, res);
    }
  }
  cout << ans << 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;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll H, W, m, h, w;
  cin >> H >> W >> m;
  set<P> bomb;
  vector<ll> hs(H), ws(W);
  rep(i, m) {
    cin >> h >> w;
    h--, w--;
    hs[h]++, ws[w]++;
    bomb.insert(P(h, w));
  }

  ll maxh = *max_element(hs.begin(), hs.end());
  ll maxw = *max_element(ws.begin(), ws.end());
  // cerr << maxh << " " << maxw << endl;

  vector<ll> rs, cs;
  rep(i, hs.size()) if (hs[i] == maxh) rs.push_back(i);
  rep(i, ws.size()) if (ws[i] == maxw) cs.push_back(i);

  for (auto r : rs) {
    for (auto c : cs) {
      if (bomb.find(P(r, c)) == bomb.end()) {
        cout << maxh + maxw << endl;
        return 0;
      }
    }
  }
  cout << maxh + maxw - 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll H, W, m, h, w;
  cin >> H >> W >> m;
  vector<vector<ll>> d(H, vector<ll>(W, 0));
  map<ll, ll> mph, mpw;
  rep(i, m) {
    cin >> h >> w;
    h--, w--;
    mph[h]++;
    mpw[w]++;
    d[h][w] = 1;
  }

  ll ans = 0;
  for (auto x : mph) {
    for (auto y : mpw) {
      ans = max(ans, x.second + y.second - d[x.first][y.first]);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

const long long A = 100000;
int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  vector<int> row(H + 1, 0), col(W + 1, 0);
  for (int i = 0; i < M; i++) {
    cin >> h.at(i) >> w.at(i);
    row.at(h.at(i))++;
    col.at(w.at(i))++;
  }
  int maxrow = row.at(1), maxcol = col.at(1);
  int rown = 0, coln = 0;
  for (int i = 1; i <= H; i++) {
    if (maxrow == row.at(i)) {
      rown++;
    } else if (maxrow < row.at(i)) {
      maxrow = row.at(i);
      rown = 1;
    }
  }
  for (int j = 1; j <= W; j++) {
    if (maxcol == col.at(j)) {
      coln++;
    } else if (maxcol < col.at(j)) {
      maxcol = col.at(j);
      coln = 1;
    }
  }
  int x = 0;
  for (int i = 0; i < M; i++) {
    if (row.at(h.at(i)) == maxrow && col.at(w.at(i)) == maxcol) {
      x++;
    }
  }
  cout << maxcol + maxrow - (rown * coln == x);
  return 0;
}

Error: WA

Fixed submission:

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

const long long A = 100000;
int main() {
  long long H, W, M;
  cin >> H >> W >> M;
  static vector<int> h(M), w(M);
  static vector<int> row(H + 1, 0), col(W + 1, 0);
  static vector<bool> exist(H * A + W + 1, false);
  for (int i = 0; i < M; i++) {
    cin >> h.at(i) >> w.at(i);
    row.at(h.at(i))++;
    col.at(w.at(i))++;
    exist.at(h.at(i) * A + w.at(i)) = true;
  }
  vector<int> maxrowindex, maxcolindex;
  int maxrow = 0, maxcol = 0;
  for (int i = 1; i <= H; i++) {
    maxrow = max(maxrow, row.at(i));
  }
  for (int j = 1; j <= W; j++) {
    maxcol = max(maxcol, col.at(j));
  }
  if (maxrow == W && maxcol == H) {
    cout << H + W - 1;
  } else {
    for (int i = 1; i <= H; i++) {
      if (maxrow == row.at(i)) {
        maxrowindex.push_back(i);
      }
    }
    for (int j = 1; j <= W; j++) {
      if (maxcol == col.at(j)) {
        maxcolindex.push_back(j);
      }
    }
    int ans = maxrow + maxcol;
    bool x = false;
    for (int i : maxrowindex) {
      for (int j : maxcolindex) {
        if (!exist.at(i * A + j)) {
          x = true;
          goto end;
        }
      }
    }
  end:
    if (x) {
      cout << ans;
    } else {
      cout << ans - 1;
    }
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> chk[300300];
int cnt[300300];
multiset<int> wow;
int N, M, K;

int main() {
  scanf("%d %d %d", &N, &M, &K);
  for (int i = 0; i < K; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    chk[x].push_back(y);
    cnt[y]++;
  }

  for (int i = 0; i < M; i++)
    wow.insert(cnt[i]);

  int a = 0;
  for (int i = 0; i < N; i++) {
    for (auto &j : chk[i]) {
      wow.erase(wow.find(cnt[j]));
      a = max(a, (int)chk[i].size() - 1 + cnt[j]);
    }
    if (!wow.empty())
      a = max(a, (int)chk[i].size() + *(wow.end().operator--()));
    for (auto &j : chk[i])
      wow.insert(cnt[j]);
  }

  printf("%d\\n", a);
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> chk[300300];
int cnt[300300];
multiset<int> wow;
int N, M, K;

int main() {
  scanf("%d %d %d", &N, &M, &K);
  for (int i = 0; i < K; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    chk[x].push_back(y);
    cnt[y]++;
  }

  for (int i = 0; i < M; i++)
    wow.insert(cnt[i]);

  int a = 0;
  for (int i = 0; i < N; i++) {
    for (auto &j : chk[i]) {
      wow.erase(wow.find(cnt[j]));
      a = max(a, (int)chk->size() - 1 + cnt[j]);
    }
    if (!wow.empty())
      a = max(a, (int)chk[i].size() + *(wow.end().operator--()));
  }

  printf("%d\\n", a);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> hm, wm;
  set<P> st;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    hm[a]++;
    wm[b]++;
    st.insert({a, b});
  }
  int hmax = 0, wmax = 0;
  vector<int> hm_candidate, wm_candidate;
  for (auto k : hm) {
    if (k.second > hmax)
      hmax = k.second;
  }
  for (auto k : wm) {
    if (k.second > wmax)
      wmax = k.second;
  }
  for (auto k : hm) {
    if (k.second == hmax)
      hm_candidate.emplace_back(k.first);
  }
  for (auto k : wm) {
    if (k.second == wmax)
      wm_candidate.emplace_back(k.first);
  }
  rep(i, hm_candidate.size()) {
    rep(j, wm_candidate.size()) {
      if (st.find({hm_candidate[i], wm_candidate[j]}) == st.end()) {
        cout << hmax + wmax << "\\n";
        return 0;
      }
    }
  }
  cout << hmax + wmax - 1 << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int ans = 0;
  vector<int> row(h, 0);
  vector<int> column(w, 0);
  vector<vector<bool>> bom(h, vector<bool>(w, false));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    bom[a][b] = true;
    row[a]++;
    column[b]++;
  }
  rep(i, h) {
    rep(j, w) {
      int num = row[i] + column[j];
      if (bom[i][j])
        num--;
      ans = max(ans, num);
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> tate(h + 1, 0);
  vector<ll> yoko(w + 1, 0);
  set<pair<ll, ll>> bomb;

  rep(i, m) {
    ll tmph, tmpw;
    cin >> tmph >> tmpw;
    tate[tmph]++;
    yoko[tmpw]++;
    bomb.insert(make_pair(tmph, tmpw));
  }

  ll result = 0;

  ll maxh = 0;
  ll maxhSum = 0;
  for (int i = 1; i <= h; i++) {
    if (maxhSum <= tate[i]) {
      maxhSum = tate[i];
      maxh = i;
    }
  }

  // hを固定してwをさがす
  for (int i = 1; i <= w; i++) {
    ll now = yoko[i];
    ll j = 0;
    if (bomb.find(make_pair(maxh, i)) != bomb.end())
      j++;
    if (result < (maxhSum + now - j)) {
      result = (maxhSum + now - j);
    }
  }

  ll maxw = 0;
  ll maxwSum = 0;
  for (int i = 1; i <= w; i++) {
    if (maxwSum <= yoko[i]) {
      maxwSum = yoko[i];
      maxw = i;
    }
  }

  // wを固定してhをさがす
  for (int i = 1; i <= h; i++) {
    ll now = tate[i];
    ll j = 0;
    if (bomb.find(make_pair(i, maxw)) != bomb.end())
      j++;
    if (result < (maxwSum + now - j)) {
      result = (maxwSum + now - j);
    }
  }

  cout << result << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> tate(h + 1, 0);
  vector<ll> yoko(w + 1, 0);
  vector<vector<ll>> bomb(h + 1, vector<ll>(w + 1, 0));

  rep(i, m) {
    ll tmph, tmpw;
    cin >> tmph >> tmpw;
    yoko[tmpw]++;
    tate[tmph]++;
    bomb[tmph][tmpw] = 1;
  }

  ll result = 0;

  ll maxh = 0;
  ll maxhSum = 0;
  for (int i = 1; i <= h; i++) {
    if (maxhSum <= tate[i]) {
      maxhSum = tate[i];
      maxh = i;
    }
  }

  // hを固定してwをさがす
  for (int i = 1; i <= w; i++) {
    ll now = yoko[i];
    if (result < (maxhSum + now - bomb[maxh][i])) {
      result = (maxhSum + now - bomb[maxh][i]);
    }
  }

  ll maxw = 0;
  ll maxwSum = 0;
  for (int i = 1; i <= w; i++) {
    if (maxwSum <= yoko[i]) {
      maxwSum = yoko[i];
      maxw = i;
    }
  }

  // wを固定してhをさがす
  for (int i = 1; i <= h; i++) {
    ll now = tate[i];
    if (result < (maxwSum + now - bomb[i][maxw])) {
      result = (maxwSum + now - bomb[i][maxw]);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main() {
  ll i, j, n;
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> r(m), c(m);
  unordered_map<ll, ll> rm, cm;
  unordered_map<ll, unordered_map<ll, bool>> mp;
  ll mxrc = 0, mxcc = 0;
  for (i = 0; i < m; i++) {
    cin >> r[i] >> c[i];
    rm[r[i]]++;
    mxrc = max(mxrc, rm[r[i]]);
    cm[c[i]]++;
    mxcc = max(mxcc, cm[c[i]]);
    mp[r[i]][c[i]] = 1;
  }
  vector<ll> rows, cols;
  for (auto p : rm) {
    if (p.second == mxrc)
      rows.push_back(p.first);
  }
  for (auto p : cm) {
    if (p.second == mxcc)
      cols.push_back(p.first);
  }
  ll ans = 1;
  for (i = 0; i < rows.size(); i++) {
    ll cur = rm[rows[i]];
    int f = 0;
    for (j = 0; j < cols.size(); j++) {
      ll val = cur + cm[cols[j]];
      if (mp[rows[i]][cols[j]]) {
        val--;
      } else
        f++;
      ans = max(ans, val);
      if (f == 1)
        break;
    }
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main() {
  ll i, j, n;
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> r(m), c(m);
  unordered_map<ll, ll> rm, cm;
  unordered_map<ll, unordered_map<ll, bool>> mp;
  ll mxrc = 0, mxcc = 0;
  for (i = 0; i < m; i++) {
    cin >> r[i] >> c[i];
    rm[r[i]]++;
    mxrc = max(mxrc, rm[r[i]]);
    cm[c[i]]++;
    mxcc = max(mxcc, cm[c[i]]);
    mp[r[i]][c[i]] = 1;
  }
  vector<ll> rows, cols;
  for (auto p : rm) {
    if (p.second == mxrc)
      rows.push_back(p.first);
  }
  for (auto p : cm) {
    if (p.second == mxcc)
      cols.push_back(p.first);
  }
  ll ans = 1;
  for (i = 0; i < rows.size(); i++) {
    ll cur = rm[rows[i]];
    for (j = 0; j < cols.size(); j++) {
      ll val = cur + cm[cols[j]];
      if (mp[rows[i]][cols[j]])
        val--;
      ans = max(ans, val);
    }
  }
  cout << ans << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

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

  vector<int> vr(h), vc(w);
  set<P> sp;
  rep(i, m) {
    int r, c;
    cin >> r >> c;
    --r, --c;
    vr[r]++;
    vc[c]++;
    sp.emplace(r, c);
  }

  int mxr = 0, mxc = 0;
  rep(i, h) mxr = max(mxr, vr[i]);
  rep(j, w) mxc = max(mxc, vc[j]);

  vector<int> vmr, vmc;
  rep(i, h) {
    if (vr[i] == mxr)
      vmr.push_back(i);
  }
  rep(j, w) {
    if (vc[j] == mxc)
      vmc.push_back(j);
  }

  int ans = mxr + mxc;
  for (int i : vmr)
    for (int j : vmc) {
      if (sp.count(P(i, j)) == 0) {
        cout << ans << endl;
        return 0;
      }
    }
  cout << ans - 1 << endl;
}

Error: 0

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);

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

  vector<int> a(w), b(h);
  set<int> mapa[w];
  int ma = 0, mb = 0;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    ++a[x];
    ++b[y];
    mapa[x].insert(y);
    ma = max(ma, a[x]);
    mb = max(mb, b[y]);
  }

  set<int> mxa, mxb;
  rep(i, w) if (a[i] == ma) mxa.insert(i);
  rep(j, h) if (b[j] == mb) mxb.insert(j);

  int mx = ma + mb;
  for (int i : mxa) {
    for (int j : mxb) {
      if (mapa[i].count(j) == 0) {
        cout << mx << endl;
        return 0;
      }
    }
  }
  cout << mx - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF = 1e18;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll H, W, M, mh = 0, mw = 0;
  cin >> H >> W >> M;
  vector<ll> h(H), w(W);
  map<pair<ll, ll>, bool> mp;
  vector<ll> my, mx;
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    h.at(a)++;
    if (h.at(a) > mh) {
      mh = h.at(a);
    }
    w.at(b)++;
    if (w.at(b) > mw) {
      mw = w.at(b);
    }
    mp[make_pair(a, b)] = true;
  }
  rep(i, H) {
    if (h.at(i) == mh) {
      my.push_back(i);
    }
  }
  rep(i, W) {
    if (w.at(i) == mw) {
      mx.push_back(i);
    }
  }
  bool check = false;
  rep(i, my.size()) {
    rep(j, mx.size()) {
      ll x = mx.at(j);
      ll y = my.at(i);
      if (mp.count({y, x}) == 0) {

        check = true;
        break;
      }
    }
    if (check == true)
      break;
  }
  if (check) {
    cout << mw + mh << endl;
  } else {
    cout << mw + mh - 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF = 1e18;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll H, W, M, mh = 0, mw = 0;
  cin >> H >> W >> M;
  vector<ll> h(H), w(W);
  map<pair<ll, ll>, bool> mp;
  vector<ll> my, mx;
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    h.at(a)++;
    if (h.at(a) > mh) {
      mh = h.at(a);
    }
    w.at(b)++;
    if (w.at(b) > mw) {
      mw = w.at(b);
    }
    mp[make_pair(a, b)] = true;
  }
  rep(i, H) {
    if (h.at(i) == mh) {
      my.push_back(i);
    }
  }
  rep(i, W) {
    if (w.at(i) == mw) {
      mx.push_back(i);
    }
  }
  bool check = false;
  rep(i, my.size()) {
    rep(j, mx.size()) {
      ll x = mx.at(j);
      ll y = my.at(i);
      if (mp.count({y, x}) == 0) {

        check = true;
      }
    }
  }
  if (check) {
    cout << mw + mh << endl;
  } else {
    cout << mw + mh - 1 << endl;
  }
}