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

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

int main() {

  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  data_type n, m, w, a, b;
  cin >> n >> w >> m;
  map<pair<int, int>, int> pai;
  vector<data_type> row(n + 1, 0), col(w + 1, 0);
  vector<pair<data_type, data_type>> ro, co;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    pai[{a, b}]++;
    row[a]++, col[b]++;
  }
  ro.push_back({0, 0});
  co.push_back({0, 0});
  for (int i = 1; i <= n; i++)
    ro.push_back({i, row[i]});
  for (int i = 1; i <= w; i++)
    co.push_back({i, col[i]});

  sort(ro.begin(), ro.end(), [](auto i, auto j) {
    if (i.second == j.second)
      return i.first < j.first;
    return i.second > j.second;
  });
  sort(co.begin(), co.end(), [](auto i, auto j) {
    if (i.second == j.second)
      return i.first < j.first;
    return i.second > j.second;
  });
  data_type ans = 0;
  for (int i = 0; i <= n; i++) {

    ans =
        max(ans, ro[i].second + co[0].second - pai[{ro[i].first, co[0].first}]);
    ans =
        max(ans, ro[i].second + co[1].second - pai[{ro[i].first, co[1].first}]);
  }

  for (int i = 0; i <= w; i++) {

    ans =
        max(ans, co[i].second + ro[0].second - pai[{ro[0].first, co[i].first}]);
    ans =
        max(ans, co[i].second + ro[1].second - pai[{ro[1].first, co[i].first}]);
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  data_type n, m, w, a, b;
  cin >> n >> w >> m;
  map<pair<int, int>, int> pai;
  vector<data_type> row(n + 1, 0), col(w + 1, 0);
  vector<pair<data_type, data_type>> ro, co;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    pai[{a, b}]++;
    row[a]++, col[b]++;
  }
  ro.push_back({0, 0});
  co.push_back({0, 0});
  for (int i = 1; i <= n; i++) {
    ro.push_back({i, row[i]});
  }
  for (int i = 1; i <= w; i++) {
    co.push_back({i, col[i]});
  }

  sort(ro.begin(), ro.end(), [](auto i, auto j) {
    if (i.second == j.second)
      return i.first < j.first;
    return i.second > j.second;
  });
  sort(co.begin(), co.end(), [](auto i, auto j) {
    if (i.second == j.second)
      return i.first < j.first;
    return i.second > j.second;
  });
  data_type ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans,
                ro[i].second + co[j].second - pai[{ro[i].first, co[j].first}]);
      data_type ans2 =
          ro[i].second + co[j + 1].second - pai[{ro[i].first, co[j + 1].first}];
      if (ans > ans2)
        break;
      else
        ans = ans2;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

#define int long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

signed main() {
  fastio map<pair<int, int>, int> mp;
  map<int, int> ma, mb;
  int h, w, m;
  cin >> h >> w >> m;

  while (m--) {
    int x, y;
    cin >> x >> y;
    ma[x]++;
    mb[y]++;
    mp[{x, y}]++;
  }

  int mr = 0, mc = 0;
  for (auto [a, b] : ma)
    mr = max(mr, b);
  for (auto [a, b] : mb)
    mc = max(mc, b);

  vector<int> v1, v2;
  for (auto [a, b] : ma)
    if (b == mr)
      v1.push_back(a);
  for (auto [a, b] : mb)
    if (b == mc)
      v2.push_back(a);
  int ans = mr + mc - 1;
  for (auto a : v1) {
    for (auto b : v2) {
      if (mp[{a, b}])
        continue;
      ans = mr + mc;
      goto stop;
    }
  }
stop:;
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define int long long
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

signed main() {
  fastio map<pair<int, int>, int> mp;
  map<int, int> ma, mb;
  int h, w, m;
  cin >> h >> w >> m;

  while (m--) {
    int x, y;
    cin >> x >> y;
    ma[x]++;
    mb[y]++;
    mp[{x, y}]++;
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      ans = max(ans, ma[i] + mb[j] - mp[{i, j}]);
    }
  }
  cout << ans << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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;
  set<pair<int, int>> st;
  int hmaxval = 0, wmaxval = 0;
  vector<int> hs(h); // hの爆弾の数
  vector<int> ws(w); // wの爆弾の数
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    st.insert({x, y});
    hs[x]++;
    chmax(hmaxval, hs[x]);
    ws[y]++;
    chmax(wmaxval, ws[y]);
  }
  vector<int> hmax;
  vector<int> wmax;
  for (int i = 0; i < h; i++) {
    if (hmaxval == hs[i]) {
      hmax.push_back(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if (wmaxval == ws[i]) {
      wmax.push_back(i);
    }
  }
  int ans = hmaxval + wmaxval - 1;
  for (auto x : hmax) {
    for (auto y : wmax) {
      if (st.find({x, y}) == st.end()) {
        cout << ans + 1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int hmaxval = 0, wmaxval = 0;
  vector<vector<bool>> grid(h, vector<bool>(w));
  vector<int> hs(h); // hの爆弾の数
  vector<int> ws(w); // wの爆弾の数
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    grid[x][y] = true;
    hs[x]++;
    hmaxval = max(hmaxval, hs[x]);
    ws[y]++;
    wmaxval = max(wmaxval, ws[y]);
  }
  vector<int> hmax;
  vector<int> wmax;
  for (int i = 0; i < h; i++) {
    if (hmaxval == hs[i]) {
      hmax.push_back(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if (wmaxval == ws[i]) {
      wmax.push_back(i);
    }
  }
  int ans = hmaxval + wmaxval - 1;
  for (auto x : hmax) {
    for (auto y : wmax) {
      if (!grid[x][y]) {
        cout << ans + 1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  int H, W, M;
  cin >> H >> W >> M;

  vector<int> h(M);
  vector<int> w(M);
  map<int, int> hmap;
  map<int, int> wmap;
  map<pair<int, int>, int> existmap;
  for (int ii = 0; ii < M; ++ii) {
    cin >> h[ii] >> w[ii];
    h[ii]--;
    w[ii]--;
    hmap[h[ii]]++;
    wmap[w[ii]]++;
    existmap[make_pair(h[ii], w[ii])] = 1;
  }

  // 行，列の最大値を取得
  int hmax = 0;
  int wmax = 0;
  for (auto itr = hmap.begin(); itr != hmap.end(); ++itr) {
    hmax = max(hmax, itr->second);
  }
  for (auto itr = wmap.begin(); itr != wmap.end(); ++itr) {
    wmax = max(wmax, itr->second);
  }

  // 最大値を持つ行，列を取得
  vector<int> hlist;
  for (auto itr = hmap.begin(); itr != hmap.end(); ++itr) {
    if (hmax == itr->second) {
      hlist.push_back(itr->first);
    }
  }
  vector<int> wlist;
  for (auto itr = wmap.begin(); itr != wmap.end(); ++itr) {
    if (wmax == itr->second) {
      wlist.push_back(itr->first);
    }
  }

  bool ok = false;
  for (int ii = 0; ii < hlist.size(); ++ii) {
    for (int jj = 0; jj < wlist.size(); ++jj) {
      pair<int, int> key = make_pair(hlist[ii], wlist[jj]);
      if (existmap[key] == 0) {
        ok = true;
        break;
      }
    }
  }

  int ans = hmax + wmax;
  if (!ok) {
    ans--;
  }

  cout << ans << "\\n";

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  int H, W, M;
  cin >> H >> W >> M;

  auto bom = make_vec<int>(H, W);
  for (int ii = 0; ii < M; ++ii) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    bom[h][w] = 1;
  }

  int ans = 0;

  cout << ans << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T> using Graph = vector<vector<T>>;
const int MOD = 998244353;
const ld PI = acosl(-1);

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

  int H, W, M;
  cin >> H >> W >> M;

  vector<int> ycnt(H), xcnt(W);
  map<pii, bool> mp;
  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    mp[{h, w}] = true;
    ycnt[h]++;
    xcnt[w]++;
  }

  int hma = 0, wma = 0, hidx = 0, widx = 0;
  for (int i = 0; i < H; ++i) {
    if (hma < ycnt[i]) {
      hma = ycnt[i];
      hidx = i;
    }
  }
  for (int i = 0; i < W; ++i) {
    if (wma < xcnt[i]) {
      wma = xcnt[i];
      widx = i;
    }
  }

  int ans = 0;
  ans = hma + wma;
  if (mp.find({hidx, widx}) != mp.end())
    ans--;

  vector<int> hcheck, wcheck;
  for (int i = 0; i < H; ++i) {
    if (hma == ycnt[i])
      hcheck.push_back(i);
  }
  for (int i = 0; i < W; ++i) {
    if (wma == xcnt[i])
      wcheck.push_back(i);
  }

  H = hcheck.size();
  W = wcheck.size();
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (mp.find({hcheck[i], wcheck[j]}) != mp.end())
        continue;
      ans = hma + wma;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T> using Graph = vector<vector<T>>;
const int MOD = 998244353;
const ld PI = acosl(-1);

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

  int H, W, M;
  cin >> H >> W >> M;

  vector<int> ycnt(H), xcnt(W);
  map<pii, bool> mp;
  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    mp[{h, w}] = true;
    ycnt[h]++;
    xcnt[w]++;
  }

  int hma = 0, wma = 0, hidx = 0, widx = 0;
  for (int i = 0; i < H; ++i) {
    if (hma < ycnt[i]) {
      hma = ycnt[i];
      hidx = i;
    }
  }
  for (int i = 0; i < W; ++i) {
    if (wma < xcnt[i]) {
      wma = xcnt[i];
      widx = i;
    }
  }

  int ans = 0;
  ans = hma + wma;
  if (mp.find({hidx, widx}) != mp.end())
    ans--;

  for (int i = 0; i < H; ++i) {
    if (ycnt[i] < hma)
      continue;
    for (int j = 0; j < W; ++j) {
      if (xcnt[j] < wma)
        continue;
      if (mp.find({i, j}) != mp.end())
        continue;
      ans = hma + wma;
      break;
    }
  }

  cout << ans << endl;

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

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int mxr = -1, mxc = -1;
  vector<vector<int>> row(h), colum(w);
  vector<int> mxh, mxw;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    row[hi].push_back(wi);
    colum[wi].push_back(hi);
    mxr = max(mxr, (int)row[hi].size());
    mxc = max(mxc, (int)colum[wi].size());
  }

  rep(i, h) {
    if (mxr == row[i].size())
      mxh.push_back(i);
  }

  vector<int> cnt(h, 0);
  rep(j, w) {
    if (mxc == colum[j].size()) {
      mxw.push_back(j);
      rep(k, colum[j].size()) cnt[colum[j][k]]++;
    }
  }

  int ans = 0;
  rep(i, mxh.size()) {
    if (cnt[mxh[i]] != mxw.size()) {
      ans++;
      break;
    }
  }

  ans += mxr + (mxc - 1);
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int mxr = -1, mxc = -1;
  vector<vector<int>> row(h), colum(w);
  vector<int> mxh, mxw;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    row[hi].push_back(wi);
    colum[wi].push_back(hi);
    mxr = max(mxr, (int)row[hi].size());
    mxc = max(mxc, (int)colum[wi].size());
  }

  rep(i, h) {
    if (mxr == row[i].size())
      mxh.push_back(i);
  }

  vector<int> cnt(w, 0);
  rep(j, w) {
    if (mxc == colum[j].size()) {
      mxw.push_back(j);
      rep(k, colum[j].size()) cnt[colum[j][k]]++;
    }
  }

  int ans = 0;
  rep(i, mxh.size()) {
    if (cnt[mxh[i]] != mxw.size()) {
      ans++;
      break;
    }
  }

  ans += mxr + (mxc - 1);
  cout << ans << endl;

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

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

#define ll long long
#define mod 1000000000007
#define pii pair<ll, ll>

#define debug(a)                                                               \\
  { cout << #a << " = " << a << endl; }

const int maxn = 1e3 + 1;
ll n, m, t, k;

ll __min(ll a, ll b) { return a < b ? a : b; }

ll __max(ll a, ll b) { return a > b ? a : b; }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m >> k;
  ll mi = 0;
  ll mj = 0;
  ll m_i = -1;
  ll m_j = -1;
  ll i, j;

  unordered_map<string, ll> u;
  unordered_map<ll, ll> ci;
  vector<ll> c_i;
  unordered_map<ll, ll> cj;
  vector<ll> c_j;

  for (ll y = 0; y < k; y++) {
    cin >> i >> j;
    --i;
    --j;
    string c = to_string(i) + "_" + to_string(j);
    u[c] = true;
    ci[i] = (ci[i] + 1);
    cj[j] = (cj[j] + 1);
    if (mi < ci[i]) {
      mi = ci[i];
      c_i = {i};
    } else if (mi == ci[i]) {
      c_i.push_back(i);
    }

    if (mj < cj[j]) {
      mj = cj[j];
      c_j = {j};
    } else if (mj == cj[j]) {
      c_j.push_back(j);
    }
  }

  ll ans = mi + mj;
  for (int i = 0; i < c_i.size(); i++) {
    for (int j = 0; j < c_j.size(); j++) {
      string c = to_string(c_i[i]) + "_" + to_string(c_j[j]);
      if (u.find(c) == u.end()) {
        cout << ans << "\\n";
        return 0;
      }
    }
  }
  cout << ans - 1 << "\\n";
}


Error: TLE

Fixed submission:

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

#define ll long long
#define mod 1000000000007
#define pii pair<ll, ll>

#define debug(a)                                                               \\
  { cout << #a << " = " << a << endl; }

const int maxn = 1e3 + 1;
ll n, m, t, k;

ll __min(ll a, ll b) { return a < b ? a : b; }

ll __max(ll a, ll b) { return a > b ? a : b; }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m >> k;
  ll mi = 0;
  ll mj = 0;
  ll m_i = -1;
  ll m_j = -1;
  ll i, j;

  unordered_map<string, ll> u;
  unordered_map<ll, ll> ci;
  unordered_map<ll, ll> cj;

  for (ll y = 0; y < k; y++) {
    cin >> i >> j;
    --i;
    --j;
    string c = to_string(i) + "_" + to_string(j);
    u[c] = true;
    ci[i] = (ci[i] + 1);
    cj[j] = (cj[j] + 1);
    mi = __max(mi, ci[i]);
    mj = __max(mj, cj[j]);
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (ci[i] == mi && cj[j] == mj) {
        string c = to_string(i) + "_" + to_string(j);
        ll f = (u.find(c) != u.end()) ? -1 : 0;

        ans = __max(ans, mi + mj + f);
      }
    }
  }
  cout << ans << "\\n";
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll h, w, m;
  cin >> h >> w >> m;

  set<pair<ll, ll>> s;
  vector<ll> mpr(300001, 0);
  vector<ll> mpc(300001, 0);
  while (m--) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    s.insert({x, y});
    mpr[x]++;
    mpc[y]++;
  }
  ll mar = INT_MIN;
  ll r;
  for (ll i = 0; i < h; i++) {
    if (mpr[i] > mar) {
      mar = mpr[i];
      r = i;
    }
  }
  ll mac = INT_MIN;
  ll c;
  for (ll i = 0; i < w; i++) {
    if (mpc[i] > mac) {
      mac = mpc[i];
      c = i;
    }
  }
  ll cnt = INT_MIN;
  for (ll i = 0; i < h; i++) {
    if (s.find({i, c}) != s.end()) {
      cnt = max(cnt, mpr[i] + mac - 1);
    } else {
      cnt = max(cnt, mpr[i] + mac);
    }
  }
  for (ll i = 0; i < w; i++) {
    if (s.find({r, i}) != s.end()) {
      cnt = max(cnt, mpc[i] + mar - 1);
    } else {
      cnt = max(cnt, mpc[i] + mar);
    }
  }
  cout << cnt << endl;
  // cout<<ma<<endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  ll a[h][w];
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++) {
      a[i][j] = 0;
    }
  set<pair<ll, ll>> s;
  vector<ll> mpr(300001, 0);
  vector<ll> mpc(300001, 0);
  while (m--) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    s.insert({x, y});
    mpr[x]++;
    mpc[y]++;
  }
  ll mar = INT_MIN;
  ll r;
  for (ll i = 0; i < h; i++) {
    if (mpr[i] > mar) {
      mar = mpr[i];
      r = i;
    }
  }
  ll mac = INT_MIN;
  ll c;
  for (ll i = 0; i < w; i++) {
    if (mpc[i] > mac) {
      mac = mpc[i];
      c = i;
    }
  }
  ll cnt = INT_MIN;
  for (ll i = 0; i < h; i++) {
    if (s.find({i, c}) != s.end()) {
      cnt = max(cnt, mpr[i] + mac - 1);
    } else {
      cnt = max(cnt, mpr[i] + mac);
    }
  }
  for (ll i = 0; i < w; i++) {
    if (s.find({r, i}) != s.end()) {
      cnt = max(cnt, mpc[i] + mar - 1);
    } else {
      cnt = max(cnt, mpc[i] + mar);
    }
  }
  cout << cnt << endl;
  // cout<<ma<<endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define nl '\\n'
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
ll m = 1000000007;
int main() {
  fast;
  ll n, m, t;
  cin >> n >> m >> t;
  map<ll, ll> r, c;
  map<pair<ll, ll>, ll> a;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    r[x]++;
    c[y]++;
    a[{x, y}] = 1;
  }

  ll count = 0, rans = 0;
  for (auto i : r) {
    if (i.second >= count) {
      count = i.second;
      rans = i.first;
    }
  }
  ll lclcount = count;
  ll cans;
  for (auto i : c) {
    ll tep = i.second;
    if (tep + lclcount > count && a[{rans, i.first}] == 0) {
      count = tep + lclcount;
      cans = i.first;
    } else if (tep + lclcount - 1 > count && a[{rans, i.first}] == 1) {
      count = tep + lclcount - 1;
      cans = i.first;
    }
  }

  ll count1 = 0;
  for (auto i : c) {
    if (i.second >= count1) {
      count1 = i.second;
      cans = i.first;
    }
  }
  lclcount = count1;

  for (auto i : r) {
    ll tep = i.second;
    if (tep + lclcount > count && a[{i.first, cans}] == 0) {
      count1 = tep + lclcount;
      cans = i.first;
    } else if (tep + lclcount - 1 > count && a[{i.first, cans}] == 1) {
      count1 = tep + lclcount - 1;
      cans = i.first;
    }
  }

  // cout<<rans<<" "<<cans<<nl;
  cout << max(count, count1);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define nl '\\n'
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
ll m = 1000000007;
int main() {
  fast;
  ll n, m, t;
  cin >> n >> m >> t;
  ll a[n][m];
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < m; j++)
      a[i][j] = 0;
  map<ll, ll> r, c;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    r[x]++;
    c[y]++;
    a[x][y] = 1;
  }

  ll count = 0, rans = 0;
  for (auto i : r) {
    if (i.second > count) {
      count = i.second;
      rans = i.first;
    }
  }
  ll lclcount = count;
  ll cans = 0;
  for (auto i : c) {
    ll tep = i.second;
    if (tep + lclcount > count && a[rans][i.first] == 0) {
      count = tep + lclcount;
      cans = i.first;
    } else if (tep + lclcount - 1 > count && a[rans][i.first] == 1) {
      count = tep + lclcount - 1;
      cans = i.first;
    }
  }

  // cout<<rans<<" "<<cans<<nl;
  cout << count;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 3e5 + 7;

int r[N], c[N];
map<PII, int> mp;

int main() {
  int n, m, k, x, y;
  scanf("%d%d%d", &n, &m, &k);
  int xx = 0, yy = 0;
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    mp[make_pair(x, y)] = 1;
    r[x]++, c[y]++;
    xx = max(xx, r[x]);
    yy = max(yy, c[y]);
  }
  vector<int> vx, vy;
  for (int i = 1; i <= n; i++)
    if (r[i] == xx)
      vx.push_back(i);
  for (int i = 1; i <= m; i++)
    if (c[i] == yy)
      vy.push_back(i);
  int flag = 0;
  for (int i = 0; i < vx.size(); i++) {
    for (int j = 0; j < vy.size(); j++) {
      if (!mp[make_pair(vx[i], vy[j])]) {
        flag = 1;
        break;
      }
    }
    if (flag)
      break;
  }
  if (flag)
    cout << xx + yy << "\\n";
  else
    cout << xx + yy - 1 << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const ULL P = 131;
const int N = 3e5 + 7;

int r[N], c[N];
map<PII, int> mp;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int xx = 0, yy = 0;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    mp[{x, y}] = 1;
    r[x]++, c[y]++;
    xx = max(xx, r[x]);
    yy = max(yy, c[y]);
  }
  vector<int> vx, vy;
  for (int i = 1; i <= n; i++)
    if (r[i] == xx)
      vx.push_back(i);
  for (int i = 1; i <= m; i++)
    if (c[i] == yy)
      vy.push_back(i);
  int flag = 0;
  for (int i = 0; i < vx.size(); i++) {
    for (int j = 0; j < vy.size(); j++) {
      if (!mp[{vx[i], vy[j]}])
        flag = 1;
    }
  }
  if (flag)
    cout << xx + yy << "\\n";
  else
    cout << xx + yy - 1 << "\\n";
  return 0;
}