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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  map<pair<ll, ll>, ll> g;
  vector<ll> sx(h), sy(w);
  set<ll> gx, gy;
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    g[{x, y}] = 1;
    sx[x]++;
    sy[y]++;
  }
  ll mh = 0, mw = 0;
  rep(i, h) mh = max(mh, sx[i]);
  rep(i, w) mw = max(mw, sy[i]);
  vector<ll> vx, vy;
  rep(i, h) if (mh == sx[i]) vx.push_back(i);
  rep(i, w) if (mw == sy[i]) vy.push_back(i);
  ll res = mh + mw;
  for (auto x : vx) {
    for (auto y : vy) {
      if (g.count({x, y}))
        continue;
      cout << res << endl;
      return 0;
    }
  }
  cout << res - 1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  map<pair<ll, ll>, ll> g;
  vector<ll> sx(h), sy(w);
  set<ll> gx, gy;
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    g[{x, y}] = 1;
    sx[x]++;
    sy[y]++;
  }
  ll mh = 0, mw = 0;
  rep(i, h) mh = max(mh, sx[i]);
  rep(i, w) mw = max(mw, sy[i]);
  set<ll> vx, vy;
  rep(i, h) if (mh == sx[i]) vx.insert(i);
  rep(i, w) if (mw == sy[i]) vy.insert(i);
  ll res = 0;
  for (auto x : vx) {
    for (auto y : vy) {
      if (g.count({x, y}))
        res = max(res, mh + mw - 1);
      else
        res = max(res, mh + mw);
    }
  }
  cout << res << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> hc(h, 0), wc(w, 0);
  map<pair<ll, ll>, ll> mp;
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    hc[x] += 1;
    wc[y] += 1;
    mp[{x, y}] = 1;
  }
  ll hm = MAX(hc), wm = MAX(wc);
  set<ll> ht, wt;
  rep(i, h) if (hm == hc[i]) ht.insert(i);
  rep(i, w) if (wm == wc[i]) wt.insert(i);
  ll res = hm + wm - 1;
  for (auto x : ht) {
    for (auto y : wt) {
      if (mp[{x, y}])
        continue;
      cout << res + 1 << endl;
      return 0;
    }
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> hc(h, 0), wc(w, 0);
  map<pair<ll, ll>, ll> mp;
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    hc[x] += 1;
    wc[y] += 1;
    mp[{x, y}] = 1;
  }
  ll hm = MAX(hc), wm = MAX(wc);
  set<ll> ht, wt;
  rep(i, h) if (hm == hc[i]) ht.insert(i);
  rep(i, w) if (wm == wc[i]) wt.insert(i);
  ll res = hm + wm - 1;
  for (auto x : ht) {
    for (auto y : wt) {
      if (mp[{x, y}])
        continue;
      res = hm + wm;
    }
  }
  cout << res << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define END '\\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int inf = 2e18;
const int mod1 = 998244353;
const int mod = 1e9 + 7;
const int nax = 300005;
int r[nax], c[nax], m, h, w;
set<pii> targets;
void solve() {
  cin >> h >> w >> m;
  loop(i, 0, m) {
    int y, x;
    cin >> y >> x;
    r[y]++;
    c[x]++;
    targets.insert({y, x});
  }
  int idy = max_element(r, r + nax) - r;
  int idx = max_element(c, c + nax) - c;
  int ans = 0;
  loop(i, 1, nax) {
    int res1 = r[i] + c[idx] - targets.count({i, idx});
    int res2 = r[idy] + c[i] - targets.count({idy, i});
    ans = max({ans, res1, res2});
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  /*int t;
  cin>>t;
  while(t--)*/
  solve();
  // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define END '\\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int inf = 2e18;
const int mod1 = 998244353;
const int mod = 1e9 + 7;
const int nax = 300005;
int r[nax], c[nax], m, h, w;
set<pii> targets;
void solve() {
  cin >> h >> w >> m;
  loop(i, 0, m) {
    int y, x;
    cin >> y >> x;
    r[y]++;
    c[x]++;
    targets.insert({y, x});
  }
  int ans = 0;
  loop(i, 1, h + 1) loop(j, 1, w + 1) {
    int a = targets.count({i, j});
    ans = max(ans, r[i] + c[j] - a);
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  /*int t;
  cin>>t;
  while(t--)*/
  solve();
  // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long row[300003], col[300003], mp[300003];

vector<long long> adj[300003];

int main() {

  long long n, m, a, b, c, d, e, f, g, h, p, q, r, fr, sc, tr, sz,
      tz = 0, i, j, k, mx = LLONG_MIN, mn = LLONG_MAX;
  long long x = 0, y = 0, cnt = 0, res = 0, ttl = 0, ans, sum = 0;
  long long flg = 0, flag = 1, na = 0, as = 1;
  vector<long long> u, v, w;
  vector<pair<long long, long long>> vct;
  vector<string> vst;
  set<long long> st, nt, tt;
  string str, ttr, ntr;

  ans = mx;

  scanf("%lld %lld %lld", &n, &m, &p);

  for (i = 1; i <= p; i++) {
    scanf("%lld %lld", &a, &b);
    adj[a].push_back(b);
    row[a]++;
    col[b]++;

    st.insert(b);
    tt.insert(a);
  }

  set<long long>::iterator it;
  tz = st.size();

  for (it = st.begin(); it != st.end(); it++) {
    b = *it;
    vct.push_back(make_pair(col[b], b));
  }

  sort(vct.begin(), vct.end());

  for (j = tz - 1; j >= 0; j--) {
    a = vct[j].first;
    b = vct[j].second;
    if (a > mx)
      mx = a;

    if (j != tz - 1) {
      if (a < q)
        break;
    }

    mp[b] = 7;
    cnt++;

    q = a;
  }

  for (it = tt.begin(); it != tt.end(); it++) {

    a = *it;

    b = row[a];
    ttl = 0;
    x = 1;
    sz = adj[a].size();

    for (j = 0; j < sz; j++) {
      c = adj[a][j];
      if (mp[c] == 7) {
        flg = 0;
        ttl++;
      }
    }

    if (cnt > ttl)
      x = 0;

    fr = b + mx - x;

    if (fr > ans)
      ans = fr;
  }

  printf("%lld\\n", ans);

  return 0;
}


Error: TLE

Fixed submission:

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

long long row[300003], col[300003], mp[300003];

vector<long long> adj[300003];

int main() {

  long long n, m, a, b, c, d, e, f, g, h, p, q, r, fr, sc, tr, sz, tz, i, j, k,
      mx = LLONG_MIN, mn = LLONG_MAX;
  long long x = 0, y = 0, cnt = 0, res = 0, ttl = 0, ans, sum = 0;
  long long flg = 0, flag = 1, na = 0, as = 1;
  vector<long long> u, v, w;
  vector<pair<long long, long long>> vct;
  vector<string> vst;
  set<long long> st, nt, tt;
  string str, ttr, ntr;

  ans = mx;

  scanf("%lld %lld %lld", &n, &m, &p);

  for (i = 1; i <= p; i++) {
    scanf("%lld %lld", &a, &b);
    adj[a].push_back(b);
    row[a]++;
    col[b]++;

    v.push_back(a);
  }

  for (j = 1; j <= m; j++) {
    vct.push_back(make_pair(col[j], j));
  }

  sort(vct.begin(), vct.end());

  for (j = m - 1; j >= 0; j--) {
    a = vct[j].first;
    b = vct[j].second;
    if (a > mx)
      mx = a;

    if (j != m - 1) {
      if (a < q)
        break;
    }

    mp[b] = 7;
    cnt++;

    q = a;
  }

  for (i = 0; i < p; i++) {

    a = v[i];
    b = row[a];
    ttl = 0;
    x = 1;

    sz = adj[a].size();

    for (j = 0; j < sz; j++) {
      c = adj[a][j];
      if (mp[c] == 7) {
        flg = 0;
        ttl++;
      }
    }

    if (cnt > ttl)
      x = 0;

    fr = b + mx - x;

    if (fr > ans)
      ans = fr;
  }

  printf("%lld\\n", ans);

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

/*** akshaykumar99 ***/

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

const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long N = 5e2 + 1;

#define ll int
// typedef long long ll;
typedef long double ld;

void test_case() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<ll, ll>> v;
  vector<ll> tot(h + 1, 0);
  for (int i = 0; i < m; i++) {
    ll hh, ww;
    cin >> hh >> ww;
    v.push_back({hh, ww});
    tot[hh]++;
  }
  ll mx = 0, ind = 0;
  for (int i = 1; i <= h; i++) {
    if (mx < tot[i]) {
      mx = tot[i];
      ind = i;
    }
  }
  tot.assign(w + 1, 0);
  for (auto u : v) {
    if (u.first != ind) {
      tot[u.second]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= w; i++) {
    ans = max(ans, mx + tot[i]);
  }
  tot.assign(w + 1, 0);
  for (auto u : v)
    tot[u.second]++;
  mx = 0;
  for (int i = 1; i <= w; i++) {
    if (mx < tot[i]) {
      mx = tot[i];
      ind = i;
    }
  }
  tot.assign(h + 1, 0);
  for (auto u : v) {
    if (u.second != ind) {
      tot[u.first]++;
    }
  }
  for (int i = 1; i <= h; i++) {
    ans = max(ans, mx + tot[i]);
  }
  cout << ans << '\\n';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll tc = 1;
  // cin>>tc;
  while (tc--)
    test_case();
  return 0;
}

Error: TLE

Fixed submission:

/*** akshaykumar99 ***/

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

const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long N = 5e2 + 1;

typedef long long ll;
typedef long double ld;

void test_case() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<ll, ll>> v;
  vector<ll> tot(h + 1, 0);
  for (int i = 0; i < m; i++) {
    ll hh, ww;
    cin >> hh >> ww;
    v.push_back({hh, ww});
    tot[hh]++;
  }
  ll mx = 0, ind = 0;
  vector<ll> vv;
  for (int i = 1; i <= h; i++) {
    mx = max(mx, tot[i]);
  }
  for (int i = 1; i <= h; i++) {
    if (tot[i] == mx)
      vv.push_back(i);
  }
  ll ans = 0;
  for (auto uu : vv) {
    tot.assign(w + 1, 0);
    for (auto u : v) {
      if (u.first != uu) {
        tot[u.second]++;
      }
    }
    ll mx1 = 0;
    for (int i = 1; i <= w; i++) {
      mx1 = max(mx1, tot[i]);
    }
    ans = max(ans, mx1 + mx);
  }
  cout << ans << '\\n';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll tc = 1;
  // cin>>tc;
  while (tc--)
    test_case();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int ans, h, w, m;
  cin >> h >> w >> m;
  int a, b;
  // vector<int>r(h,0),c(w,0);
  // vector<vector<bool>>v(h,vector<bool>(w,0));
  vector<pair<int, int>> bomb(m);
  vector<int> p1(h, 0), p2(w, 0);
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    p1[a]++;
    p2[b]++;
    bomb[i] = make_pair(a, b);
  }
  ll cr = 0, cc = 0;
  int maxR, maxC;
  maxR = p1[0];
  rep(i, h) maxR = max(maxR, p1[i]);
  rep(i, h) {
    if (maxR == p1[i]) {
      cr++;
    }
  }
  maxC = p2[0];
  rep(i, w) maxC = max(maxC, p2[i]);
  rep(i, w) {
    if (maxC == p2[i]) {
      cc++;
    }
  }
  int cb = 0;
  rep(i, m) {
    if (p1[bomb[i].first] == maxR && p2[bomb[i].second] == maxC) {
      cb++;
    }
  }
  if (cr * cc > cb) {
    ans = maxC + maxR;
  } else {
    ans = maxC + maxR - 1;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int ans, h, w, m;
  cin >> h >> w >> m;
  int a, b;
  // vector<int>r(h,0),c(w,0);
  vector<vector<bool>> v(h, vector<bool>(w, 0));
  vector<pair<int, int>> p1(h), p2(w);
  rep(i, h) p1[i] = make_pair(0, i);
  rep(i, w) p2[i] = make_pair(0, i);
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    p1[a].first++;
    p2[b].first++;
    v[a][b] = 1;
  }
  sort(p1.begin(), p1.end(), greater<pair<int, int>>());
  sort(p2.begin(), p2.end(), greater<pair<int, int>>());
  int cr = 1, cc = 1;
  for (int i = 1; i < h; i++) {
    if (p1[i].first == p1[i - 1].first) {
      cr++;
    } else {
      break;
    }
  }
  for (int i = 1; i < w; i++) {
    if (p2[i].first == p2[i - 1].first) {
      cc++;
    } else {
      break;
    }
  }
  ans = p1[0].first + p2[0].first - 1;
  bool f = 0;
  rep(i, cr) {
    if (f) {
      break;
    }
    rep(j, cc) {
      if (v[p1[i].second][p2[j].second] == 0) {
        ans++;
        f = 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  vector<int> rowbombs(h), columnbombs(w);
  set<pair<int, int>> monsexist;

  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--, wi--;

    rowbombs[hi]++;
    columnbombs[wi]++;
    monsexist.insert({hi, wi});
  }

  int ans = 0;

  const int maxrowbombs = *max_element(rowbombs.begin(), rowbombs.end());
  const int maxcolumnbombs =
      *max_element(columnbombs.begin(), columnbombs.end());

  vector<int> rr, cc;
  rr.reserve(m);
  cc.reserve(m);

  for (int i = 0; i < h; i++) {
    if (rowbombs[i] == maxrowbombs)
      rr.emplace_back(i);
  }
  for (int i = 0; i < w; i++) {
    if (columnbombs[i] == maxcolumnbombs)
      cc.emplace_back(i);
  }

  bool cross = true;

  for (auto &&i : rr) {
    for (auto &&j : cc) {
      if (monsexist.count({i, j}) == 0) {
        cross = false;
      }

      if (!cross)
        break;
    }
    if (!cross)
      break;
  }

  ans = maxrowbombs + maxcolumnbombs;
  if (cross)
    ans--;

  cout << ans << endl;
}


Error: TLE

Fixed submission:

// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  vector<int> rowbombs(h), columnbombs(w);
  map<pair<int, int>, int> monsexist;

  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--, wi--;

    rowbombs[hi]++;
    columnbombs[wi]++;
    monsexist[{hi, wi}]++;
  }

  int ans = 0;

  const int maxrowbombs = *max_element(rowbombs.begin(), rowbombs.end());
  const int maxcolumnbombs =
      *max_element(columnbombs.begin(), columnbombs.end());

  vector<int> rr, cc;
  rr.reserve(m);
  cc.reserve(m);

  for (int i = 0; i < h; i++) {
    if (rowbombs[i] == maxrowbombs)
      rr.emplace_back(i);
  }
  for (int i = 0; i < w; i++) {
    if (columnbombs[i] == maxcolumnbombs)
      cc.emplace_back(i);
  }

  for (auto &&i : rr) {
    for (auto &&j : cc) {
      ans = max(maxrowbombs + maxcolumnbombs - monsexist[{i, j}], ans);
    }
  }

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

#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() {
  int h, w, m;
  cin >> h >> w >> m;
  set<P> s;
  vector<int> c1(h), c2(w);
  rep(mi, m) {
    int i, j;
    cin >> i >> j;
    --i, --j;
    ++c1[i], ++c2[j];
    s.insert({i, j});
  }

  ll ans = 0;
  int mx1 = 0, mx2 = 0;
  rep(i, h) mx1 = max(mx1, c1[i]);
  rep(i, w) mx2 = max(mx2, c2[i]);

  int cnt1 = 0;
  rep(i, h) cnt1 += (c1[i] == mx1);
  int cnt2 = 0;
  rep(i, w) cnt2 += (c2[i] == mx2);

  ll e = (ll)cnt1 * cnt2;
  for (auto p : s) {
    if (c1[p.first] == mx1 && c2[p.second] == mx2)
      --e;
  }

  ans = (ll)mx1 + mx2;
  if (e == 0)
    --ans;
  cout << ans << endl;
  return 0;
}


Error: TLE

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() {
  int h, w, m;
  cin >> h >> w >> m;
  set<P> s;
  vector<int> c1(h), c2(w);
  rep(mi, m) {
    int i, j;
    cin >> i >> j;
    --i, --j;
    ++c1[i], ++c2[j];
    s.insert({i, j});
  }

  ll ans = 0;
  rep(i, h) {
    rep(j, w) {
      ll now = (ll)c1[i] + c2[j];
      if (s.find({i, j}) != s.end())
        --now;
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9 + 7;
const ll LLINF = 1e18;
using namespace std;

ll llmin(ll x, ll y) {
  if (x < y)
    return x;
  return y;
}

ll llmax(ll x, ll y) {
  if (x > y)
    return x;
  return y;
}

map<pair<int, int>, int> mp;
vector<pair<int, int>> xb(350000);
vector<pair<int, int>> yb(350000);

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  if (h == 1 || w == 1) {
    cout << m << endl;
    return 0;
  }

  for (int i = 0; i <= h; i++) {
    xb[i] = make_pair(0, i);
  }
  for (int i = 0; i <= w; i++) {
    yb[i] = make_pair(0, i);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    xb[x].first++;
    yb[y].first++;
    mp[make_pair(x, y)]++;
  }
  sort(xb.begin(), xb.begin() + h + 1, greater<pair<int, int>>());
  sort(yb.begin(), yb.begin() + w + 1, greater<pair<int, int>>());

  ll xx = 1, yy = 1;
  for (int i = 1; i <= h; i++) {
    if (xb[0].first == xb[i].first)
      xx++;
  }
  for (int i = 1; i <= h; i++) {
    if (yb[0].first == yb[i].first)
      yy++;
  }

  ll prod = xx * yy;

  if (prod > m) {
    cout << xb[0].first + yb[0].first << endl;
    return 0;
  } else {
    for (int i = 0; i < xx; i++) {
      for (int j = 0; j < yy; j++) {
        if (!mp[make_pair(xb[i].second, yb[j].second)]) {
          cout << xb[0].first + yb[0].first << endl;
          return 0;
        }
      }
    }
  }
  cout << xb[0].first + yb[0].first - 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9 + 7;
const ll LLINF = 1e18;
using namespace std;

ll llmin(ll x, ll y) {
  if (x < y)
    return x;
  return y;
}

ll llmax(ll x, ll y) {
  if (x > y)
    return x;
  return y;
}

bool bomb[700000];
vector<pair<int, int>> xb(350000);
vector<pair<int, int>> yb(350000);

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  if (h == 1 || w == 1) {
    cout << m << endl;
    return 0;
  }

  for (int i = 0; i <= h; i++) {
    xb[i] = make_pair(0, i);
  }
  for (int i = 0; i <= w; i++) {
    yb[i] = make_pair(0, i);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    xb[x].first++;
    yb[y].first++;
    bomb[(x - 1) * w + y] = true;
  }
  sort(xb.begin(), xb.begin() + h + 1, greater<pair<int, int>>());
  sort(yb.begin(), yb.begin() + w + 1, greater<pair<int, int>>());

  int ans = 0;
  for (int i = 0; i < min(50, h); i++) {
    for (int j = 0; j < min(50, w); j++) {
      if (xb[i].second != 0) {
        if (bomb[(xb[i].second - 1) * w + yb[j].second])
          ans = max(ans, xb[i].first + yb[j].first - 1);
        else
          ans = max(ans, xb[i].first + yb[j].first);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<ll, ll>> bombs(m);
  vector<ll> h_count(h), w_count(w);
  for (ll i = 0; i < m; i++) {
    ll hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    bombs[i] = {hi, wi};
    h_count[hi]++;
    w_count[wi]++;
  }
  vector<ll> h_orig = h_count, w_orig = w_count;
  sort(h_count.begin(), h_count.end());
  sort(w_count.begin(), w_count.end());
  ll h_max = h_count[(ll)h_count.size() - 1];
  ll w_max = w_count[(ll)w_count.size() - 1];
  ll h_len = h_count.end() - lower_bound(h_count.begin(), h_count.end(), h_max);
  ll w_len = w_count.end() - lower_bound(w_count.begin(), w_count.end(), w_max);
  ll c = 0;
  for (ll i = 0; i < m; i++) {
    auto p = bombs[i];
    if (h_orig[p.first] + w_orig[p.second] == h_max + w_max)
      c++;
  }
  if (c < h_len * w_len)
    cout << h_max + w_max;
  else
    cout << h_max + w_max - 1;
  return 0;
}

Error: WA

Fixed submission:

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

typedef long long ll;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<vector<bool>> is_bomb(h, vector<bool>(w));
  vector<pair<int, int>> bombs(m);
  vector<int> h_count(h), w_count(w);
  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    bombs[i] = {hi, wi};
    h_count[hi]++;
    w_count[wi]++;
  }
  vector<int> h_orig = h_count, w_orig = w_count;
  sort(h_count.begin(), h_count.end());
  sort(w_count.begin(), w_count.end());
  int h_max = h_count[h_count.size() - 1];
  int w_max = w_count[w_count.size() - 1];
  int h_len =
      h_count.end() - lower_bound(h_count.begin(), h_count.end(), h_max);
  int w_len =
      w_count.end() - lower_bound(w_count.begin(), w_count.end(), w_max);
  int c = 0;
  for (int i = 0; i < m; i++) {
    auto p = bombs[i];
    if (h_orig[p.first] + w_orig[p.second] == h_max + w_max - 1) {
      c++;
    }
  }
  if (c < h_len * w_len) {
    cout << h_max + w_max;
  } else {
    cout << h_max + w_max - 1;
  }
  return 0;
}