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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll hor[300005], ver[300005];

int main() {

  ll n, m, t, res = 0;
  cin >> n >> m >> t;
  set<pair<ll, ll>> s;
  set<ll> px, py;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    hor[x]++;
    ver[y]++;
    s.insert({x, y});
  }

  ll mx = *max_element(hor, hor + 300005);
  ll my = *max_element(ver, ver + 300005);

  for (ll i = 1; i <= 300005; i++) {
    if (hor[i] == mx)
      px.insert(i);
    if (ver[i] == my)
      py.insert(i);
  }

  for (auto i : px) {
    for (auto j : py) {
      ll tmp = hor[i] + ver[j];
      if (s.find({i, j}) != s.end())
        tmp -= 1;
      res = max(res, tmp);
      if (res == mx + my) {
        cout << res;
        return 0;
      }
    }
  }

  cout << res;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll hor[300005], ver[300005];

int main() {

  ll n, m, t, res = 0;
  cin >> n >> m >> t;
  set<pair<ll, ll>> s;
  set<ll> px, py;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    hor[x]++;
    ver[y]++;
    s.insert({x, y});
  }

  ll mx = *max_element(hor, hor + 300005);
  ll my = *max_element(ver, ver + 300005);

  for (ll i = 1; i <= 300005; i++) {
    if (hor[i] == mx)
      px.insert(i);
    if (ver[i] == my)
      py.insert(i);
  }

  for (auto i : px) {
    for (auto j : py) {
      ll tmp = hor[i] + ver[j];
      if (s.find({i, j}) != s.end())
        tmp -= 1;
      res = max(res, tmp);
    }
  }

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

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

int x[333333], y[333333];
int main() {
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> s;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    s.emplace(a, b);
    x[a]++, y[b]++;
  }
  int m1 = 0, m2 = 0;
  for (int i = 0; i < h; i++)
    m1 = max(m1, x[i + 1]);
  for (int i = 0; i < w; i++)
    m2 = max(m2, y[i + 1]);
  vector<int> z;
  for (int j = 0; j < w; j++)
    if (y[j + 1] == m2)
      z.push_back(j + 1);
  for (int i = 0; i < h; i++) {
    if (x[i + 1] < m1)
      continue;
    for (int j : z) {
      if (s.find({i + 1, j}) == s.end())
        goto pn;
    }
  }
  m1--;
pn:
  cout << m1 + m2 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int x[333333], y[333333];
int main() {
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> s;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    s.emplace(a, b);
    x[a]++, y[b]++;
  }
  int m1 = 0, m2 = 0;
  for (int i = 0; i < h; i++)
    m1 = max(m1, x[i + 1]);
  for (int i = 0; i < w; i++)
    m2 = max(m2, y[i + 1]);
  for (int i = 0; i < h; i++) {
    if (x[i + 1] < m1)
      continue;
    for (int j = 0; j < w; j++) {
      if (y[j + 1] < m2)
        continue;
      if (s.find({i + 1, j + 1}) == s.end())
        goto pn;
    }
  }
  m1--;
pn:
  cout << m1 + m2 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int h, w, m;
  cin >> h >> w >> m;
  vector<long long int> gridh(h, 0);
  vector<long long int> gridw(w, 0);
  vector<pair<long long int, long long int>> hoge(m);
  for (long long int i = 0; i < m; i++) {
    long long int h1, w1;
    cin >> h1 >> w1;
    hoge.at(i) = make_pair(h1 - 1, w1 - 1);
    gridh.at(h1 - 1)++;
    gridw.at(w1 - 1)++;
  }
  long long int ans = 0;
  long long int ansh, answ;
  long long int high = 0;
  long long int maxh = 0;
  for (long long int i = 0; i < gridh.size(); i++) {
    if (high < gridh.at(i)) {
      ansh = i;
      high = gridh.at(i);
      maxh = 1;
    } else if (high == gridh.at(i)) {
      maxh++;
    }
  }
  high = 0;
  long long int maxw = 0;
  for (long long int i = 0; i < gridw.size(); i++) {
    if (high < gridw.at(i)) {
      answ = i;
      high = gridw.at(i);
      maxw = 1;
    } else if (high == gridw.at(i)) {
      maxw++;
    }
  }
  ans = gridh.at(ansh) + gridw.at(answ);
  bool ok = false;
  long long int dup = 0;
  for (long long int i = 0; i < m; i++) {
    long long int H = hoge.at(i).first;
    long long int W = hoge.at(i).second;
    if (gridh.at(H) + gridw.at(W) == ans) {
      dup++;
    }
  }
  if (dup == maxh * maxw)
    ans--;
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int h, w, m;
  cin >> h >> w >> m;
  vector<long long int> gridh(h, 0);
  vector<long long int> gridw(w, 0);
  map<pair<long long int, long long int>, long long int> put;
  vector<pair<long long int, long long int>> hoge(m);
  for (long long int i = 0; i < m; i++) {
    long long int h1, w1;
    cin >> h1 >> w1;
    hoge.push_back(make_pair(h1 - 1, w1 - 1));
    gridh.at(h1 - 1)++;
    gridw.at(w1 - 1)++;
    put[make_pair(h1 - 1, w1 - 1)]++;
  }
  long long int ans = 0;
  long long int ansh, answ;
  long long int high = 0;
  for (long long int i = 0; i < gridh.size(); i++) {
    if (high < gridh.at(i)) {
      ansh = i;
      high = gridh.at(i);
    }
  }
  high = 0;
  for (long long int i = 0; i < gridw.size(); i++) {
    if (high < gridw.at(i)) {
      ansh = i;
      high = gridw.at(i);
    }
  }
  ans = gridh.at(ansh) + gridw.at(answ);
  if (put.count(make_pair(ansh, answ)))
    ans--;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n + 1; i++)
// cout << std::fixed << std::setprecision(15) << y << endl;

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

  ll h, w;
  pair<ll, ll> r[H + 1], c[W + 1];
  set<ll> b[H + 1];
  rep(i, H + 1) { r[i] = make_pair(0, i); }
  rep(i, W + 1) { c[i] = make_pair(0, i); }
  rep(i, M) {
    cin >> h >> w;
    r[h] = make_pair(r[h].first + 1, h);
    c[w] = make_pair(c[w].first + 1, w);
    b[h].insert(w);
  }
  sort(r, r + H + 1, greater<pair<ll, ll>>());
  sort(c, c + W + 1, greater<pair<ll, ll>>());

  ll maxRowTarget = r[0].first;
  ll maxColTarget = c[0].first;
  ll rp = 0, cp = 0;
  bool foundAns = false;
  ll ans;
  while (r[rp].first == maxRowTarget) {
    cp = 0;
    while (c[cp].first == maxColTarget) {
      if (b[r[rp].second].find(c[cp].second) == b[r[rp].second].end()) {
        ans = maxRowTarget + maxColTarget;
        foundAns = true;
        break;
      }
      cp++;
    }
    if (foundAns) {
      break;
    }
    rp++;
  }
  if (!foundAns) {
    ans = maxRowTarget + maxColTarget - 1;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n + 1; i++)
// cout << std::fixed << std::setprecision(15) << y << endl;

#define MOD 1000000007

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

  ll h, w;
  pair<ll, ll> r[H + 1], c[W + 1];
  set<ll> b[H + 1];
  rep(i, H + 1) { r[i] = make_pair(0, i); }
  rep(i, W + 1) { c[i] = make_pair(0, i); }
  rep(i, M) {
    cin >> h >> w;
    r[h] = make_pair(r[h].first + 1, h);
    c[w] = make_pair(c[w].first + 1, w);
    b[h].insert(w);
  }
  sort(r, r + H + 1, greater<pair<ll, ll>>());
  sort(c, c + W + 1, greater<pair<ll, ll>>());

  ll maxRowTarget = r[0].first;
  ll maxColTarget = c[0].first;
  ll rp = 0, cp = 0;
  bool foundAns = false;
  ll ans;
  while (r[rp].first == maxRowTarget) {
    cp = 0;
    while (c[cp].first == maxColTarget) {
      if (b[r[rp].second].find(c[cp].second) == b[r[rp].second].end()) {
        ans = maxRowTarget + maxColTarget;
        foundAns = true;
      }
      cp++;
    }
    rp++;
  }
  if (!foundAns) {
    ans = maxRowTarget + maxColTarget - 1;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, s, e) for (ll i = s; i < e; i++)
#define Forr(i, s, e) for (ll i = s; i > e; i--)
#define pb push_back
#define ll long long
#define int ll
#define mp make_pair
#define infi 1e12
const ll mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  cout << fixed << setprecision(8);
  ll r, c, m;
  cin >> r >> c >> m;
  ll row[r];
  ll col[c];
  For(i, 0, r) row[i] = 0;
  For(i, 0, c) col[i] = 0;
  set<pair<ll, ll>> st;
  For(i, 0, m) {
    ll x, y;
    cin >> x >> y;
    st.insert({x - 1, y - 1});
    row[x - 1]++;
    col[y - 1]++;
  }
  ll maxrow = 0;
  For(i, 0, r) if (row[i] > row[maxrow]) maxrow = i;
  ll maxcol = 0;
  For(i, 0, c) if (col[i] > col[maxcol]) maxcol = i;
  vector<ll> rows;
  vector<ll> cols;
  For(i, 0, r) if (row[i] == row[maxrow]) rows.pb(i);
  For(i, 0, c) if (col[i] == col[maxcol]) cols.pb(i);
  bool nob = false;
  For(i, 0, rows.size()) {
    For(j, 0, cols.size()) {
      auto itr = st.find({rows[i], cols[j]});
      if (itr == st.end()) {
        nob = true;
        break;
      }
    }
    if (nob)
      break;
  }
  if (nob)
    cout << max(row[maxrow] + col[maxcol], (ll)0);
  else {
    cout << max(row[maxrow] + col[maxcol] - 1, (ll)0);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, s, e) for (ll i = s; i < e; i++)
#define Forr(i, s, e) for (ll i = s; i > e; i--)
#define pb push_back
#define ll long long
#define int ll
#define mp make_pair
#define infi 1e12
const ll mod = 1e9 + 7;
vector<vector<ll>> gd;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  cout << fixed << setprecision(8);
  ll r, c, m;
  cin >> r >> c >> m;
  ll row[r];
  ll col[c];
  For(i, 0, r) row[i] = 0;
  For(i, 0, c) col[i] = 0;
  For(i, 0, r) {
    vector<ll> temp;
    For(j, 0, c) temp.pb(0);
    gd.pb(temp);
  }
  For(i, 0, m) {
    ll x, y;
    cin >> x >> y;
    gd[x - 1][y - 1] = 1;
    row[x - 1]++;
    col[y - 1]++;
  }
  ll maxrow = 0;
  For(i, 0, r) if (row[i] > row[maxrow]) maxrow = i;
  ll maxcol = 0;
  For(i, 0, c) if (col[i] > col[maxcol]) maxcol = i;
  vector<ll> rows;
  vector<ll> cols;
  For(i, 0, r) if (row[i] == row[maxrow]) rows.pb(i);
  For(i, 0, c) if (col[i] == col[maxcol]) cols.pb(i);
  bool nob = false;
  For(i, 0, rows.size()) {
    For(j, 0, cols.size()) {
      if (gd[rows[i]][cols[j]] == 0) {
        nob = true;
        break;
      }
    }
  }
  if (nob)
    cout << max(row[maxrow] + col[maxcol], (ll)0);
  else {
    cout << max(row[maxrow] + col[maxcol] - 1, (ll)0);
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\\n';
#define OUT(n) cout << (n) << '\\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS int H, W, M;
  cin >> H >> W >> M;
  map<pii, bool> mp;
  vector<int> bh(H), bw(W);
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    bh[h]++;
    bw[w]++;
    mp[{h, w}] = true;
  }
  vector<pii> bhr, bwr;
  REP(i, H) bhr.emplace_back(bh[i], i);
  REP(i, W) bwr.emplace_back(bw[i], i);
  sort(RALL(bhr));
  sort(RALL(bwr));

  int ans = bhr[0].first + bwr[0].first - 1;
  int hmax = bhr[0].first;
  int hi = 0;
  bool loop = true;
  while (bhr[hi].first == hmax && hi < H) {
    int wmax = bwr[0].first;
    int wi = 0;
    while (bwr[wi].first == wmax && wi < W) {
      if (mp[{bhr[hi].second, bwr[wi].second}] == false) {
        loop = false;
        ans++;
        break;
      }
      wi++;
    }
    if (!loop)
      break;
    hi++;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\\n';
#define OUT(n) cout << (n) << '\\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS int H, W, M;
  cin >> H >> W >> M;
  map<pii, bool> mp;
  vector<int> bh(H), bw(W);
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    bh[h]++;
    bw[w]++;
    mp[{h, w}] = true;
  }
  vector<pii> bhr, bwr;
  REP(i, H) bhr.emplace_back(bh[i], i);
  REP(i, W) bwr.emplace_back(bw[i], i);
  sort(RALL(bhr));
  sort(RALL(bwr));

  int ans = 0;
  int hmax = bhr[0].first;
  int hi = 0;
  while (bhr[hi].first == hmax && hi < H) {
    int wmax = bwr[0].first;
    int wi = 0;
    while (bwr[wi].first == wmax && wi < W) {
      ans = max(ans, bhr[hi].first + bwr[wi].first +
                         (mp[{bhr[hi].second, bwr[wi].second}] ? -1 : 0));
      wi++;
    }
    hi++;
  }

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

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

#include <bits/stdc++.h>
#define pb push_back

#define f(i, a, b) for (int i = a; i < b; i++)
#define f1(i, a, b) for (int i = a; i <= b; i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main() {

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

  int h, w, m, x, y, ans, maxi = 0, maxi1 = 0, res = 0, k, k1;
  cin >> h >> w >> m;
  map<int, int> map1, map2;
  map<pair<int, int>, int> visit;
  while (m--) {
    cin >> x >> y;
    map1[x]++;
    map2[y]++;
    visit[{x, y}] = 1;
    if (map1[x] > maxi) {
      maxi = map1[x];
      k = x;
    }
    if (map2[y] > maxi1) {
      maxi1 = map2[y];
      k1 = y;
    }
  }

  for (int i = 0; i <= h; i++) {
    ans = maxi1 + map1[i];
    if (visit[{i, k1}]) {
      ans--;
    }
    res = max(res, ans);
  }
  for (int i = 0; i <= w; i++) {
    ans = maxi + map2[i];
    if (visit[{k, i}]) {
      ans--;
    }
    res = max(res, ans);
  }
  cout << res << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back

#define f(i, a, b) for (int i = a; i < b; i++)
#define f1(i, a, b) for (int i = a; i <= b; i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main() {

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

  int h, w, m, x, y, ans, maxi = 0, maxi1 = 0, res = 0, k, k1;
  cin >> h >> w >> m;
  int arr[h + 1][w + 1];
  memset(arr, 0, sizeof(arr));
  map<int, int> map1, map2;
  map<pair<int, int>, int> visit;
  while (m--) {
    cin >> x >> y;
    arr[x][y] = 1;
    map1[x]++;
    map2[y]++;
    visit[{x, y}] = 1;
    if (map1[x] > maxi) {
      maxi = map1[x];
      k = x;
    }
    if (map2[y] > maxi1) {
      maxi1 = map2[y];
      k1 = y;
    }
  }

  for (int i = 0; i <= h; i++) {
    ans = maxi1 + map1[i];
    if (visit[{i, k1}]) {
      ans--;
    }
    res = max(res, ans);
  }
  for (int i = 0; i <= w; i++) {
    ans = maxi + map2[i];
    if (visit[{k, i}]) {
      ans--;
    }
    res = max(res, ans);
  }
  cout << res << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int N = 3e5 + 20;

int n, m, k, x, y, mxr, mxc, r[N], c[N];
vector<int> rows, cols;
set<pair<int, int>> s;

int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    r[x]++;
    c[y]++;
    s.insert({x, y});
  }

  for (int i = 1; i <= n; i++)
    mxr = max(mxr, r[i]);
  for (int j = 1; j <= m; j++)
    mxc = max(mxc, c[j]);

  for (int i = 1; i < N; i++)
    if (r[i] == mxr)
      rows.push_back(i);
  for (int j = 1; j <= m; j++)
    if (c[j] == mxc)
      cols.push_back(j);

  for (auto i : rows)
    for (auto j : cols)
      if (s.find({i, j}) == s.end())
        return 0 * printf("%d", mxr + mxc);
  printf("%d", mxr + mxc - 1);
}

Error: TLE

Fixed submission:

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

const int N = 3e5 + 20;

int n, m, k, x, y, mxr, mxc, r[N], c[N];
vector<int> rows, cols;
set<pair<int, int>> s;

int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    r[x]++;
    c[y]++;
    s.insert({x, y});
  }

  for (int i = 1; i <= n; i++)
    mxr = max(mxr, r[i]);
  for (int j = 1; j <= m; j++)
    mxc = max(mxc, c[j]);

  for (int i = 1; i < N; i++) {
    if (r[i] == mxr) {
      rows.push_back(i);
    }
  }
  for (int j = 1; j <= m; j++) {
    if (c[j] == mxc) {
      cols.push_back(j);
    }
  }

  int ans = max(mxr, mxc);

  for (auto i : rows) {
    for (auto j : cols) {
      int t = r[i] + c[j];
      if (s.find({i, j}) != s.end())
        t--;
      ans = max(ans, t);
    }
  }
  printf("%d", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ch(n);
  vector<int> cw(m);
  int k;
  cin >> k;
  set<pair<int, int>> st;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    st.emplace(x, y);
    ++ch[x];
    ++cw[y];
  }
  int mxh = *max_element(ch.begin(), ch.end());
  int mxw = *max_element(cw.begin(), cw.end());
  vector<int> up;
  vector<int> dw;
  for (int i = 0; i < n; i++) {
    if (ch[i] == mxh) {
      up.push_back(i);
    }
  }
  for (int i = 0; i < m; i++) {
    if (cw[i] == mxw) {
      dw.push_back(i);
    }
  }
  for (int x : up) {
    for (int y : dw) {
      if (!st.count({x, y})) {
        cerr << x << " " << y << endl;
        cout << (mxh + mxw) << '\\n';
        return 0;
      }
    }
  }
  cout << max(0, mxh + mxw - 1) << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ch(n);
  vector<int> cw(n);
  int k;
  cin >> k;
  set<pair<int, int>> st;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    st.emplace(x, y);
    ++ch[x];
    ++cw[y];
  }
  int mxh = *max_element(ch.begin(), ch.end());
  int mxw = *max_element(cw.begin(), cw.end());
  vector<int> up;
  vector<int> dw;
  for (int i = 0; i < n; i++) {
    if (ch[i] == mxh) {
      up.push_back(i);
    }
  }
  for (int i = 0; i < m; i++) {
    if (cw[i] == mxw) {
      dw.push_back(i);
    }
  }
  for (int x : up) {
    for (int y : dw) {
      if (!st.count({x, y})) {
        cout << (ch[x] + cw[y]) << '\\n';
        return 0;
      }
    }
  }
  cout << mxh + mxw - 1 << '\\n';
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int> a(H), b(W);
  set<pair<int, int>> bomb;
  rep(i, m) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    bomb.insert({h, w});
    a[h]++;
    b[w]++;
  }

  int res1 = 0, res2 = 0;
  int ans = 0;
  rep(i, H) res1 = max(res1, a[i]);
  rep(i, W) res2 = max(res2, b[i]);
  vector<int> p, q;
  rep(i, H) if (a[i] == res1) p.pb(i);
  rep(i, W) if (b[i] == res2) q.pb(i);
  if (p.size() * q.size() > m) {
    cout << res1 + res2 << endl;
    return 0;
  }
  rep(i, p.size()) {
    rep(j, q.size()) {
      if (bomb.count({p[i], q[j]}))
        ans = max(ans, res1 + res2 - 1);
      else
        ans = max(ans, res1 + res2);
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  vector<int> a(H), b(W);
  set<pair<int, int>> bomb;
  rep(i, m) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    bomb.insert({h, w});
    a[h]++;
    b[w]++;
  }

  int res1 = 0, res2 = 0;
  int ans = 0;
  rep(i, H) res1 = max(res1, a[i]);
  rep(i, W) res2 = max(res2, b[i]);
  vector<int> p, q;
  rep(i, H) if (a[i] == res1) p.pb(i);
  rep(i, W) if (b[i] == res2) q.pb(i);
  rep(i, p.size()) {
    rep(j, q.size()) {
      if (bomb.count({p[i], q[j]}))
        ans = max(ans, res1 + res2 - 1);
      else
        ans = max(ans, res1 + res2);
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

bool operator!=(std::pair<int, int> const &lhs,
                std::pair<int, int> const &rhs) {
  return lhs.first != rhs.first || lhs.second != rhs.second;
}

int main() {
  int H, W, M;
  std::cin >> H >> W >> M;
  std::vector<int> target_x(W + 1);
  std::vector<int> target_y(H + 1);
  std::vector<std::pair<int, int>> map;
  map.reserve(M);
  int max_x = 0;
  int max_y = 0;
  for (int i = 0; i < M; i++) {
    int h, w;
    std::cin >> h >> w;
    map.emplace_back(std::make_pair(w, h));
    target_x[w]++;
    target_y[h]++;
    if (target_x[w] > max_x) {
      max_x = target_x[w];
    }
    if (target_y[h] > max_y) {
      max_y = target_y[h];
    }
  }
  int count_xy = 0;
  for (auto const &e : map) {
    if (target_x[e.first] == max_x && target_y[e.second] == max_y)
      count_xy++;
  }
  int count_x_ = std::count(target_x.begin(), target_x.end(), max_x);
  int count_y_ = std::count(target_y.begin(), target_y.end(), max_y);

  if (count_xy == count_x_ * count_y_) {
    std::cout << max_x + max_y - 1 << std::endl;
  } else {
    std::cout << max_x + max_y << std::endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

bool operator!=(std::pair<int, int> const &lhs,
                std::pair<int, int> const &rhs) {
  return lhs.first != rhs.first || lhs.second != rhs.second;
}

int main() {
  int H, W, M;
  std::cin >> H >> W >> M;
  std::vector<int> target_x(W);
  std::vector<int> target_y(H);
  std::vector<std::pair<int, int>> map;
  map.reserve(M);
  int max_x = 0;
  int x_index = 0;
  int max_y = 0;
  int y_index = 0;
  for (int i = 0; i < M; i++) {
    int h, w;
    std::cin >> h >> w;
    map.emplace_back(std::make_pair(w, h));
    target_x[w]++;
    target_y[h]++;
    if (target_x[w] > max_x) {
      max_x = target_x[w];
      x_index = w;
    }
    if (target_y[h] > max_y) {
      max_y = target_y[h];
      y_index = h;
    }
  }
  std::sort(map.begin(), map.end());
  if (std::binary_search(map.begin(), map.end(),
                         std::make_pair(x_index, y_index))) {
    std::cout << max_x + max_y - 1 << std::endl;
  } else {
    std::cout << max_x + max_y << std::endl;
  }
}