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

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> hs(h), ws(w);
  set<P> s;
  rep(i, n) {
    int r, c;
    cin >> r >> c;
    r--;
    c--;
    hs[r]++;
    ws[c]++;
    s.emplace(r, c);
  }

  int mh = 0, mw = 0;
  rep(i, h) mh = max(mh, hs[i]);
  rep(j, w) mw = max(mw, ws[j]);
  vector<int> is, js;
  rep(i, h) if (mh == hs[i]) is.push_back(i);
  rep(j, w) if (mw == ws[j]) js.push_back(j);

  int ans = mh + mw;
  for (int i : is) {
    for (int j : js) {
      if (s.count(P(i, j)))
        continue;
      cout << ans << endl;
      return 0;
    }
  }
  ans--;
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> hs(h), ws(w);
  set<P> s;
  rep(i, n) {
    int r, c;
    cin >> r >> c;
    r--;
    c--;
    hs[r]++;
    ws[c]++;
    s.emplace(r, c);
  }

  int mh = 0, mw = 0;
  rep(i, h) mh = max(mh, hs[i]);
  rep(j, w) mw = max(mw, ws[j]);
  vector<int> is, js;
  rep(i, h) if (mh == hs[i]) is.push_back(i);
  rep(j, w) if (mw == hs[j]) js.push_back(j);

  int ans = mh + mw;
  for (int i : is) {
    for (int j : js) {
      if (s.count(P(i, j)))
        continue;
      cout << ans << endl;
      return 0;
    }
  }
  ans--;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll rows[300005];
ll cols[300005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll r, c, i, j, n, k;
  cin >> r >> c >> n;
  map<pair<ll, ll>, ll> mat;
  while (n--) {
    cin >> i >> j;
    rows[i]++;
    cols[j]++;
    mat[{i, j}]++;
  }
  ll ans = 0;
  map<ll, vector<ll>> row_max, col_max;
  for (i = 1; i <= r; i++) {
    row_max[rows[i]].push_back(i);
  }
  for (i = 1; i <= c; i++) {
    col_max[cols[i]].push_back(i);
  }
  auto it1 = row_max.rbegin();
  vector<ll> g1 = it1->second;
  auto it2 = col_max.rbegin();
  vector<ll> g2 = it2->second;
  for (auto a : g1) {
    for (auto b : g2) {
      if (mat[{a, b}] >= 1) {
        ans = max(ans, rows[a] + cols[b] - 1);
      } else {
        cout << rows[a] + cols[b];
        return 0;
      }
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll rows[300005];
ll cols[300005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll r, c, i, j, n, k;
  cin >> r >> c >> n;
  map<pair<ll, ll>, ll> mat;
  while (n--) {
    cin >> i >> j;
    rows[i]++;
    cols[j]++;
    mat[{i, j}]++;
  }
  ll ans = 0;
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      if (mat[{i, j}] >= 1) {
        ans = max(ans, rows[i] + cols[j] - 1);
      } else {
        ans = max(ans, rows[i] + cols[j]);
      }
    }
  }
  cout << ans;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  map<ll, ll> Hn;
  map<ll, ll> Wn;
  set<pair<ll, ll>> S;
  for (ll i = 0; i < M; i++) {
    ll hn, wn;
    cin >> hn >> wn;
    Hn[hn]++;
    Wn[wn]++;
    S.insert(make_pair(hn, wn));
  }
  vector<ll> Hindex(0);
  vector<ll> Windex(0);
  ll Hmax = 0;
  for (ll i = 1; i <= H; i++) {
    if (Hn[i] > Hmax) {
      Hindex = {i};
      Hmax = Hn[i];
    } else if (Hn[i] == Hmax) {
      Hindex.push_back(i);
    }
  }
  ll Wmax = 0;
  for (ll i = 1; i <= W; i++) {
    if (Wn[i] > Wmax) {
      Windex = {i};
      Wmax = Wn[i];
    } else if (Wn[i] == Wmax) {
      Windex.push_back(i);
    }
  }
  for (ll h : Hindex) {
    for (ll w : Windex) {
      if (!S.count(make_pair(h, w))) {
        cout << Hmax + Wmax << endl;
        return 0;
      }
    }
  }
  cout << Hmax + Wmax - 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  map<ll, ll> Hn;
  map<ll, ll> Wn;
  vector<vector<bool>> TF(H, vector<bool>(W, false));
  for (ll i = 0; i < M; i++) {
    ll hn, wn;
    cin >> hn >> wn;
    Hn[hn]++;
    Wn[wn]++;
    TF[hn - 1][wn - 1] = true;
  }
  vector<ll> Hindex(0);
  vector<ll> Windex(0);
  ll Hmax = 0;
  for (ll i = 1; i <= H; i++) {
    if (Hn[i] > Hmax) {
      Hindex = {i};
      Hmax = Hn[i];
    } else if (Hn[i] == Hmax) {
      Hindex.push_back(i);
    }
  }
  ll Wmax = 0;
  for (ll i = 1; i <= W; i++) {
    if (Wn[i] > Wmax) {
      Windex = {i};
      Wmax = Wn[i];
    } else if (Wn[i] == Wmax) {
      Windex.push_back(i);
    }
  }
  for (ll h : Hindex) {
    for (ll w : Windex) {
      if (!TF[h - 1][w - 1]) {
        cout << Hmax + Wmax << endl;
        return 0;
      }
    }
  }
  cout << Hmax + Wmax - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
ifstream input_from_file("input.txt");
#define cin input_from_file
#else

#endif

const int pp = 1 << 19;

int seg[2 * pp];

void add(int v, int x) {
  v += pp;
  seg[v] += x;
  v /= 2;
  while (v > 0)
    seg[v] = max(seg[2 * v], seg[2 * v + 1]), v /= 2;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); // Togliere nei problemi con query online

  int H, W;
  cin >> H >> W;
  int M;
  cin >> M;
  set<int> setrows, setcols;
  vector<int> h(M), w(M);
  for (int i = 0; i < M; i++)
    cin >> h[i] >> w[i], setrows.insert(h[i]), setcols.insert(w[i]);
  vector<int> rows(setrows.begin(), setrows.end());
  vector<int> cols(setcols.begin(), setcols.end());

  unordered_map<int, int> rowtoid;
  for (int i = 0; i < (int)rows.size(); i++)
    rowtoid[rows[i]] = i;
  unordered_map<int, int> coltoid;
  for (int i = 0; i < (int)cols.size(); i++)
    coltoid[cols[i]] = i;

  vector<vector<int>> ptrow(rows.size());
  for (int i = 0; i < M; i++) {
    ptrow[rowtoid[h[i]]].push_back(coltoid[w[i]]);
  }
  vector<int> qqcol(cols.size(), 0);
  for (int i = 0; i < M; i++)
    qqcol[coltoid[w[i]]]++;
  for (int i = 0; i < (int)cols.size(); i++)
    add(i, qqcol[i]);
  //~ cout << seg[1] << endl;
  int res = 0;

  for (int i = 0; i < (int)rows.size(); i++) {
    for (int x : ptrow[i])
      add(x, -1);
    res = max(res, seg[1] + (int)ptrow[i].size());
    for (int x : ptrow[i])
      add(x, 1);
  }
  cout << res << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
ifstream input_from_file("input.txt");
#define cin input_from_file
#else

#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); // Togliere nei problemi con query online

  int H, W;
  cin >> H >> W;
  vector<vector<bool>> pres(H, vector<bool>(W, false));
  vector<int> qqrow(H, 0), qqcol(W, 0);
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    pres[h][w] = true;
    qqrow[h]++, qqcol[w]++;
  }
  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int qq = qqrow[i] + qqcol[j];
      if (pres[i][j])
        qq--;
      res = max(res, qq);
    }
  }
  cout << res << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 3e5 + 10;
int cnt1[MAXN], cnt2[MAXN];
void solve() {
  int h, w, n;
  cin >> h >> w >> n;
  set<pii> a;
  for (int i = 1; i <= n; ++i) {
    int x, y;
    cin >> x >> y;
    cnt1[x]++;
    cnt2[y]++;
    a.insert(mp(x, y));
  }
  int mx = *max_element(cnt1 + 1, cnt1 + h + 1);
  int mx2 = *max_element(cnt2 + 1, cnt2 + w + 1);
  veci x, y;
  for (int i = 1; i <= h; ++i)
    if (cnt1[i] == mx)
      x.pb(i);
  for (int i = 1; i <= w; ++i)
    if (cnt2[i] == mx2)
      y.pb(i);
  int ans = 0;
  for (auto v : x)
    for (auto u : y) {
      int ch = a.count(mp(v, u));
      ans = max(ans, cnt1[v] + cnt2[u] - ch);
      if (!ch)
        break;
    }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 3e5 + 10;
int cnt1[MAXN], cnt2[MAXN];
void solve() {
  int h, w, n;
  cin >> h >> w >> n;
  set<pii> a;
  for (int i = 1; i <= n; ++i) {
    int x, y;
    cin >> x >> y;
    cnt1[x]++;
    cnt2[y]++;
    a.insert(mp(x, y));
  }
  int mx = *max_element(cnt1 + 1, cnt1 + h + 1);
  int mx2 = *max_element(cnt2 + 1, cnt2 + w + 1);
  veci x, y;
  for (int i = 1; i <= h; ++i)
    if (cnt1[i] == mx)
      x.pb(i);
  for (int i = 1; i <= w; ++i)
    if (cnt2[i] == mx2)
      y.pb(i);
  int ans = 0;
  for (auto v : x)
    for (auto u : y)
      ans = max(ans, cnt1[v] + cnt2[u] - (int)a.count(mp(v, u)));
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\\n';
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, w, m, i, ht, wt, hmax = 0, wmax = 0, hcnt = 0, wcnt = 0, bcnt = 0;
  cin >> h >> w >> m;
  vector<int> bh(h);
  vector<int> bw(w);
  vector<pair<int, int>> vp(m);
  for (i = 0; i < m; ++i) {
    cin >> ht >> wt;
    --ht;
    --wt;
    ++bh.at(ht);
    ++bw.at(wt);
    hmax = max(hmax, bh.at(ht));
    wmax = max(wmax, bw.at(wt));
    vp.at(i) = make_pair(ht, wt);
  }
  for (i = 0; i < h; ++i)
    if (bh.at(i) == hmax)
      ++hcnt;
  for (i = 0; i < w; ++i)
    if (bw.at(i) == wmax)
      ++wcnt;
  for (i = 0; i < m; ++i) {
    ht = vp.at(i).first;
    wt = vp.at(i).second;
    if (bh.at(ht) == hmax && bw.at(wt) == wmax)
      ++bcnt;
  }
  if (hcnt * wcnt - bcnt == 0)
    cout << hmax + wmax - 1 << endl;
  else
    cout << hmax + wmax << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll h, w, ht, wt, ih = 0, iw = 0, M, i, maxh = 0, maxw = 0, ans = 0;
  cin >> h >> w >> M;
  vector<ll> bh(h);
  vector<ll> bw(w);
  vector<vector<ll>> m(h, vector<ll>(w));
  for (i = 0; i < M; ++i) {
    cin >> ht >> wt;
    --ht;
    --wt;
    m.at(ht).at(wt) = 1;
    ++bh.at(ht);
    ++bw.at(wt);
    if (bh.at(ht) >= maxh) {
      ih = ht;
      maxh = bh.at(ht);
    }
    if (bw.at(wt) >= maxw) {
      iw = wt;
      maxw = bw.at(wt);
    }
  }
  if (maxh >= maxw) {
    ans += maxh;
    if (m.at(ih).at(iw) == 0) {
      ans += maxw;
    } else {
      ans += maxw - 1;
      for (i = 0; i < w; ++i) {
        if (m.at(ih).at(i) == 0 && bw.at(i) == maxw) {
          ans += 1;
          break;
        }
      }
    }
  } else {
    ans += maxw;
    if (m.at(ih).at(iw) == 0) {
      ans += maxh;
    } else {
      ans += maxh - 1;
      for (i = 0; i < h; ++i) {
        if (m.at(i).at(iw) == 0 && bh.at(i) == maxh) {
          ans += 1;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1ll << 60;

#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) ;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h(M), w(M);
  REP(i, M) cin >> h[i] >> w[i];

  set<P> is;
  REP(i, M)
  is.insert(P{h[i], w[i]});

  map<ll, ll> tate;
  map<ll, ll> yoko;
  REP(i, M)
  tate[h[i]]++;
  REP(i, M)
  yoko[w[i]]++;

  vector<P> tatev;
  vector<P> yokov;
  for (auto &p : tate)
    tatev.push_back(P{p.second, p.first});
  for (auto &p : yoko)
    yokov.push_back(P{p.second, p.first});

  sort(ALL(tatev), greater<P>());
  sort(ALL(yokov), greater<P>());

  ll res{0};

  ll ma = yokov.front().first;
  ll yokoi = yokov.front().second;
  REP(i, (ll)tatev.size()) {
    auto p = tatev[i];
    ll tatei = p.second;
    ll tmp = p.first + ma;
    if (is.count(P{tatei, yokoi}))
      tmp = max(0ll, tmp - 1);
    res = max(res, tmp);
  }

  ma = tatev.front().first;
  ll tatei = tatev.front().second;
  REP(i, (ll)yokov.size()) {
    auto p = yokov[i];
    ll yokoi = p.second;
    ll tmp = p.first + ma;
    if (is.count(P{tatei, yokoi}))
      tmp = max(0ll, tmp - 1);
    res = max(res, tmp);
  }

  std::cout << res << std::endl;
  return 0;
}


Error: TLE

Fixed submission:

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1ll << 60;

#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) ;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h(M), w(M);
  REP(i, M) cin >> h[i] >> w[i];

  set<P> is;
  REP(i, M)
  is.insert(P{h[i], w[i]});

  map<ll, ll> tate;
  map<ll, ll> yoko;
  REP(i, M)
  tate[h[i]]++;
  REP(i, M)
  yoko[w[i]]++;

  vector<P> tatev;
  vector<P> yokov;
  for (auto &p : tate)
    tatev.push_back(P{p.second, p.first});
  for (auto &p : yoko)
    yokov.push_back(P{p.second, p.first});

  sort(ALL(tatev), greater<P>());
  sort(ALL(yokov), greater<P>());

  ll res{0};

  REP(i, (ll)tatev.size()) REP(j, (ll)yokov.size()) {
    auto p1 = tatev[i];
    auto p2 = yokov[j];
    ll tmp = p1.first + p2.first;

    if (is.count(P{p1.second, p2.second}))
      tmp = max(0ll, tmp - 1);
    res = max(res, tmp);
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> using v2 = vector<vector<T>>;
template <typename T> inline v2<T> fill(int r, int c, const T &t) {
  return v2<T>(r, vector<T>(c, t));
}
#define F first
#define S second

void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<pair<int, int>> t(m);
  for (int i = 0; i < m; ++i) {
    cin >> t[i].F >> t[i].S;
    --t[i].F, --t[i].S;
  }

  vector<int> rowc(h, 0), colc(w, 0);
  for (int i = 0; i < m; ++i) {
    ++rowc[t[i].F], ++colc[t[i].S];
  }

  int ans = 0;
  for (int i = 0; i < m; ++i) {
    ans = max(ans, rowc[t[i].F] + colc[t[i].S] - 1);
  }

  map<int, vector<int>> rowmap;
  for (int i = 0; i < m; ++i)
    rowmap[t[i].F].push_back(t[i].S);

  // multiset<int> colset;
  map<int, int> colset;
  for (int i = 0; i < w; ++i)
    ++colset[colc[i]];

  for (auto &p : rowmap) {
    // cout << p.F+1 << ": ";
    for (int col : p.S) {
      // cout << col+1 << ' ';
      // colset.erase(colset.find(colc[col]));
      --colset[colc[col]];
      if (colset[colc[col]] == 0)
        colset.erase(colset.find(colc[col]));
    }
    // cout << '\\n';

    if (colset.empty())
      continue;
    ans = max(ans, rowc[p.F] + (--colset.end())->F);

    for (int col : p.S) {
      ++colset[colc[col]];
    }
  }

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> using v2 = vector<vector<T>>;
template <typename T> inline v2<T> fill(int r, int c, const T &t) {
  return v2<T>(r, vector<T>(c, t));
}
#define F first
#define S second

void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<pair<int, int>> t(m);
  for (int i = 0; i < m; ++i) {
    cin >> t[i].F >> t[i].S;
    --t[i].F, --t[i].S;
  }

  vector<int> rowc(h, 0), colc(w, 0);
  for (int i = 0; i < m; ++i) {
    ++rowc[t[i].F], ++colc[t[i].S];
  }

  int ans = 0;
  for (int i = 0; i < m; ++i) {
    ans = max(ans, rowc[t[i].F] + colc[t[i].S] - 1);
  }

  map<int, vector<int>> rowmap;
  for (int i = 0; i < m; ++i)
    rowmap[t[i].F].push_back(t[i].S);

  multiset<int> colset;
  for (int i = 0; i < w; ++i)
    colset.insert(colc[i]);

  for (auto &p : rowmap) {
    // cout << p.F+1 << ": ";
    for (int col : p.S) {
      // cout << col+1 << ' ';
      colset.erase(colset.find(colc[col]));
    }
    // cout << '\\n';

    if (colset.empty())
      continue;
    ans = max(ans, rowc[p.F] + *(--colset.end()));

    for (int col : p.S) {
      colset.insert(colc[col]);
    }
  }

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

constexpr int MAXN = 5 + 3e5;

int c1[MAXN], c2[MAXN], curr[MAXN];
vector<int> r[MAXN];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int h, w, m;
  cin >> h >> w >> m;
  set<ii> cell;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    ++c1[x];
    ++c2[y];
    r[x].push_back(y);
  }

  int ans = 1;
  multiset<int> s;

  for (int i = 1; i <= w; ++i) {
    curr[i] = c2[i];
    s.insert(curr[i]);
  }

  for (int i = 1; i <= h; ++i) {
    for (auto p : r[i]) {
      s.erase(s.find(curr[p]));
      curr[p] = c2[p] - 1;
      s.insert(curr[p]);
    }

    ans = max(ans, c1[i] + *s.rbegin());

    for (auto p : r[i]) {
      s.erase(s.find(curr[p]));
      curr[p] = c2[p];
      s.insert(curr[p]);
    }
  }

  cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

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

constexpr int MAXN = 5 + 3e5;

int c1[MAXN], c2[MAXN];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int h, w, m, maxix = 0;
  cin >> h >> w >> m;
  set<ii> s;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    s.insert({x, y});
    ++c1[x];
    ++c2[y];
    maxix = max(maxix, c1[x]);
  }

  int ans = 1;
  for (int i = 1; i <= h; ++i) {
    if (c1[i] == maxix) {
      for (int j = 1; j <= w; ++j) {
        ans = max(ans, c1[i] + c2[j] - (int)s.count({i, j}));
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

ll maxlist(vector<ll> &maxindices, vector<ll> &counts) {
  ll maxval = -1;
  for (ll i = 0; i < (ll)counts.size(); i++) {
    if (maxval == counts[i]) {
      maxindices.push_back(i);
    } else if (maxval < counts[i]) {
      maxval = counts[i];
      maxindices.clear();
      maxindices.push_back(i);
    }
  }
  return maxval;
}

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> hcount(H, 0);
  vector<ll> wcount(W, 0);

  unordered_set<ll> exist;
  for (ll i = 0; i < M; i++) {
    ll h, w;
    cin >> h >> w;
    h--;
    w--;
    hcount[h]++;
    wcount[w]++;
    exist.insert(h * 1000000LL + w);
  }
  vector<ll> max_hi;
  ll max_h = maxlist(max_hi, hcount);
  vector<ll> max_wi;
  ll max_w = maxlist(max_wi, wcount);

  for (auto hi : max_hi) {
    for (auto wi : max_wi) {
      if (!exist.count(hi * 1000000LL + wi)) {
        cout << max_h + max_w << endl;
        return 0;
      }
    }
  }
  cout << max_h + max_w - 1 << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

ll maxlist(vector<ll> &maxindices, vector<ll> &counts) {
  ll maxval = -1;
  for (ll i = 0; i < (ll)counts.size(); i++) {
    if (maxval == counts[i]) {
      maxindices.push_back(i);
    } else if (maxval < counts[i]) {
      maxval = counts[i];
      maxindices.clear();
      maxindices.push_back(i);
    }
  }
  return maxval;
}

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> hcount(H, 0);
  vector<ll> wcount(W, 0);

  vector<vector<bool>> exist(H, vector<bool>(W, false));
  for (ll i = 0; i < M; i++) {
    ll h, w;
    cin >> h >> w;
    h--;
    w--;
    hcount[h]++;
    wcount[w]++;
    exist[h][w] = true;
  }
  vector<ll> max_hi;
  ll max_h = maxlist(max_hi, hcount);
  vector<ll> max_wi;
  ll max_w = maxlist(max_wi, wcount);

  for (auto hi : max_hi) {
    for (auto wi : max_wi) {
      if (!exist[hi][wi]) {
        cout << max_h + max_w << endl;
        return 0;
      }
    }
  }
  cout << max_h + max_w - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int *x = new int[h];
  int *y = new int[w];
  for (int i = 0; i < h; i++)
    x[i] = 0;
  for (int i = 0; i < w; i++)
    y[i] = 0;
  map<pair<int, int>, int> p;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    x[a - 1]++;
    y[b - 1]++;
    p[pair<int, int>(a - 1, b - 1)]++;
  }
  int ans = 0;
  int mx = -1, xv = 0;
  for (int i = 0; i < h; i++) {
    if (xv < x[i]) {
      mx = i;
      xv = x[i];
    }
  }
  for (int i = 0; i < w; i++) {
    ans = max(ans, x[mx] + y[i] - p[pair<int, int>(mx, i)]);
  }
  int my = -1, yv = 0;
  for (int i = 0; i < w; i++) {
    if (yv < y[i]) {
      my = i;
      yv = y[i];
    }
  }
  for (int i = 0; i < h; i++) {
    ans = max(ans, x[i] + y[my] - p[pair<int, int>(i, my)]);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int pos(int x, int y, int h, int w) { return x * w + y; }
int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> x;
  map<int, int> y;
  int **c = new int *[h];
  for (int i = 0; i < h; i++) {
    c[i] = new int[w];
    for (int j = 0; j < w; j++) {
      c[i][j] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    x[a - 1]++;
    y[b - 1]++;
    c[a - 1][b - 1]++;
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, x[i] + y[j] - c[i][j]);
    }
  }
  cout << ans << endl;
}