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

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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;
}

using pint = pair<int, int>;

tuple<vector<int>, int> maxpos(vector<int> x) {
  vector<int> ans;
  int xmax = 0;
  REP(i, x.size()) { xmax = max(xmax, x[i]); }
  // cout << "max" << xmax << endl;
  REP(i, x.size()) {
    if (xmax == x[i])
      ans.push_back(i);
  }
  return forward_as_tuple(ans, xmax);
}

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  vector<int> x(H, 0), y(W, 0);
  set<pint> st;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    h[i] = a;
    w[i] = b;
    x[h[i]] += 1;
    y[w[i]] += 1;
    st.insert(pint(h[i], w[i]));
  }

  vector<int> xmax, ymax;
  int xl, yl;
  tie(xmax, xl) = maxpos(x);
  tie(ymax, yl) = maxpos(y);

  int ans = xl + yl - 1;
  for (auto xx : xmax) {
    for (auto yy : ymax) {
      if (st.find(pint(xx, yy)) == st.end()) {
        ++ans;
        goto OUT;
      }
    }
  }
OUT:
  cout << ans << endl;

  return 0;
}

/*
 3 3 3
 1 1
 2 2
 3 3
 -> ans = 2
 */


Error: TLE

Fixed submission:

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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;
}

// xが最大値をとる座標を返す
vector<int> pos(vector<int> x) {
  int xmax = 0;
  REP(i, x.size()) xmax = max(xmax, x[i]);
  vector<int> ans;
  REP(i, x.size()) {
    if (x[i] == xmax)
      ans.push_back(i);
  }
  return ans;
}

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    h[i] = a;
    w[i] = b;
  }

  vector<int> x(H, 0), y(W, 0);
  REP(i, M) {
    x[h[i]] += 1;
    y[w[i]] += 1;
  }

  vector<int> xpos = pos(x), ypos = pos(y);

  int exist = 0;
  REP(i, M) {
    REP(j, xpos.size()) REP(k, ypos.size()) {
      if (h[i] == xpos[j] and w[i] == ypos[k])
        ++exist;
    }
  }

  int gap;
  if (exist == xpos.size() * ypos.size())
    gap = 1;
  else
    gap = 0;
  /*for ( int i = 0; i < x.size(); ++i) cout << "x [" << i << "] " << x[i] <<
  endl; for ( int i = 0; i < y.size(); ++i) cout << "y [" << i << "] " << y[i]
  << endl; for ( auto a: xpos) cout << "x " << a << endl; for ( auto a: ypos)
  cout << "y " << a << endl;*/

  cout << x[xpos[0]] + y[ypos[0]] - gap << endl;

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

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

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<int> hn(h + 10, 0), wn(w + 10, 0);
  map<P, bool> hw;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    hn[hi]++;
    wn[wi]++;
    hw[make_pair(hi, wi)] = true;
  }
  ll mah = 0;
  set<ll> idh;
  rep(i, h) {
    if (mah == hn[i]) {
      idh.insert(i);
    }
    if (mah < hn[i]) {
      if (!idh.empty())
        idh.clear();
      idh.insert(i);
      mah = hn[i];
    }
  }
  ll maw = 0;
  set<ll> idw;
  rep(i, w) {
    if (maw == wn[i]) {
      idw.insert(i);
    }
    if (maw < wn[i]) {
      if (!idw.empty())
        idw.clear();
      idw.insert(i);
      maw = wn[i];
    }
  }

  ll res = mah + maw;
  bool ok = true;
  for (auto ith : idh) {
    for (auto itw : idw) {
      if (hw[make_pair(ith, itw)] == false) {
        ok = false;
      }
    }
    if (!ok)
      break;
  }
  if (ok)
    res--;
  cout << res << endl;
  // cout << ok << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> hn(h + 10, 0), wn(w + 10, 0);
  map<P, bool> hw;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    hn[hi]++;
    wn[wi]++;
    hw[make_pair(hi, wi)] = true;
  }
  ll mah = 0;
  set<ll> idh;
  rep(i, h) {
    if (mah == hn[i]) {
      idh.insert(i);
    }
    if (mah < hn[i]) {
      if (!idh.empty())
        idh.clear();
      idh.insert(i);
      mah = hn[i];
    }
  }
  ll maw = 0;
  set<ll> idw;
  rep(i, w) {
    if (maw == wn[i]) {
      idw.insert(i);
    }
    if (maw < wn[i]) {
      if (!idw.empty())
        idw.clear();
      idw.insert(i);
      maw = wn[i];
    }
  }

  ll res = mah + maw;
  bool ok = true;
  for (auto ith : idh) {
    for (auto itw : idw) {
      if (hw[make_pair(ith, itw)] == false) {
        ok = false;
      }
    }
  }
  if (ok)
    res--;
  cout << res << endl;
  // cout << ok << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> hh(H);
  vector<int> ww(W);
  vector<pair<int, int>> memo(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    memo.at(i) = make_pair(a, b);
    hh.at(a)++;
    ww.at(b)++;
  }
  int mh = 0;
  int mw = 0;
  for (int i = 0; i < H; i++) {
    mh = max(mh, hh.at(i));
  }
  for (int i = 0; i < W; i++) {
    mw = max(mw, ww.at(i));
  }
  int counth = 0;
  int countw = 0;
  for (int i = 0; i < H; i++) {
    if (mh == hh.at(i)) {
      counth++;
    }
  }
  for (int i = 0; i < W; i++) {
    if (mw == ww.at(i)) {
      countw++;
    }
  }
  int count = 0;
  for (int i = 0; i < M; i++) {
    int h = memo.at(i).first;
    int w = memo.at(i).second;
    if (hh.at(h) == mh && ww.at(w) == mw) {
      count++;
    }
  }
  if (count == counth * countw) {
    cout << mh + mw - 1 << endl;
  } else {
    cout << mh + mw << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long
  int H, W, M;
  cin >> H >> W >> M;
  vector<vector<int>> G(H, vector<int>(W, 0));
  vector<int> hh(H);
  vector<int> ww(W);
  vector<pair<int, int>> memo(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    memo.at(i) = make_pair(a, b);
    hh.at(a)++;
    ww.at(b)++;
  }
  int mh = 0;
  int mw = 0;
  for (int i = 0; i < H; i++) {
    mh = max(mh, hh.at(i));
  }
  for (int i = 0; i < W; i++) {
    mw = max(mw, ww.at(i));
  }
  int counth = 0;
  int countw = 0;
  for (int i = 0; i < H; i++) {
    if (mh == hh.at(i)) {
      counth++;
    }
  }
  for (int i = 0; i < W; i++) {
    if (mw == ww.at(i)) {
      countw++;
    }
  }
  int count = 0;
  for (int i = 0; i < M; i++) {
    int h = memo.at(i).first;
    int w = memo.at(i).second;
    if (hh.at(h) == mh && ww.at(w) == mw) {
      count++;
    }
  }
  if (count == counth * countw) {
    cout << mh + mw - 1 << endl;
  } else {
    cout << mh + mw << endl;
  }
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

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

  long long H, W, M, cmaxR{0}, cmaxC{0}, cr{0}, cc{0}, pr;
  cin >> H >> W >> M;
  vector<pair<long long int, long long int>> targets;
  vector<long long> rows(H + 1, 0), columns(W + 1, 0);
  while (M--) {
    long long int x, y;
    cin >> x >> y;
    cmaxR = max(cmaxR, ++rows[x]);
    cmaxC = max(cmaxC, ++columns[y]);
    targets.push_back({x, y});
  }
  for (auto i : rows) {
    if (i == cmaxR) {
      ++cr;
    }
  }
  for (auto i : columns) {
    if (i == cmaxC) {
      ++cc;
    }
  }
  pr = cr * cc;
  for (auto &i : targets) {
    if (rows[i.first] == cmaxR && columns[i.second] == cmaxC) {
      --pr;
    }
  }
  if (pr) {
    cout << cmaxR + cmaxC << endl;
  } else {
    cout << cmaxR + cmaxC - 1 << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {

  int h, w, m;
  cin >> h >> w >> m;
  // vector<int> H(m), W(m);
  vector<int> rowNum(h, 0);
  vector<int> columnNum(w, 0);
  vector<vector<bool>> exist(h, vector<bool>(w, false));
  int rowNumMax = 0;
  int columnNumMax = 0;
  int rowNumMaxIndex;
  int columnNumMaxIndex;
  for (int i = 0; i < m; i++) {
    int H, W;
    cin >> H >> W;
    H--;
    W--;
    rowNum[H]++;
    columnNum[W]++;
    exist[H][W] = true;
    if (chmax(rowNumMax, rowNum[H])) {
      rowNumMaxIndex = H;
    }
    if (chmax(columnNumMax, columnNum[W])) {
      columnNumMaxIndex = W;
    }
  }
  ll ans = 0;
  ans = rowNumMax + columnNumMax;
  if (exist[rowNumMaxIndex][columnNumMaxIndex]) {
    ans--;
  }
  // for (int i = 0; i < h; i++) {
  //     for (int j = 0; j < w; j++) {
  //         ll tmpAns = 0;
  //         tmpAns += rowNum[i];
  //         tmpAns += columnNum[j];
  //         if (exist[i][j]) tmpAns--;
  //         ans = max(ans, tmpAns);
  //     }
  // }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> H(h);
  rep(i, h) H[i] = 0;
  vector<int> W(w);
  rep(i, w) W[i] = 0;
  set<P> grid;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    H[a]++;
    W[b]++;
    grid.emplace(a, b);
  }

  int h_max = *max_element(H.begin(), H.end());
  int w_max = *max_element(W.begin(), W.end());
  vector<int> h_sec;
  vector<int> w_sec;
  rep(i, h) {
    if (H[i] == h_max) {
      h_sec.push_back(i);
    }
  }
  rep(i, w) {
    if (W[i] == w_max) {
      w_sec.push_back(i);
    }
  }
  int ans = h_max + w_max;
  int sub = 1;
  for (int i : h_sec) {
    for (int j : w_sec) {
      if (!grid.count(P(i, j))) {
        sub = 0;
        break;
      }
    }
    if (sub == 0)
      break;
  }
  cout << ans - sub << endl;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> H(h);
  rep(i, h) H[i] = 0;
  vector<int> W(w);
  rep(i, w) W[i] = 0;
  map<int, vector<int>> grid;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    H[a]++;
    W[b]++;
    grid[a].push_back(b);
  }

  int h_max = *max_element(H.begin(), H.end());
  int w_max = *max_element(W.begin(), W.end());
  vector<int> h_sec;
  vector<int> w_sec;
  rep(i, h) {
    if (H[i] == h_max) {
      h_sec.push_back(i);
    }
  }
  rep(i, w) {
    if (W[i] == w_max) {
      w_sec.push_back(i);
    }
  }
  int ans = h_max + w_max;
  int sub = 1;
  for (int i : h_sec) {
    for (int j : w_sec) {
      if (find(grid[i].begin(), grid[i].end(), j) == grid[i].end()) {
        sub = 0;
        break;
      }
    }
    if (sub == 0)
      break;
  }
  cout << ans - sub << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using P = pair<int, int>;
int h, w, m;
vector<int> x, y, ch(3e5, 0), cw(3e5, 0);
vector<set<int>> x2y(3e5, set<int>());
int main(void) {
  scanf("%d %d %d", &h, &w, &m);
  x.assign(m, 0);
  y.assign(m, 0);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x[i], &y[i]);
    ch[--x[i]]++;
    cw[--y[i]]++;
    x2y[x[i]].insert(y[i]);
  }
  vector<P> ph, pw;
  for (int i = 0; i < h; i++)
    ph.push_back(P(ch[i], i));
  for (int i = 0; i < w; i++)
    pw.push_back(P(cw[i], i));
  sort(ph.begin(), ph.end(), greater<P>());
  sort(pw.begin(), pw.end(), greater<P>());
  bool flg = false;
  int ans = 0;
  for (int i = 0; i < h; i++) {
    if (i > 0 && ph[i].first < ph[i - 1].first)
      break;
    ;
    for (int j = 0; j < w; j++) {
      if (j > 0 && pw[j].first < pw[j - 1].first)
        break;
      ;
      int tmp = ph[i].first + pw[j].first;
      auto itr = x2y[ph[i].second].find(pw[j].second);
      if (itr != x2y[ph[i].second].end())
        tmp--;
      else
        flg = true;
      ans = max(ans, tmp);
      if (flg)
        break;
    }
    if (flg)
      break;
  }
  printf("%d\\n", ans);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using P = pair<int, int>;
int h, w, m;
vector<int> x, y, ch(3e5, 0), cw(3e5, 0);
vector<set<int>> x2y(3e5, set<int>());
int main(void) {
  scanf("%d %d %d", &h, &w, &m);
  x.assign(m, 0);
  y.assign(m, 0);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x[i], &y[i]);
    ch[--x[i]]++;
    cw[--y[i]]++;
    x2y[x[i]].insert(y[i]);
  }
  vector<P> ph, pw;
  for (int i = 0; i < h; i++)
    ph.push_back(P(ch[i], i));
  for (int i = 0; i < w; i++)
    pw.push_back(P(cw[i], i));
  sort(ph.begin(), ph.end(), greater<P>());
  sort(pw.begin(), pw.end(), greater<P>());

  int ans = 0;
  for (int i = 0; i < h; i++) {
    if (i > 0 && ph[i].first < ph[i - 1].first)
      break;
    ;
    for (int j = 0; j < w; j++) {
      if (j > 0 && pw[j].first < pw[j - 1].first)
        break;
      ;
      int tmp = ph[i].first + pw[j].first;
      auto itr = x2y[ph[i].second].find(pw[j].second);
      if (itr != x2y[ph[i].second].end())
        tmp--;
      ans = max(ans, tmp);
    }
  }
  printf("%d\\n", ans);
}
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); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(), in.end()

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;
}

using ll = long long;
using ull = unsigned long long;
using namespace std;
using P = pair<int, int>;
using PP = pair<int, P>;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> H(h + 1, 0), W(w + 1, 0);
  vector<int> hh(m), ww(m);
  map<pair<int, int>, int> check;
  rep(i, m) {
    cin >> hh[i] >> ww[i];
    H[hh[i]]++;
    W[ww[i]]++;
    check[make_pair(hh[i], ww[i])]++;
  }

  vector<int> c1;
  int c1m = 0;
  rep(i, h + 1) chmax(c1m, H[i]);
  rep(i, h + 1) if (H[i] == c1m) c1.push_back(i);
  sort(all(c1), greater<int>());

  vector<int> c2;
  int c2m = 0;
  rep(i, w + 1) chmax(c2m, W[i]);
  rep(i, w + 1) if (W[i] == c2m) c2.push_back(i);
  sort(all(c2), greater<int>());

  rep(i, (int)c1.size()) rep(j, (int)c2.size()) {
    if (!check[make_pair(c1[i], c2[j])]) {
      cout << c1m + c2m << endl;
      return 0;
    }
  }
  cout << c1m + c2m - 1 << endl;
  return 0;
}

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); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(), in.end()

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;
}

using ll = long long;
using ull = unsigned long long;
using namespace std;
using P = pair<int, int>;
using PP = pair<int, P>;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<int> H(h + 1, 0), W(w + 1, 0);
  vector<int> hh(w), ww(w);
  map<pair<int, int>, int> check;
  rep(i, m) {
    cin >> hh[i] >> ww[i];
    H[hh[i]]++;
    W[ww[i]]++;
    check[make_pair(hh[i], ww[i])]++;
  }

  vector<int> c1;
  int c1m = 0;
  rep(i, h + 1) chmax(c1m, H[i]);
  rep(i, h + 1) if (H[i] == c1m) c1.push_back(i);
  sort(all(c1), greater<int>());

  vector<int> c2;
  int c2m = 0;
  rep(i, w + 1) chmax(c2m, W[i]);
  rep(i, w + 1) if (W[i] == c2m) c2.push_back(i);
  sort(all(c2), greater<int>());

  rep(i, (int)c1.size()) rep(j, (int)c2.size()) {
    if (!check[make_pair(c1[i], c2[j])]) {
      cout << c1m + c2m << endl;
      return 0;
    }
  }
  cout << c1m + c2m - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
}

const ld PI = 4 * atan((ld)1);
const int INF = 1e9 + 7;
const ll _INF = 1e18 + 7;
const int mxn = 3e5 + 7;

set<int> rw, cw;
int row[mxn], col[mxn], rowsum[mxn], colsum[mxn];
set<pii> st;

int main() {
  setIO();
  int r, c, m, mxr = 0, mxc = 0;
  cin >> r >> c >> m;
  for (int i = 0; i < m; i++) {
    cin >> row[i] >> col[i];
    rowsum[row[i]]++;
    colsum[col[i]]++;
    mxr = max(mxr, rowsum[row[i]]);
    mxc = max(mxc, colsum[col[i]]);
    st.insert(mp(row[i], col[i]));
  }
  for (int i = 0; i < m; i++) {
    if (rowsum[row[i]] == mxr)
      rw.insert(row[i]);
    if (colsum[col[i]] == mxc)
      cw.insert(col[i]);
  }
  for (int i : rw) {
    for (int j : cw) {
      if (!st.count(mp(i, j))) {
        cout << mxc + mxr << endl;
        return 0;
      }
    }
  }
  cout << mxr + mxc - 1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
}

const ld PI = 4 * atan((ld)1);
const int INF = 1e9 + 7;
const ll _INF = 1e18 + 7;
const int mxn = 3e5 + 7;

vector<int> rw, cw;
int row[mxn], col[mxn], rowsum[mxn], colsum[mxn];
set<pii> st;

int main() {
  setIO();
  int r, c, m, mxr = 0, mxc = 0;
  cin >> r >> c >> m;
  for (int i = 0; i < m; i++) {
    cin >> row[i] >> col[i];
    rowsum[row[i]]++;
    colsum[col[i]]++;
    mxr = max(mxr, rowsum[row[i]]);
    mxc = max(mxc, colsum[col[i]]);
    st.insert(mp(row[i], col[i]));
  }
  for (int i = 0; i < m; i++) {
    if (rowsum[row[i]] == mxr)
      rw.emp(row[i]);
    if (colsum[col[i]] == mxc)
      cw.emp(col[i]);
  }
  int ans = 0;
  for (int i = 0; i < (int)rw.size(); i++) {
    for (int j = 0; j < (int)cw.size(); j++) {
      if (st.count(mp(rw[i], cw[j])))
        ans = max(ans, mxr + mxc - 1);
      else
        ans = max(ans, mxr + mxc);
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;

  vector<pair<int, int>> vy(h), vx(w);
  for (int i = 0; i < h; i++)
    vy[i].second = i;
  for (int i = 0; i < w; i++)
    vx[i].second = i;

  set<pair<int, int>> s;
  for (int i = 0; i < n; i++) {
    int y, x;
    cin >> y >> x;
    y--, x--;
    vy[y].first++;
    vx[x].first++;
    s.insert({y, x});
  }

  sort(vy.rbegin(), vy.rend());
  sort(vx.rbegin(), vx.rend());

  int r = min(2, n);
  for (auto ey : vy) {
    if (ey.first + vx.front().first <= r)
      break;
    for (auto ex : vx) {
      if (ey.first + ex.first <= r)
        break;
      r = max(r, ey.first + ex.first - (int)s.count({ey.second, ex.second}));
    }
  }
  cout << r << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;

  vector<pair<int, int>> vy(h), vx(w);
  for (int i = 0; i < h; i++)
    vy[i].second = i;
  for (int i = 0; i < w; i++)
    vx[i].second = i;

  set<pair<int, int>> s;
  for (int i = 0; i < n; i++) {
    int y, x;
    cin >> y >> x;
    y--, x--;
    vy[y].first++;
    vx[x].first++;
    s.insert({y, x});
  }

  sort(vy.rbegin(), vy.rend());
  sort(vx.rbegin(), vx.rend());

  int r = min(2, n);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < h; j++) {
      if (vy[i].first + vx[i].first <= r)
        break;
      r = max(r, vy[i].first + vx[j].first -
                     (int)s.count({vy[i].second, vx[j].second}));
    }
  }
  cout << r << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  map<ll, ll> row, col;
  map<pair<ll, ll>, bool> field;
  for (int i = 0; i < m; ++i) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    field[{x, y}] = true;
    row[x]++;
    col[y]++;
  }

  ll max_row = 0;
  ll max_col = 0;
  for (const auto &e : row) {
    max_row = max(max_row, e.second);
  }
  for (const auto &e : col) {
    max_col = max(max_col, e.second);
  }
  ll ans = max_row + max_col;

  vector<ll> row_kouho, col_kouho;
  for (const auto &e : row) {
    if (e.second == max_row)
      row_kouho.push_back(e.first);
  }
  for (const auto &e : col) {
    if (e.second == max_col)
      col_kouho.push_back(e.first);
  }
  for (int i = 0; i < row_kouho.size(); ++i) {
    for (int j = 0; j < col_kouho.size(); ++j) {
      if (!field[{row_kouho[i], col_kouho[j]}]) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  map<ll, ll> row, col;
  vector<vector<bool>> field(h, vector<bool>(w, false));
  for (int i = 0; i < m; ++i) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    field[x][y] = true;
    row[x]++;
    col[y]++;
  }

  ll max_row = 0;
  ll max_col = 0;
  for (const auto &e : row) {
    max_row = max(max_row, e.second);
  }
  for (const auto &e : col) {
    max_col = max(max_col, e.second);
  }
  ll ans = max_row + max_col;

  vector<ll> row_kouho, col_kouho;
  for (const auto &e : row) {
    if (e.second == max_row)
      row_kouho.push_back(e.first);
  }
  for (const auto &e : col) {
    if (e.second == max_col)
      col_kouho.push_back(e.first);
  }
  for (int i = 0; i < row_kouho.size(); ++i) {
    for (int j = 0; j < col_kouho.size(); ++j) {
      if (!field[row_kouho[i]][col_kouho[j]]) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
}