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

#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<P> hw(m);
  vector<int> hh(h, 0);
  vector<int> ww(w, 0);
  set<P> s;
  rep(i, m) {
    int hhh, www;
    cin >> hhh >> www;
    hhh--;
    www--;
    hh.at(hhh)++;
    ww.at(www)++;
    hw.at(i) = P(hhh, www);
    s.emplace(hhh, www);
  }
  int hMax = -1;
  vector<int> hi;
  int wMax = -1;
  vector<int> wi;
  rep(i, h) {
    if (hh.at(i) > hMax) {
      hMax = hh.at(i);
      hi.clear();
      hi.push_back(i);
    } else if (hh.at(i) == hMax) {
      hi.push_back(i);
    }
  }
  rep(i, w) {
    if (ww.at(i) > wMax) {
      wMax = ww.at(i);
      wi.clear();
      wi.push_back(i);
    } else if (ww.at(i) == wMax) {
      wi.push_back(i);
    }
  }
  int res = hMax + wMax;
  bool cross = true; // 交点に爆破対象
  for (int i : hi) {
    for (int j : wi) {
      if (s.count(P(i, j)) > 0) {
        continue;
      }
      // 爆破対象がない交点があった
      cross = false;
      break;
    }
    if (!cross) {
      break;
    }
  }
  if (cross) {
    res--;
  }
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<P> hw(m);
  vector<int> hh(h, 0);
  vector<int> ww(w, 0);
  set<P> s;
  rep(i, m) {
    int hhh, www;
    cin >> hhh >> www;
    hhh--;
    www--;
    hh.at(hhh)++;
    ww.at(www)++;
    hw.at(i) = P(hhh, www);
    s.emplace(hhh, www);
  }
  int hMax = -1;
  vector<int> hi;
  int wMax = -1;
  vector<int> wi;
  rep(i, h) {
    if (hh.at(i) > hMax) {
      hMax = hh.at(i);
      hi.clear();
      hi.push_back(i);
    } else if (hh.at(i) == hMax) {
      hi.push_back(i);
    }
  }
  rep(i, w) {
    if (ww.at(i) > wMax) {
      wMax = ww.at(i);
      wi.clear();
      wi.push_back(i);
    } else if (ww.at(i) == wMax) {
      wi.push_back(i);
    }
  }
  int res = hMax + wMax;
  bool cross = true; // 交点に爆破対象
  for (int i : hi) {
    for (int j : wi) {
      if (s.count(P(i, j)) > 0) {
        continue;
      }
      // 爆破対象がない交点があった
      cross = false;
    }
  }
  if (cross) {
    res--;
  }
  cout << res << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<set<int>> b(h);
  vector<int> sums_h(h, 0);
  vector<int> sums_w(w, 0);
  int bh, bw;
  for (int i = 0; i < m; i++) {
    cin >> bh >> bw;
    sums_h.at(bh - 1)++;
    sums_w.at(bw - 1)++;
    b.at(bh - 1).insert(bw - 1);
  }
  int result = 0;
  int max_h = 0;
  int max_w = 0;
  vector<int> index_h;
  vector<int> index_w;
  for (int i = 0; i < h; i++) {
    if (max_h < sums_h.at(i)) {
      max_h = sums_h.at(i);
      index_h.clear();
      index_h.push_back(i);
    } else if (max_h == sums_h.at(i)) {
      index_h.push_back(i);
    }
  }
  for (int j = 0; j < w; j++) {
    if (max_w < sums_w.at(j)) {
      max_w = sums_w.at(j);
      index_w.clear();
      index_w.push_back(j);
    } else if (max_w == sums_w.at(j)) {
      index_w.push_back(j);
    }
  }
  for (int i = 0; i < index_h.size(); i++) {
    for (int j = 0; j < index_w.size(); j++) {
      if (!b.at(index_h.at(i)).count(index_w.at(j))) {
        cout << max_h + max_w << endl;
        return 0;
      }
    }
  }
  cout << max_h + max_w - 1 << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<set<int>> b(h);
  vector<int> sums_h(h, 0);
  vector<int> sums_w(w, 0);
  int bh, bw;
  for (int i = 0; i < m; i++) {
    cin >> bh >> bw;
    sums_h.at(bh - 1)++;
    sums_w.at(bw - 1)++;
    b.at(bh - 1).insert(bw - 1);
  }
  int result = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (b.at(i).count(j)) {
        result = max(result, sums_h.at(i) + sums_w.at(j) - 1);
      } else {
        result = max(result, sums_h.at(i) + sums_w.at(j));
      }
    }
  }
  cout << result << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
vector<pair<int, int>> vec;
int co[300030] = {0}, co1[300030] = {0};
vector<int> ma, ma1;
int main() {
  long long h, w, m;
  cin >> h >> w >> m;
  int s = 0, s1 = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    co[x]++;
    co1[y]++;
    vec.emplace_back(make_pair(x, y));
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i <= w; i++) {
    if (co1[i] > s) {
      s = co1[i];
    }
  }
  for (int i = 0; i <= w; i++) {
    if (co1[i] == s) {
      ma.emplace_back(i);
    }
  }
  for (int i = 0; i <= h; i++) {
    if (co[i] > s1) {
      s1 = co[i];
    }
  }
  for (int i = 0; i <= h; i++) {
    if (co[i] == s1) {
      ma1.emplace_back(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < ma1.size(); i++) {
    for (int j = 0; j < ma.size(); j++) {
      int count = s1 + s;
      if (binary_search(vec.begin(), vec.end(), make_pair(ma1[i], ma[j]))) {
        count--;
      } else {
        cout << count << endl;
        return 0;
      }
    }
  }
  cout << s1 + s - 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
vector<pair<int, int>> vec;
long long co[300030] = {0}, co1[300030] = {0};
vector<int> ma;
int main() {
  long long h, w, m;
  cin >> h >> w >> m;
  int s = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    co[x]++;
    co1[y]++;
    vec.emplace_back(make_pair(x, y));
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i <= w; i++) {
    if (co1[i] > s) {
      s = co1[i];
    }
  }
  for (int i = 0; i <= w; i++) {
    if (co1[i] == s) {
      ma.emplace_back(i);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= h; i++) {
    for (int j = 0; j < ma.size(); j++) {
      long long count = co[i] + s;
      if (binary_search(vec.begin(), vec.end(), make_pair(i, ma[j]))) {
        count--;
      }
      if (ans < count) {
        ans = count;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vvll = vector<vll>;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<map<int, bool>> cy(h + 1);
  vi sx(h + 1), sy(w + 1);
  FOR(i, 1, m) {
    int x, y;
    cin >> x >> y;
    cy[x][y] = 1, sx[x]++, sy[y]++;
  }
  priority_queue<pii> pq;
  FOR(i, 1, w)
  pq.push({sy[i], i});
  int ans = 0;
  FOR(i, 1, h) {
    if (sx[i]) {
      vpii rm;
      int tmx = 0;
      while (!pq.empty() && cy[i][pq.top().se]) {
        tmx = max(tmx, pq.top().fi - 1);
        rm.pb(pq.top());
        pq.pop();
      }
      if (!pq.empty())
        tmx = max(tmx, pq.top().fi);
      ans = max(ans, sx[i] + tmx);
      for (pii j : rm)
        pq.push(j);
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vvll = vector<vll>;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<map<int, bool>> cy(h + 1);
  vi sx(h + 1), sy(w + 1);
  FOR(i, 1, m) {
    int x, y;
    cin >> x >> y;
    cy[x][y] = 1, sx[x]++, sy[y]++;
  }
  priority_queue<pii> pq;
  FOR(i, 1, w)
  pq.push({sy[i], i});
  int ans = 0;
  FOR(i, 1, h) {
    if (sx[i]) {
      vpii rm;
      int tmx = 0;
      while (cy[i][pq.top().se]) {
        tmx = max(tmx, pq.top().fi - 1);
        rm.pb(pq.top());
        pq.pop();
      }
      if (!pq.empty())
        tmx = max(tmx, pq.top().fi);
      ans = max(ans, sx[i] + tmx);
      for (pii j : rm)
        pq.push(j);
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;

struct point {
  int x, y;
} p[maxn];

map<int, int> xcnt, ycnt;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  int maxh = 0, maxw = 0;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    p[i] = {h, w};
    xcnt[h]++, ycnt[w]++;
    maxh = max(maxh, xcnt[h]), maxw = max(maxw, ycnt[w]);
  }
  int cnt = 0;
  for (int i = 0; i < M; i++) {
    int h = p[i].x, w = p[i].y;
    if (xcnt[h] == maxh && ycnt[w] == maxw)
      cnt++;
  }
  // cout<<cnt<<endl;
  int num1 = 0, num2 = 0;
  for (auto tmp : xcnt)
    if (tmp.second == maxh)
      num1++;
  for (auto tmp : ycnt)
    if (tmp.second == maxw)
      num2++;
  // cout<<ycnt[i]<<endl;
  // cout<<num1<<' '<<num2<<endl;
  if (num1 * num2 == cnt)
    cout << maxh + maxw - 1 << endl;
  else
    cout << maxh + maxw << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
vector<int> h[N];

struct nobe {
  int r, cnt;
} a[N], b[N];

bool cmp(nobe a, nobe b) { return a.cnt > b.cnt; }

int main() {
  int h0, w0, m;
  cin >> h0 >> w0 >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    a[x].cnt++;
    a[x].r = x;
    b[y].cnt++;
    b[y].r = y;
    h[x].push_back(y);
  }
  sort(a + 1, a + h0 + 1, cmp);
  sort(b + 1, b + w0 + 1, cmp);
  int f = 0;
  for (int i = 1; i <= h0; i++) {
    if (f || (a[i].cnt < a[1].cnt))
      break;
    for (int j = 1; j <= w0; j++) {
      if ((f || b[j].cnt < b[1].cnt))
        break;
      if (a[i].cnt == a[1].cnt && b[j].cnt == b[1].cnt) {
        int flag = 0;
        for (int ii = 0; ii < h[a[i].r].size(); ii++)
          if (h[a[i].r][ii] == b[j].r)
            flag = 1;
        if (!flag)
          f = 1;
      }
    }
  }
  // cout<<a[1].cnt<<' '<<b[1].cnt<<' '<<a[1].r<<' '<<b[1].r<<endl;
  if (f)
    cout << a[1].cnt + b[1].cnt << endl;
  else
    cout << a[1].cnt + b[1].cnt - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll h, w, m, a, b;
  cin >> h >> w >> m;
  vector<ll> l(h, 0), r(w, 0); // 横列, 縦列
  map<P, ll> t;
  rep1(i, m) {
    cin >> a >> b;
    a--;
    b--;
    l[a]++;
    r[b]++;
    P p = make_pair(a, b);
    t[p]++;
  }
  ll max_l = *max_element(l.begin(), l.end());
  ll max_r = *max_element(r.begin(), r.end());
  vector<ll> ndx_l, ndx_r; // 横列, 縦列
  rep1(i, h) if (l[i] == max_l) ndx_l.push_back(i);
  rep1(i, w) if (r[i] == max_r) ndx_r.push_back(i);
  ll ans = max_l + max_r - 1;
  for (auto x : ndx_l) {
    for (auto y : ndx_r) {
      P p = make_pair(x, y);
      if (t[p] == 0) {
        ans = max_l + max_r;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  // printf("%.12f", ans);
}

Error: 0

Fixed submission:

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> freqx(3005, 0);
  vector<int> freqy(3005, 0);
  int mat[h + 2][w + 2];
  memset(mat, 0, sizeof(mat));
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    mat[x][y]++;
    freqx[x]++;
    freqy[y]++;
  }
  int mx = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int dx = freqx[i];
      int dy = freqy[j];
      int sum = dx + dy;
      if (mat[i][j] > 0) {
        sum -= mat[i][j];
      }
      mx = max(mx, sum);
    }
  }
  cout << mx << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); ++i)
typedef long long ll;
using namespace std;

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


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); ++i)
typedef long long ll;
using namespace std;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<ll> x(h), y(w);
  vector<ll> xi(h), yi(w);
  rep(i, m) {
    cin >> xi[i] >> yi[i];
    x[xi[i]]++;
    y[yi[i]]++;
  }
  int mm = 0, mm2 = 0, mi, mi2;
  rep(i, h) {
    if (mm < x[i]) {
      mm = x[i];
      mi = i;
    }
  }
  rep(i, w) {
    if (mm2 < x[i]) {
      mm2 = x[i];
      mi2 = i;
    }
  }
  rep(i, m) {
    if (mi == xi[i] && mi2 == yi[i]) {
      cout << mm + mm2 - 1 << endl;
      return 0;
    }
  }
  cout << mm + mm2 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  unordered_map<int, int> bombh, bombw;
  set<pair<int, int>> st;
  int max1 = 0, max2 = 0;
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    st.insert(make_pair(h, w));
    bombh[h]++;
    if (bombh[h] > max1)
      max1 = bombh[h];
    bombw[w]++;
    if (bombw[w] > max2)
      max2 = bombw[w];
  }
  // for(auto x: bombh)cout << x.first << x.second << endl;
  // cout << endl;
  // for(auto x:bombw)cout << x.first << x.second << endl;

  vector<int> Hkouho, Wkouho;
  for (auto x : bombh) {
    if (x.second == max1) {
      Hkouho.push_back(x.first);
    }
  }
  for (auto x : bombw) {
    if (x.second == max2) {
      Wkouho.push_back(x.first);
    }
  }
  // rep(i, Hkouho.size()) cout << Hkouho[i] << " " ;
  // cout << endl;
  // rep(i, Wkouho.size()) cout << Wkouho[i] << " " ;
  // cout << endl;
  int ans = max1 + max2;
  for (auto h : Hkouho) {
    for (auto w : Wkouho) {
      // bool flag = true;
      // rep(i, M){
      //     if(G[i][0] == h && G[i][1] == w){
      //         flag = false;
      //     }
      // }
      // if(flag == true){
      //     cout << ans << endl;
      //     return 0;
      // }
      pair<int, int> tmp = make_pair(h, w);
      if (st.find(tmp) == st.end()) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  unordered_map<int, int> bombh, bombw;
  Graph G(M, vector<int>(2, 0));
  rep(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    G[i][0] = h;
    G[i][1] = w;
    bombh[h]++;
    bombw[w]++;
  }
  // for(auto x: bombh)cout << x.first << x.second << endl;
  // cout << endl;
  // for(auto x:bombw)cout << x.first << x.second << endl;

  int max1 = 0, max2 = 0;
  vector<int> Hkouho, Wkouho;
  for (auto x : bombh) {
    if (x.second > max1)
      max1 = x.second;
  }
  for (auto x : bombh) {
    if (x.second == max1)
      Hkouho.push_back(x.first);
  }
  for (auto x : bombw)
    if (x.second > max2)
      max2 = x.second;
  for (auto x : bombw) {
    if (x.second == max2)
      Wkouho.push_back(x.first);
  }
  int ans = max1 + max2;
  // cout << max1 << " " << max2 << endl;
  for (auto h : Hkouho) {
    for (auto w : Wkouho) {
      bool flag = true;
      rep(i, M) {
        if (G[i][0] == h && G[i][1] == w) {
          flag = false;
        }
      }
      if (flag == true) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

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

  set<P> points;
  rep(i, 0, M - 1) {
    int h, w;
    cin >> h >> w;
    points.insert(P(h, w));
  }

  map<int, int> mp_rows, mp_columns;
  int max_row_cnt = 0;
  int max_column_cnt = 0;

  for (P point : points) {
    max_row_cnt = max(max_row_cnt, ++mp_rows[point.first]);
    max_column_cnt = max(max_column_cnt, ++mp_columns[point.second]);
  }

  vector<int> max_row_indices;
  for (auto mp_row : mp_rows) {
    if (max_row_cnt == mp_row.second)
      max_row_indices.push_back(mp_row.first);
  }

  vector<int> max_column_indices;
  for (auto mp_column : mp_columns) {
    if (max_column_cnt == mp_column.second)
      max_column_indices.push_back(mp_column.first);
  }

  int ans = max_row_cnt + max_column_cnt;
  for (auto h : max_row_indices) {
    for (auto w : max_column_indices) {
      if (points.find(P(h, w)) == points.end()) {
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << ans - 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

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

  vector<vector<bool>> rows(H, vector<bool>(W, false));
  vector<ll> rows_cnt(H, 0);
  vector<ll> columns_cnt(W, 0);
  rep(i, 0, M - 1) {
    ll h, w;
    cin >> h >> w;
    h--;
    w--;
    rows[h][w] = true;
    rows_cnt[h]++;
    columns_cnt[w]++;
  }

  ll max_row_cnt = 0;
  vector<ll> max_row_indices;
  rep(i, 0, H - 1) {
    if (max_row_cnt == rows_cnt[i]) {
      max_row_indices.push_back(i);
    } else if (max_row_cnt < rows_cnt[i]) {
      max_row_indices.clear();
      max_row_indices.push_back(i);
      max_row_cnt = rows_cnt[i];
    }
  }

  ll max_column_cnt = 0;
  vector<ll> max_column_indices;
  rep(i, 0, W - 1) {
    if (max_column_cnt == columns_cnt[i]) {
      max_column_indices.push_back(i);
    } else if (max_column_cnt < columns_cnt[i]) {
      max_column_indices.clear();
      max_column_indices.push_back(i);
      max_column_cnt = columns_cnt[i];
    }
  }

  for (ll max_row_index : max_row_indices) {
    for (ll max_column_index : max_column_indices) {
      if (!rows[max_row_index][max_column_index]) {
        cout << max_row_cnt + max_column_cnt << endl;
        return 0;
      }
    }
  }

  cout << max_row_cnt + max_column_cnt - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007

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

  ll h, w, m;
  cin >> h >> w >> m;
  set<pair<ll, ll>> s;
  map<ll, ll> mp1, mp2;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    s.insert({x, y});
    mp1[x]++;
    mp2[y]++;
  }
  ll nx = -1, ny = -1;
  ll mx = -1;
  for (int i = 1; i <= h; i++) {
    if (mx < mp1[i]) {
      mx = mp1[i];
      nx = i;
    }
  }
  ll ans = 0;
  vector<int> rows;
  for (int i = 1; i <= h; i++) {
    if (mx == mp1[i]) {
      rows.pb(i);
    }
  }
  mx = -1;
  for (int i = 1; i <= w; i++) {
    if (mx < mp2[i]) {
      mx = mp2[i];
      ny = i;
    }
  }
  vector<int> cols;
  for (int i = 1; i <= w; i++) {
    if (mx == mp2[i]) {
      cols.pb(i);
    }
  }
  ans = mp1[nx] + mp2[ny] - 1;
  bool flag = 0;
  for (auto e : rows) {
    for (auto f : cols) {
      if (s.find({e, f}) == s.end()) {
        ans = mp1[e] + mp2[f];
        flag = 1;
        break;
      }
    }
    if (flag) {
      break;
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#include <string>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007

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

  int h, w, m;
  cin >> h >> w >> m;
  ll a[h + 1][w + 1];
  memset(a, 0, sizeof(a));
  map<ll, ll> mp1, mp2;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    a[x][y] = 1;
    mp1[x]++;
    mp2[y]++;
  }
  ll ans = 0;
  ll nx = -1, ny = -1;
  ll mx = -1;
  for (int i = 1; i <= h; i++) {
    if (mx < mp1[i]) {
      mx = mp1[i];
      nx = i;
    }
  }
  deb(mx);
  mx = -1;
  for (int i = 1; i <= w; i++) {
    if (mx < mp2[i]) {
      mx = mp2[i];
    }
  }
  for (int i = 1; i <= w; i++) {
    if (mx == mp2[i]) {
      if (a[nx][i] == 1) {
        ans = max(ans, mp1[nx] + mp2[i] - 1);
      } else {
        ans = max(ans, mp1[nx] + mp2[i]);
      }
    }
  }
  cout << ans;
}