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

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll INF = 1e15 + 4;
const int Nmax = 2e5 + 1;
const int Nd = 61;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  ll th, tw;
  vector<ll> nh(h, 0), nw(w, 0);
  vector<pair<ll, ll>> b(m);
  ll maxh = 0, maxw = 0;
  ll n_maxh = 0, n_maxw = 0;
  rep(i, m) {
    cin >> th;
    cin >> tw;
    th--;
    tw--;
    b[i].first = th;
    b[i].second = tw;
    nh[th]++;
    nw[tw]++;

    if (maxh < nh[th])
      n_maxh = 1;
    if (maxw < nw[tw])
      n_maxw = 1;
    if (maxh == nh[th])
      n_maxh++;
    if (maxw == nw[tw])
      n_maxw++;
    maxh = max(maxh, nh[th]);
    maxw = max(maxw, nw[tw]);
  }
  ll count_b = 0;
  rep(i, m) {
    if (nh[b[i].first] + nw[b[i].second] == maxh + maxw) {
      count_b++;
    }
  }

  ll count_tot = n_maxh * n_maxw;

  if (count_b < count_tot ||
      count_tot > 300001) { // bomb位置以外の最大値をとる箇所がある．
    cout << maxh + maxw << endl;
  } else {
    cout << maxh + maxw - 1 << endl;
  }

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll INF = 1e15 + 4;
const int Nmax = 2e5 + 1;
const int Nd = 61;
ll dfs[3003][3003][4];
ll s[1003][1003];
vector<int> di = {1, -1, 0, 0};
vector<int> dj = {0, 0, 1, -1};

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int th, tw;
  vector<int> nh(h, 0), nw(w, 0);
  vector<P> b(m);
  vector<vector<bool>> pt(h, vector<bool>(w, false));
  int maxh = 0, maxw = 0;
  int now, ans;
  ans = 0;
  rep(i, m) {
    cin >> th;
    cin >> tw;
    th--;
    tw--;
    b[i].first = th;
    b[i].second = tw;
    nh[th]++;
    nw[tw]++;
    pt[th][tw] = true;
    maxh = max(maxh, nh[th]);
    maxw = max(maxw, nw[tw]);
  }
  int n_maxh = 0, n_maxw = 0;

  rep(i, h) {
    if (nh[i] == maxh)
      n_maxh++;
  }
  rep(i, w) {
    if (nw[i] == maxw)
      n_maxw++;
  }

  int count_b = 0;
  rep(i, m) {
    if (nh[b[i].first] + nw[b[i].second] == maxh + maxw) {
      count_b++;
    }
  }

  if (count_b < n_maxh * n_maxw) {
    cout << maxh + maxw << endl;
  } else {
    cout << maxh + maxw - 1 << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, n) for (long long int i = a; i < n; i++)
#define loop(i, a, n) for (long long int i = a; i >= n; i--)

int main() {
  ios_base ::sync_with_stdio(false), cin.tie(NULL);

  int a, b, c, ans = -1;
  cin >> a >> b >> c;
  int x[c], y[c], m2x = -1, m1x = -1;
  map<int, int> m2, m1;
  map<pair<int, int>, int> m;
  forr(i, 0, c) {
    cin >> x[i] >> y[i];
    m[{x[i], y[i]}]++;
    m1[x[i]]++;
    m2[y[i]]++;
    m2x = max(m2x, m2[y[i]]);
    m1x = max(m1x, m1[x[i]]);
  }
  vector<int> v, w;
  for (auto const x : m1) {
    if (x.second == m1x)
      v.push_back(x.first);
  }
  for (auto const x : m2) {
    if (x.second == m2x)
      w.push_back(x.first);
  }
  forr(i, 0, v.size()) {
    forr(j, 0, w.size()) {
      int xx = m1[v[i]] + m2[w[j]] - m[{v[i], w[j]}];
      ans = max(ans, xx);
      if (m[{v[i], w[j]}] == 0)
        break;
    }
  }
  cout << ans << '\\n';
  // cout<<m1[5]<<' '<<m2[3]<<' '<<m[{5, 3}]<<' '<<m[{3, 5}];

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, n) for (long long int i = a; i < n; i++)
#define loop(i, a, n) for (long long int i = a; i >= n; i--)

int main() {
  ios_base ::sync_with_stdio(false), cin.tie(NULL);

  int a, b, c, ans = -1;
  cin >> a >> b >> c;
  int x[c], y[c], m2x = -1, m1x = -1;
  map<int, int> m2, m1;
  map<pair<int, int>, int> m;
  forr(i, 0, c) {
    cin >> x[i] >> y[i];
    m[{x[i], y[i]}]++;
    m1[x[i]]++;
    m2[y[i]]++;
    m2x = max(m2x, m2[y[i]]);
    m1x = max(m1x, m1[x[i]]);
  }
  vector<int> v, w;
  for (auto const x : m1) {
    if (x.second == m1x)
      v.push_back(x.first);
  }
  for (auto const x : m2) {
    if (x.second == m2x)
      w.push_back(x.first);
  }
  forr(i, 0, v.size()) {
    forr(j, 0, w.size()) {
      int xx = m1[v[i]] + m2[w[j]] - m[{v[i], w[j]}];
      ans = max(ans, xx);
    }
  }
  cout << ans << '\\n';
  // cout<<m1[5]<<' '<<m2[3]<<' '<<m[{5, 3}]<<' '<<m[{3, 5}];

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

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")

typedef long long int ll;
typedef long double ld;

#define MAX 300005
#define endl endl
#define UPPER 1000000000

ll H, W;
ll C1, C2, D1, D2;
vector<string> vec;
vector<vector<ll>> flg(1000 + 1, vector<ll>(1000 + 1, 0));
vector<vector<ll>> cost(1000 + 1, vector<ll>(1000 + 1, 1e18));
set<pair<ll, pair<ll, ll>>> q;

int main() {

  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll H, W;
  cin >> H >> W;

  vector<ll> vec[H + 1];
  ll m;
  cin >> m;
  unordered_map<ll, ll> col;
  map<ll, ll> mp;
  for (ll i = 0; i < m; ++i) {
    ll a, b;
    cin >> a >> b;
    vec[a].push_back(b);

    col[b]++;
  }

  for (auto it : col) {
    mp[it.second]++;
  }

  ll ans = 0;
  for (ll i = 1; i <= H; i++) {
    for (ll j : vec[i]) {
      mp[col[j]]--;
      if (mp[col[j]] == 0) {
        mp.erase(col[j]);
      }
      col[j]--;
      mp[col[j]]++;
    }
    if (mp.size() != 0)
      ans = max(ans, ll(vec[i].size()) + (*(--mp.end())).first);
    for (ll j : vec[i]) {
      mp[col[j]]--;
      if (mp[col[j]] == 0) {
        mp.erase(col[j]);
      }
      col[j]++;
      mp[col[j]]++;
    }
  }

  cout << ans << endl;
}


Error: WA

Fixed submission:

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")

typedef long long int ll;
typedef long double ld;

#define MAX 300005
#define endl endl
#define UPPER 1000000000

ll dp[1005][1005];
ll H, W;
ll C1, C2, D1, D2;
vector<string> vec;
ll solve(ll i, ll j) {
  if (i == D1 && j == D2)
    return 0;
  if (i < 0 || i >= H || j < 0 || j >= W) {
    return 1e18;
  }

  if (vec[i][j] == '#') {
    return 1e18;
  }
  //~ cout<<i<<" "<<j<<endl;
  //~ ll z;
  //~ cin>>z;

  if (dp[i][j] == -1) {
    ll ans = 1e18;
    dp[i][j] = 1e18;
    for (ll ii = -2; ii <= 2; ii++) {
      for (ll jj = -2; jj <= 2; jj++) {
        if (ii == 0 && jj == 0)
          continue;
        if ((abs(ii) < 2 && jj == 0) || (abs(jj) < 2 && ii == 0)) {
          ans = min(ans, solve(i + ii, j + jj));
        } else {
          ans = min(ans, 1 + solve(i + ii, j + jj));
        }
      }
    }
    dp[i][j] = ans;
    // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
  }
  return dp[i][j];
}

int main() {

  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> H >> W;

  cin >> C1 >> C2;

  cin >> D1 >> D2;
  C1--;
  C2--;
  D1--;
  D2--;

  for (ll i = 0; i < H; i++) {
    string s;
    cin >> s;
    vec.push_back(s);
  }
  memset(dp, -1, sizeof(dp));
  ll val = solve(C1, C2);
  if (val == 1e18) {
    cout << -1 << endl;
  } else {
    cout << val << endl;
  }
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  int mxr = 0, mxc = 0;
  vector<int> row(h), col(w);
  vector<pair<int, int>> v;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    mxr = max(mxr, ++row[x]);
    mxc = max(mxc, ++col[y]);
    v.emplace_back(x, y);
  }
  int inter = 0;
  for (auto [x, y] : v) {
    if (row[x] == mxr and col[y] == mxc)
      ++inter;
  }
  int cnt_mxr = count(row.begin(), row.end(), mxr);
  int cnt_mxc = count(col.begin(), col.end(), mxc);
  cout << (mxr + mxc - (inter == 1ll * cnt_mxr * cnt_mxc)) << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define max(a, b) a > b ? a : b
#define min(a, b) a < b ? a : b
template <class TT> inline void read(TT &xx) {
  xx = 0;
  char cc = getchar();
  bool ff = false;
  while (cc < '0' || cc > '9') {
    if (cc == '-')
      ff = true;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    xx = (xx << 3) + (xx << 1) + cc - '0';
    cc = getchar();
  }
  if (ff)
    xx = -xx;
}
#define PII pair<int, int>
#define N 100105
int n, m, w;
int x, y;
map<PII, bool> mp;
vector<int> cnt1, cnt2;
int row[N], col[N];
int maxr, maxc;

int main() {
  read(n);
  read(m);
  read(w);

  for (int i = 1; i <= w; ++i) {
    read(x);
    read(y);

    mp[{x, y}] = true;

    row[x]++;
    col[y]++;

    maxr = max(maxr, row[x]);
    maxc = max(maxc, col[y]);
  }

  for (int i = 1; i <= n; ++i) {
    if (row[i] == maxr)
      cnt1.push_back(i);
  }
  for (int i = 1; i <= m; ++i) {
    if (col[i] == maxc)
      cnt2.push_back(i);
  }

  for (int i = 0; i < cnt1.size(); ++i) {
    for (int j = 0; j < cnt2.size(); ++j) {
      if (!mp[{cnt1[i], cnt2[j]}]) {
        printf("%d\\n", maxr + maxc);
        return 0;
      }
    }
  }

  printf("%d\\n", maxr + maxc - 1);

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

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

int main() {
  int H, W, m;
  cin >> H >> W >> m;
  map<int, int> tate, yoko;
  set<pair<int, int>> st;
  rep(i, m) {
    int h, w;
    cin >> h >> w;
    yoko[w]++;
    tate[h]++;
    st.insert({h, w});
  }

  int mah = 0, maw = 0;
  for (auto p : tate)
    mah = max(mah, p.second);

  for (auto p : yoko)
    maw = max(maw, p.second);

  set<int> sth;
  for (auto p : tate) {
    if (mah == p.second)
      sth.insert(p.first);
  }

  set<int> stw;
  for (auto p : yoko) {
    if (maw == p.second)
      stw.insert(p.first);
  }

  int ans = mah + maw - 1;
  for (auto h : sth) {
    for (auto w : stw) {
      if (st.find({h, w}) == st.end()) {
        ans = mah + maw;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int H, W, m;
  cin >> H >> W >> m;
  map<int, int> tate, yoko;
  set<pair<int, int>> st;
  rep(i, m) {
    int h, w;
    cin >> h >> w;
    yoko[w]++;
    tate[h]++;
    st.insert({h, w});
  }

  int mah = 0, maw = 0;
  for (auto p : tate)
    mah = max(mah, p.second);

  for (auto p : yoko)
    maw = max(maw, p.second);

  set<int> sth;
  for (auto p : tate) {
    if (mah == p.second)
      sth.insert(p.first);
  }

  set<int> stw;
  for (auto p : yoko) {
    if (maw == p.second)
      stw.insert(p.first);
  }

  int ans = 0;
  for (auto h : sth) {
    for (auto w : stw) {
      if (st.find({h, w}) == st.end())
        ans = mah + maw;
      else
        ans = max(ans, mah + maw - 1);
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
using Grid = vector<vector<char>>;
using vin = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vch = vector<char>;
using pinin = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i, n) for (ll i = 0; i < (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes = "Yes", no = "No";

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  set<pinin> s;
  vin hm(h), wm(w);
  rep(i, m) {
    pinin hw;
    cin >> hw.first >> hw.second;
    hw.first--;
    hw.second--;
    s.insert(hw);
    hm[hw.first]++;
    wm[hw.second]++;
  }
  set<int> hma, wma;
  int hmax = 0, wmax = 0;
  rep(i, h) { hmax = max(hmax, hm[i]); }
  rep(i, w) { wmax = max(wmax, wm[i]); }
  rep(i, h) {
    if (hmax == hm[i])
      hma.insert(i);
  }
  rep(i, w) {
    if (wmax == wm[i])
      wma.insert(i);
  }
  int ans = hmax + wmax - 1;
  bool fin = false;
  for (int x : hma) {
    for (int y : wma) {
      pinin xy;
      xy.first = x;
      xy.second = y;
      if (!s.count(xy)) {
        ans = hmax + wmax;
        break;
        fin = true;
      }
    }
    if (fin)
      break;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
using Grid = vector<vector<char>>;
using vin = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vch = vector<char>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int hm = 0, wm = 0;
  vin hmax(h, 0), wmax(w, 0);
  vin hko;
  Graph hw(h);
  rep(i, m) {
    int hh, ww;
    cin >> hh >> ww;
    hmax[hh - 1]++;
    hw[hh - 1].push_back(ww - 1);
    wmax[ww - 1]++;
  }
  rep(i, h) hm = max(hm, hmax[i]);
  rep(i, h) {
    if (hmax[i] == hm) {
      hko.push_back(i);
    }
  }
  rep(i, w) wm = max(wm, wmax[i]);

  rep(i, w) {
    if (wmax[i] == wm) {
      for (int x : hko) {
        bool ex = true;
        for (int y : hw[x]) {
          if (y == i) {
            ex = false;
          }
        }
        if (ex) {
          cout << wm + hm << endl;
          return 0;
        }
      }
    }
  }
  cout << hm + wm - 1 << endl;
}
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 < (n); ++i)

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int maxr = 0, maxc = 0;
  vector<int> hs(h), ws(w);
  set<P> s;
  rep(i, m) {
    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(i, w) mw = max(mw, ws[i]);
  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;
  return 0;
}

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 < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int maxr = 0, maxc = 0;
  // set<int> rows, cols;
  vector<int> rows, cols;
  int grid[h][w];
  rep(i, h) rep(j, w) grid[i][j] = 0;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    grid[x - 1][y - 1] = 1;
  }
  rep(i, h) {
    int ans = 0;
    rep(j, w) ans += grid[i][j];
    if (ans > maxr) {
      maxr = ans;
      rows.clear();
      rows.push_back(i);
    } else if (ans == maxr) {
      rows.push_back(i);
    }
  }
  rep(j, w) {
    int ans = 0;
    rep(i, h) ans += grid[i][j];
    if (ans > maxc) {
      maxc = ans;
      cols.clear();
      cols.push_back(j);
    } else if (ans == maxc) {
      cols.push_back(j);
    }
  }
  for (int i : rows) {
    for (int j : cols) {
      if (grid[i][j] != 1) {
        cout << maxr + maxc << endl;
        return 0;
      }
    }
  }
  cout << maxr + maxc - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> hs(h), ws(w);
  set<P> s;
  for (int i = 0; i < n; i++) {
    int r, c;
    cin >> r >> c;
    r--;
    c--;
    hs[r]++;
    ws[c]++;
    s.emplace(r, c);
  }
  int mh = 0, mw = 0;
  for (int i = 0; i < h; i++) {
    mh = max(mh, hs[i]);
  }
  for (int i = 0; i < w; i++) {
    mw = max(mw, ws[i]);
  }
  vector<int> is, js;
  for (int i = 0; i < h; i++) {
    if (mh == hs[i]) {
      is.push_back(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if (mw == ws[i]) {
      js.push_back(i);
    }
  }
  int ans = mh + mw;
  for (int i = 0; i < is.size(); i++) {
    for (int j = 0; j < js.size(); j++) {
      if (s.count(P(is[i], js[j]))) {
        continue;
      }
      cout << ans << endl;
      return 0;
    }
  }
  --ans;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> hs(h), ws(w);
  set<P> s;
  for (int i = 0; i < n; i++) {
    int r, c;
    cin >> r >> c;
    r--;
    c--;
    hs[r]++;
    ws[c]++;
    s.emplace(r, c);
  }
  int mh = 0, mw = 0;
  for (int i = 0; i < h; i++) {
    mh = max(mh, hs[i]);
  }
  for (int i = 0; i < w; i++) {
    mw = max(mw, ws[i]);
  }
  vector<int> is, js;
  for (int i = 0; i < h; i++) {
    if (mh == hs[i]) {
      is.push_back(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if (mw == ws[i]) {
      js.push_back(i);
    }
  }
  int ans = mh + mw;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s.count(P(is[i], js[j]))) {
        continue;
      }
      cout << ans << endl;
      return 0;
    }
  }
  --ans;
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>

#define DOLL long double
#define LOLI long long int
using namespace std;

const long C_10PW9 = 1000000000;
const int ULCODE = 32;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> Height(H), Width(W);
  vector<pair<int, int>> BOM;
  for (int i = 0; i < M; i++) {
    int hi, wi;
    cin >> hi >> wi;
    Height[hi - 1]++;
    Width[wi - 1]++;
    BOM.push_back(make_pair<int, int>(hi - 1, wi - 1));
  }
  auto Hbeg = Height.begin();
  auto hinx = distance(Hbeg, max_element(Hbeg, Height.end()));
  auto Wbeg = Width.begin();
  auto winx = distance(Wbeg, max_element(Wbeg, Width.end()));
  int HM = Height[hinx], WM = Width[winx];
  LOLI HC = 0, WC = 0;
  for (int i = 0; i < H; i++) {
    if (Height[i] == HM) {
      HC++;
    }
  }
  for (int i = 0; i < W; i++) {
    if (Width[i] == WM) {
      WC++;
    }
  }
  LOLI HWC = HC * WC;
  for (int i = 0; i < M; i++) {
    int h = BOM[i].first, w = BOM[i].second;
    if (Height[h] == HM && Width[w] == WM) {
      HWC--;
    }
  }
  int vec = 0;
  if (HWC <= 0) {
    vec = -1;
  }
  cout << HM + WM + vec << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>

#define DOLL long double
using namespace std;

const long C_10PW9 = 1000000000;
const int ULCODE = 32;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> Height(H);
  vector<int> Width(W);
  vector<vector<int>> HFF(H, vector<int>());
  for (int i = 0; i < M; i++) {
    int hi, wi;
    cin >> hi >> wi;
    Height[hi - 1]++;
    Width[wi - 1]++;
    HFF[hi - 1].push_back(wi - 1);
  }
  auto Hbeg = Height.begin();
  auto Hen = Height.end();
  auto hiter = max_element(Hbeg, Hen);
  auto hinx = distance(Hbeg, hiter);
  auto Wbeg = Width.begin();
  auto Wen = Width.end();
  auto witer = max_element(Wbeg, Wen);
  auto winx = distance(Wbeg, witer);
  int HM = Height[hinx], WM = Width[winx];
  vector<int> WIXES;
  auto itr = find(Wbeg, Wen, WM);
  while (itr != Wen) {
    WIXES.push_back(distance(Wbeg, itr));
    itr++;
    itr = find(itr, Wen, WM);
  }
  auto H_itr = find(Hbeg, Hen, HM);
  auto WIXSIZ = WIXES.size();
  bool FULL = false;
  while (H_itr != Hen) {
    auto h_inx = distance(Hbeg, H_itr);
    H_itr++;
    H_itr = find(H_itr, Hen, HM);
    for (unsigned long long int i = 0; i < WIXSIZ; i++) {
      int WWI = WIXES[i];
      if (find(HFF.at(h_inx).begin(), HFF.at(h_inx).end(), WWI) ==
          HFF.at(h_inx).end()) {
        FULL = true;
        break;
      }
    }
    if (FULL) {
      break;
    }
  }
  cout << HM + WM + ((FULL) ? 0 : -1);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define froop1(a, n) for (int i = a; i < n; i++)
#define froop2(a, n) for (int i = a; i > n; i--)

#define ll long long

#define pq(name, type) priority_queue<type> name
#define vec(name, type, length, value) vector<type> name(length, value)
#define vec2(name, type, length, width, value)                                 \\
  vector<vector<type>> name(length, vector<type>(width, value));

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h;
  vector<ll> w;
  vector<ll> Wid(W, 0);
  vector<ll> Hei(H, 0);
  ll hmax = 0, wmax = 0;
  ll c1 = 0, c2 = 0;
  froop1(0, M) {
    ll a, b;
    cin >> a >> b;
    h.push_back(a);
    w.push_back(b);
    Wid.at(b - 1)++;
    Hei.at(a - 1)++;
    if (hmax < Hei.at(a - 1)) {
      hmax = Hei.at(a - 1);
      c1 = 1;
    } else if (hmax == Hei.at(a - 1)) {
      c1++;
    }
    if (wmax < Wid.at(b - 1)) {
      wmax = Wid.at(b - 1);
      c2 = 1;
    } else if (wmax == Wid.at(b - 1)) {
      c2++;
    }
  }
  ll pat = c1 * c2;
  int sw = 0;
  for (int i = 0; i < M; i++) {
    ll n = h.at(i) - 1;
    ll m = w.at(i) - 1;
    if (Wid.at(m) == wmax && Hei.at(n) == hmax)
      pat--;
  }
  if (pat == 0) {
    cout << hmax + wmax - 1 << endl;
  } else {
    cout << hmax + wmax << endl;
  }
}


Error: TLE

Fixed submission:

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

#define froop1(a, n) for (int i = a; i < n; i++)
#define froop2(a, n) for (int i = a; i > n; i--)

#define ll long long

#define pq(name, type) priority_queue<type> name
#define vec(name, type, length, value) vector<type> name(length, value)
#define vec2(name, type, length, width, value)                                 \\
  vector<vector<type>> name(length, vector<type>(width, value));

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h;
  vector<ll> w;
  vector<ll> Wid(W, 0);
  vector<ll> Hei(H, 0);
  ll hmax = 0, wmax = 0;
  ll c1 = 0, c2 = 0;
  froop1(0, M) {
    ll a, b;
    cin >> a >> b;
    h.push_back(a);
    w.push_back(b);
    Wid.at(b - 1)++;
    Hei.at(a - 1)++;
    if (hmax < Hei.at(a - 1)) {
      hmax = Hei.at(a - 1);
      c1 = 1;
    } else if (hmax == Hei.at(a - 1)) {
      c1++;
    }
    if (wmax < Wid.at(b - 1)) {
      wmax = Wid.at(b - 1);
      c2 = 1;
    } else if (wmax == Wid.at(b - 1)) {
      c2++;
    }
  }
  ll pat = c1 * c2;
  int sw = 0;
  while (h.size() != 0 && w.size() != 0) {
    ll n = h.at(0) - 1;
    ll m = w.at(0) - 1;
    h.erase(h.begin());
    w.erase(w.begin());
    if (Wid.at(m) == wmax && Hei.at(n) == hmax)
      pat--;
  }
  if (pat == 0) {
    cout << hmax + wmax - 1 << endl;
  } else {
    cout << hmax + wmax << endl;
  }
}