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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define str to_string
#define endl "\\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}

// AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main() {
  int h, w, m, x, y;
  cin >> h >> w >> m;
  vector<int> bh(0);
  vector<int> bw(0);
  vector<int> height(h);
  vector<int> width(w);
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    height[x - 1]++;
    width[y - 1]++;
    bh.pb(x - 1);
    bw.pb(y - 1);
  }
  int hbest = *max_element(all(height)), wbest = *max_element(all(width));
  lint cross = count(all(height), hbest) * count(all(width), wbest);
  for (int i = 0; i < m; i++) {
    if (height[bh[i]] == hbest && width[bw[i]] == wbest)
      cross--;
  }
  int ans = hbest + wbest;
  if (cross == 0)
    ans--;
  cout << ans << endl;
}


Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define str to_string
#define endl "\\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
// AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main() {
  int h, w, m, x, y;
  cin >> h >> w >> m;
  vector<vector<bool>> bomb(h, vector<bool>(w, false));
  vector<int> height(h);
  vector<int> width(w);
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    height[x - 1]++;
    width[y - 1]++;
    bomb[x - 1][y - 1] = true;
  }
  int hbest = *max_element(all(height)), wbest = *max_element(all(width));
  vector<int> hkouho(0);
  vector<int> wkouho(0);
  for (int i = 0; i < h; i++) {
    if (hbest == height[i])
      hkouho.pb(i);
  }
  for (int i = 0; i < w; i++) {
    if (wbest == width[i])
      wkouho.pb(i);
  }
  bool tyoufuku = true;
  for (int i : hkouho) {
    if (tyoufuku == false)
      break;
    for (int j : wkouho) {
      if (bomb[i][j] == false) {
        tyoufuku = false;
        break;
      }
    }
  }
  int ans;
  if (tyoufuku)
    ans = hbest + wbest - 1;
  else
    ans = hbest + wbest;
  cout << ans << endl;
}
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<vector<int>> V(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> V.at(i).at(0) >> V.at(i).at(1);
  }

  vector<int> BH(H, 0);
  vector<int> BW(W, 0);

  for (int i = 0; i < M; i++) {
    BH.at(V.at(i).at(0) - 1)++;
    BW.at(V.at(i).at(1) - 1)++;
  }

  vector<int> HMI(0);
  vector<int> WMI(0);

  int mh = 0, mw = 0;
  for (int i = 0; i < H; i++) {
    mh = max(mh, BH.at(i));
  }

  for (int i = 0; i < W; i++) {
    mw = max(mw, BW.at(i));
  }

  int64_t ch = 0, cw = 0;
  for (int i = 0; i < H; i++) {
    if (BH.at(i) == mh) {
      ch++;
    }
  }

  for (int i = 0; i < W; i++) {
    if (BW.at(i) == mw) {
      cw++;
    }
  }

  int finish = 1;
  int64_t C = 0;

  for (int k = 0; k < M; k++) {
    if (BH.at(V.at(k).at(0) - 1) == mh && BW.at(V.at(k).at(1) - 1) == mw) {
      C++;
    }
  }
  if (cw * ch > C) {
    finish = 0;
  } else {
    finish = 1;
  }

  cout << mh + mw - finish << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<vector<int>> V(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> V.at(i).at(0) >> V.at(i).at(1);
  }

  vector<int> BH(H, 0);
  vector<int> BW(W, 0);

  for (int i = 0; i < M; i++) {
    BH.at(V.at(i).at(0) - 1)++;
    BW.at(V.at(i).at(1) - 1)++;
  }

  vector<int> HMI(0);
  vector<int> WMI(0);

  int MAX = 0;
  int mh = 0, mw = 0;
  for (int i = 0; i < H; i++) {
    mh = max(mh, BH.at(i));
  }
  MAX += mh;

  for (int i = 0; i < W; i++) {
    mw = max(mw, BW.at(i));
  }
  MAX += mw;

  for (int i = 0; i < H; i++) {
    if (BH.at(i) == mh) {
      HMI.push_back(i);
    }
  }

  for (int i = 0; i < W; i++) {
    if (BW.at(i) == mw) {
      WMI.push_back(i);
    }
  }

  int finish = 0;
  for (int i = 0; i < (int)HMI.size(); i++) {
    for (int j = 0; j < (int)WMI.size(); j++) {
      finish = 0;
      for (int k = 0; k < M; k++) {
        if (V.at(k).at(0) == HMI.at(i) + 1 && V.at(k).at(1) == WMI.at(j) + 1) {
          finish = 1;
          break;
        }
      }
      if (finish == 0) {
        break;
      }
    }
    if (finish == 0) {
      break;
    }
  }
  cout << MAX - finish << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;

map<pii, int> mp;
map<int, int> r, c;

inline void solve() {
  int h, w, t, rr = 0, cc = 0;
  cin >> h >> w >> t;
  for (int i = 0; i < t; i++) {
    int a, b;
    cin >> a >> b;
    r[a]++;
    c[b]++;
    rr = max(rr, r[a]);
    cc = max(cc, c[b]);
    mp[{a, b}] = 1;
  }
  int ans = rr + cc - 1;
  vector<int> row, col;
  for (auto &it : r)
    if (it.ss == rr)
      row.pb(it.ff);
  for (auto &it : c)
    if (it.ss == cc)
      col.pb(it.ff);
  for (int i = 0; i < sz(row); i++) {
    bool ok = false;
    for (int j = 0; j < sz(col); j++) {
      if (!mp[{row[i], col[j]}]) {
        ans = rr + cc;
        ok = true;
        break;
      }
    }
    if (ok)
      break;
  }
  cout << ans << endl;
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}


Error: TLE

Fixed submission:

/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;

map<pii, int> r, c, mp;

inline void solve() {
  int h, w, t;
  cin >> h >> w >> t;
  for (int i = 0; i < t; i++) {
    int a, b;
    cin >> a >> b;
    r[{a, b}] = 1;
    c[{a, b}] = 1;
    mp[{a, b}] = 1;
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      r[{i, j}] += r[{i, j - 1}];
    }
    for (int j = w - 1; j >= 1; j--) {
      r[{i, j}] = r[{i, j + 1}];
    }
  }
  for (int j = 1; j <= w; j++) {
    for (int i = 1; i <= h; i++)
      c[{i, j}] += c[{i - 1, j}];
    for (int i = h - 1; i > 0; i--)
      c[{i, j}] = c[{i + 1, j}];
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      ans = max(ans, r[{i, j}] + c[{i, j}] - mp[{i, j}]);
    }
  }
  cout << ans << endl;
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

bool inside(ll h, ll w, ll y, ll x) {
  return (0 <= y && y < h && 0 <= x && x < w);
}

int main() {
  ll h, w, m;
  cin >> h >> w >> m;

  vector<pair<ll, ll>> bomb(m);
  vector<ll> r(h);
  vector<ll> c(w);
  for (int i = 0; i < m; i++) {
    ll hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    bomb[i] = {hi, wi};
    r[hi]++;
    c[wi]++;
  }

  ll maxr = 0;
  ll maxc = 0;
  for (int i = 0; i < h; i++)
    maxr = max(maxr, r[i]);
  for (int i = 0; i < w; i++)
    maxc = max(maxc, c[i]);

  ll maxrcnt = 0;
  ll maxccnt = 0;
  for (int i = 0; i < h; i++) {
    if (r[i] == maxr)
      maxrcnt++;
  }
  for (int i = 0; i < w; i++) {
    if (c[i] == maxc)
      maxccnt++;
  }

  ll mcnt = 0;
  for (int i = 0; i < m; i++) {
    if (r[bomb[i].first] == maxr && c[bomb[i].second] == maxc) {
      mcnt++;
    }
  }

  if (mcnt == maxrcnt * maxccnt)
    cout << maxr + maxc - 1 << endl;
  else
    cout << maxr + maxc << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ll h, w, m;
  cin >> h >> w >> m;

  vector<vector<bool>> g(h, vector<bool>(w, false));
  vector<ll> hs(h, 0);
  vector<ll> ws(w, 0);

  for (ll i = 0; i < m; i++) {
    ll y, x;
    cin >> y >> x;
    y--;
    x--;
    g[y][x] = true;
    hs[y]++;
    ws[x]++;
  }

  ll ans = 0;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      ll sum = hs[i] + ws[j];
      if (g[i][j])
        sum--;
      ans = max(ans, sum);
    }
  }

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

const ll INF = 1e18;
const int MOD = 1e9 + 7;

int main() {

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

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

  vi row(H, 0), col(W, 0);
  vpi bomb(M);

  for (int i = 0; i < M; ++i) {
    int h, w;
    cin >> h >> w;
    --h, --w;
    bomb[i] = {h, w};
    ++row[h];
    ++col[w];
  }

  int mxRow = 0, mxCol = 0;
  for (auto x : row)
    mxRow = max(mxRow, x);
  for (auto x : col)
    mxCol = max(mxCol, x);

  ll cntMxRow = 0, cntMxCol = 0, cntBoth = 0;
  for (auto x : row)
    cntMxRow += (x == mxRow);
  for (auto x : col)
    cntMxCol += (x == mxCol);
  for (auto x : bomb)
    cntBoth += (row[x.f] == mxRow && col[x.s] == mxCol);

  if (cntMxRow * cntMxCol > cntBoth)
    cout << mxRow + mxCol << '\\n';
  else
    cout << mxRow + mxCol - 1 << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;

const ll INF = 1e18;
const int MOD = 1e9 + 7;

int main() {

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

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

  vector<vector<bool>> g(H, vector<bool>(W, false));
  vi col(W, 0), row(H, 0);
  int colMx = 0, rowMx = 0, colIdx = -1, rowIdx = -1;

  while (M--) {
    int j, i;
    cin >> j >> i;
    g[j - 1][i - 1] = true;
    ++col[i - 1], ++row[j - 1];
    if (row[j - 1] > rowMx)
      rowIdx = j - 1, rowMx = row[j - 1];
    if (col[i - 1] > colMx)
      colIdx = i - 1, colMx = col[i - 1];
  }

  cout << row[rowIdx] + col[colIdx] - (g[rowIdx][colIdx]) << "\\n";

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

#include <bits/stdc++.h>

using namespace std;
const int maxn = 3e5 + 111;
vector<int> tg[maxn], tg1[maxn], r, c;
int H, W, M, col[maxn], row[maxn];

bool cmp1(int i, int j) { return row[i] > row[j]; }

bool cmp2(int i, int j) { return col[i] > col[j]; }

int main() {
  memset(col, 0, sizeof(col));
  memset(row, 0, sizeof(row));
  scanf("%d%d%d", &H, &W, &M);
  for (int i = 1; i <= H; i++)
    r.push_back(i);
  for (int j = 1; j <= W; j++)
    c.push_back(j);
  int hi, wi;
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &hi, &wi);
    tg[hi].push_back(wi);
    tg1[wi].push_back(hi);
    col[wi]++;
    row[hi]++;
  }
  sort(r.begin(), r.end(), cmp1);
  sort(c.begin(), c.end(), cmp2);
  int ans = 0;
  int cnt = r[0];
  for (int j = 0; j < tg[cnt].size(); j++)
    col[tg[cnt][j]]--;
  int tmp = 0;
  for (int j = 1; j <= W; j++)
    tmp = max(tmp, col[j]);
  for (int j = 0; j < tg[cnt].size(); j++)
    col[tg[cnt][j]]++;
  ans = row[cnt] + tmp;

  cnt = c[0];
  tmp = 0;
  for (int j = 0; j < tg1[cnt].size(); j++)
    row[tg1[cnt][j]]--;
  for (int j = 1; j <= H; j++)
    tmp = max(tmp, row[j]);
  for (int j = 0; j < tg1[cnt].size(); j++)
    row[tg1[cnt][j]]++;
  ans = max(ans, col[cnt] + tmp);

  printf("%d", ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 3e5 + 111;
vector<int> tg[maxn];
int H, W, M, col[maxn], row[maxn];

int main() {
  memset(col, 0, sizeof(col));
  memset(row, 0, sizeof(row));
  scanf("%d%d%d", &H, &W, &M);
  int hi, wi;
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &hi, &wi);
    tg[hi].push_back(wi);
    col[wi]++;
    row[hi]++;
  }
  int ans = 0;
  for (int i = 1; i <= H; i++) {
    int cnt = row[i];
    int tmp = 0;
    for (int j = 0; j < tg[i].size(); j++)
      col[tg[i][j]]--;
    for (int j = 1; j <= W; j++)
      tmp = max(tmp, col[j]);
    for (int j = 0; j < tg[i].size(); j++)
      col[tg[i][j]]++;
    ans = max(ans, cnt + tmp);
  }
  printf("%d", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int t = 1;
  while (t--) {
    int h, w;
    cin >> h >> w;
    int m;
    cin >> m;
    int maxCol = 0, maxRow = 0;
    vector<int> hc(h + 1, 0), wc(w + 1, 0);
    map<pair<int, int>, int> mp;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> y >> x;
      hc[y]++;
      wc[x]++;
      maxCol = max(maxCol, hc[y]);
      maxRow = max(maxRow, wc[x]);
      mp[{y, x}]++;
    }

    vector<int> colsWithMax, rowsWithMax;

    for (int i = 1; i <= h; i++) {
      if (hc[i] == maxCol)
        colsWithMax.push_back(i);
    }

    for (int i = 1; i <= w; i++) {
      if (wc[i] == maxRow)
        rowsWithMax.push_back(i);
    }

    int ans = maxCol + maxRow - 1;

    for (auto i : colsWithMax) {
      for (auto j : rowsWithMax) {
        if (mp.find({i, j}) == mp.end()) {
          ans++;
          goto outer;
        }
      }
    }

  outer:
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int t = 1;
  while (t--) {
    int h, w;
    cin >> h >> w;
    int m;
    cin >> m;
    int maxCol = 0, maxRow = 0;
    vector<int> hc(h + 1, 0), wc(w + 1, 0);
    map<pair<int, int>, int> mp;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> y >> x;
      hc[y]++;
      wc[x]++;

      maxCol = max(maxCol, hc[y]);
      maxRow = max(maxRow, wc[x]);
      mp[{y, x}]++;
    }

    int ans = maxCol + maxRow - 1;
    for (int i = 0; i <= h; i++) {
      for (int j = 0; j <= w; j++) {
        if (hc[i] + wc[j] == ans + 1 && mp.find({i, j}) == mp.end()) {
          ans++;
          goto outer;
        }
      }
    }
  outer:
    cout << ans << endl;
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  // vector<vi> masu(h,vi(w,0));
  map<pair<int, int>, int> mp;
  vi tate_count(h, 0);
  vi yoko_count(w, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    yoko_count[b]++;
    tate_count[a]++;
    pair<int, int> kani = make_pair(a, b);
    mp[kani]++;
  }
  int maxi_t = 0;
  for (int i = 0; i < h; i++) {
    maxi_t = max(maxi_t, tate_count[i]);
  }
  int maxi_y = 0;
  for (int i = 0; i < w; i++) {
    maxi_y = max(maxi_y, yoko_count[i]);
  }
  int ans = maxi_y + maxi_t;
  vi yoko, tate;
  for (int i = 0; i < h; i++) {
    if (maxi_t == tate_count[i])
      tate.push_back(i);
  }
  for (int i = 0; i < w; i++) {
    if (maxi_y == yoko_count[i])
      yoko.push_back(i);
  }
  bool flag = false;
  if (tate.size() * yoko.size() > 1e9) {
    cout << ans << endl;
    return 0;
  }
  for (auto x : yoko) {
    for (auto y : tate) {
      pair<int, int> ebi = make_pair(y, x);
      if (mp[ebi] == 0)
        flag = true;
    }
  }
  if (!flag)
    ans--;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  // vector<vi> masu(h,vi(w,0));
  map<pair<int, int>, int> mp;
  vi tate_count(h, 0);
  vi yoko_count(w, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    yoko_count[b]++;
    tate_count[a]++;
    pair<int, int> kani = make_pair(a, b);
    mp[kani]++;
  }
  int maxi_t = 0;
  for (int i = 0; i < h; i++) {
    maxi_t = max(maxi_t, tate_count[i]);
  }
  int maxi_y = 0;
  for (int i = 0; i < w; i++) {
    maxi_y = max(maxi_y, yoko_count[i]);
  }
  int ans = maxi_y + maxi_t;
  vi yoko, tate;
  for (int i = 0; i < h; i++) {
    if (maxi_t == tate_count[i])
      tate.push_back(i);
  }
  for (int i = 0; i < w; i++) {
    if (maxi_y == yoko_count[i])
      yoko.push_back(i);
  }
  bool flag = false;
  for (auto x : yoko) {
    for (auto y : tate) {
      pair<int, int> ebi = make_pair(y, x);
      if (mp[ebi] == 0)
        flag = true;
    }
  }
  if (!flag)
    ans--;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef unsigned long long ll;
const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int HASH = 131;

int h[maxn];
int w[maxn];
map<pair<int, int>, int> mp;
struct node {
  int num, id;
  friend bool operator<(node a, node b) { return a.num < b.num; }
};

node x[maxn], y[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    int a, b;
    cin >> a >> b;
    h[a]++;
    w[b]++;
    mp[make_pair(a, b)] = 1;
  }
  for (int i = 1; i <= n; i++) {
    y[i].num = h[i];
    y[i].id = i;
  }
  for (int i = 1; i <= m; i++) {
    x[i].num = w[i];
    x[i].id = i;
  }
  sort(y + 1, y + 1 + n);
  sort(x + 1, x + 1 + m);
  int max_y = y[n].num;
  int max_x = x[m].num;
  int sign = 1;
  for (int i = n; i >= 1; i--) {
    if (y[i].num != max_y)
      break;
    for (int j = m; j >= 1; j--) {
      if (x[j].num != max_x)
        break;
      if (mp[make_pair(y[i].id, x[j].id)] == 0) {
        sign = 0;
        break;
      }
    }
    if (sign == 0)
      break;
  }
  if (sign == 0)
    printf("%d\\n", max_y + max_x);
  else
    printf("%d\\n", max_y + max_x - 1);
  return 0;
}


Error: 127
/tmp/458338fd-72ff-4ecb-ab71-b959e2102493.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef unsigned long long ll;
const int maxn = 1e4 + 50;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int HASH = 131;

int h[maxn];
int w[maxn];
bool mp[maxn][maxn];
struct node {
  int num, id;
  friend bool operator<(node a, node b) { return a.num < b.num; }
};

node x[maxn], y[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    int a, b;
    cin >> a >> b;
    h[a]++;
    w[b]++;
    mp[a][b] = 1;
  }
  for (int i = 1; i <= n; i++) {
    y[i].num = h[i];
    y[i].id = i;
  }
  for (int i = 1; i <= m; i++) {
    x[i].num = w[i];
    x[i].id = i;
  }
  sort(y + 1, y + 1 + n);
  sort(x + 1, x + 1 + m);
  int max_y = y[n].num;
  int max_x = x[m].num;
  int sign = 1;
  for (int i = n; i >= 1; i--) {
    if (y[i].num != max_y)
      break;
    for (int j = m; j >= 1; j--) {
      if (x[j].num != max_x)
        break;
      if (mp[y[i].id][x[j].id] == 0) {
        sign = 0;
        break;
      }
    }
    if (sign == 0)
      break;
  }
  if (sign == 0)
    printf("%d\\n", max_y + max_x);
  else
    printf("%d\\n", max_y + max_x - 1);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

  ll maxh = 0;
  ll maxw = 0;
  set<pair<int, int>> st;

  vec<ll> h(M), w(M), hb(H), wb(W);
  rep(i, M) {
    cin >> h[i] >> w[i];
    --h[i], --w[i];
    ++hb[h[i]], ++wb[w[i]];
    maxh = max(maxh, hb[h[i]]);
    maxw = max(maxw, wb[w[i]]);
    st.insert({h[i], w[i]});
  }
  vec<ll> maxhs, maxws;
  rep(i, H) if (hb[i] == maxh) maxhs.push_back(i);
  rep(i, W) if (wb[i] == maxw) maxws.push_back(i);
  for (auto e : maxhs) {
    for (auto j : maxws) {
      if (st.count({e, j}) == 0) {
        cout << maxh + maxw << endl;
        return 0;
      }
    }
  }
  cout << maxh + maxw - 1 << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

  ll maxh = 0;
  ll maxw = 0;

  vec<ll> h(H), w(W), hb(H), wb(W);
  vec<vec<ll>> hs(H), ws(W);
  rep(i, M) {
    cin >> h[i] >> w[i];
    --h[i], --w[i];
    ++hb[h[i]], ++wb[w[i]];
    hs[h[i]].push_back(w[i]);
    ws[w[i]].push_back(h[i]);
    maxh = max(maxh, hb[h[i]]);
    maxw = max(maxw, wb[w[i]]);
  }
  sort(all(hs));
  vec<ll> maxhs, maxws;
  rep(i, H) if (hb[i] == maxh) maxhs.push_back(i);
  rep(i, W) if (wb[i] == maxw) maxws.push_back(i);
  for (auto e : maxhs)
    for (auto j : maxws) {
      bool flag = true;
      rep(i, hs[e].size()) {
        if (hs[e][i] == j) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << maxh + maxw << endl;
        return 0;
      }
    }
  cout << maxh + maxw - 1 << endl;
}