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

#include <bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x[c + 50], y[c + 50], mx = 0, my = 0, cntx[a + 50] = {0},
                            cnty[b + 50] = {0};
  for (int i = 0; i < c; i++) {
    cin >> x[i] >> y[i];
    cntx[x[i]]++;
    mx = max(mx, cntx[x[i]]);
    cnty[y[i]]++;
    my = max(my, cnty[y[i]]);
  }
  int t1 = 0, t2 = 0;
  for (int i = 1; i <= a; i++)
    if (cntx[i] == mx)
      t1++;
  for (int i = 1; i <= b; i++)
    if (cnty[i] == my)
      t2++;
  int t = t1 * t2;
  for (int i = 0; i < c; i++) {
    if (cntx[x[i]] == mx && cnty[y[i]] == my)
      t--;
  }
  if (t)
    cout << mx + my;
  else
    cout << mx + my - 1;
  cout << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int cntx[300050], cnty[300050];
int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<pair<int, int>, bool> M;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    M[make_pair(x, y)] = true;
    cntx[x]++;
    cnty[y]++;
  }
  int ans = 0;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      ans = max(ans, cntx[i] + cnty[j] - M[make_pair(i, j)]);
  cout << ans << '\\n';
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int n, m, k;
  cin >> n >> m >> k;

  int r[n + 1], c[m + 1];
  map<pair<int, int>, int> grid;

  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);

  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    grid[make_pair(x, y)] = 1;
    r[x]++, c[y]++;
  }
  int x, y;

  int temp = -1;
  for (int i = 1; i <= n; i++)
    if (temp < r[i]) {
      temp = r[i];
      x = i;
    }
  vector<int> xs, ys;
  for (int i = 1; i <= n; i++)
    if (r[i] == temp)
      xs.push_back(i);
  temp = -1;

  for (int i = 1; i <= m; i++)
    if (temp < c[i]) {
      temp = c[i];
      y = i;
    }
  for (int i = 1; i <= m; i++)
    if (c[i] == temp)
      ys.push_back(i);
  int ans = 0;
  bool f = false;
  for (int x : xs) {
    for (int y : ys) {
      int temp = r[x] + c[y];
      if (!grid[make_pair(x, y)]) {
        ans = temp;
        f = true;
        break;
      } else
        ans = temp - 1;
    }
    if (f)
      break;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

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

  int n, m, k;
  cin >> n >> m >> k;

  int r[n + 1], c[m + 1];
  map<pair<int, int>, int> grid;

  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);

  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    grid[make_pair(x, y)] = 1;
    r[x]++, c[y]++;
  }
  int x, y;

  int temp = -1;
  for (int i = 1; i <= n; i++)
    if (temp < r[i]) {
      temp = r[i];
      x = i;
    }
  vector<int> xs, ys;
  for (int i = 1; i <= n; i++)
    if (r[i] == temp)
      xs.push_back(i);
  temp = -1;

  for (int i = 1; i <= m; i++)
    if (temp < c[i]) {
      temp = c[i];
      y = i;
    }
  for (int i = 1; i <= m; i++)
    if (c[i] == temp)
      ys.push_back(i);
  int ans = 0;

  for (int x : xs) {
    for (int y : ys) {
      int temp = r[x] + c[y];
      if (grid[make_pair(x, y)] == 1)
        temp--;
      ans = max(ans, temp);
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  map<pair<int, int>, int> mp;
  int h, w, m;
  cin >> h >> w >> m;
  vector<pair<int, int>> row(h), col(w);

  rep(i, h) row[i] = make_pair(0, i);
  rep(j, w) col[j] = make_pair(0, j);

  int ht, wt;
  rep(i, m) {
    cin >> ht >> wt;
    --ht;
    --wt;
    mp[make_pair(ht, wt)] = 1;
    row[ht].first++;
    col[wt].first++;
  }

  sort(row.begin(), row.end(), greater<pair<int, int>>());
  sort(col.begin(), col.end(), greater<pair<int, int>>());

  int rt = row[0].first, ct = col[0].first, cnt = 0;
  int ans = rt + ct - mp[make_pair(row[0].second, col[0].second)];
  for (int i = 0; row[i].first == rt && cnt <= m + 1; ++i) {
    for (int j = 0; col[j].first == ct && cnt <= m + 1; ++j) {
      ht = row[i].second, wt = col[j].second;
      int tmp = row[i].first + col[j].first - mp[make_pair(ht, wt)];
      if (ans < tmp) {
        ans = tmp;
        break;
      }
      cnt++;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  map<pair<int, int>, int> mp;
  int h, w, m;
  cin >> h >> w >> m;
  vector<pair<int, int>> row(h), col(w);

  rep(i, h) row[i] = make_pair(0, i);
  rep(j, w) col[j] = make_pair(0, j);

  int ht, wt;
  rep(i, m) {
    cin >> ht >> wt;
    --ht;
    --wt;
    mp[make_pair(ht, wt)] = 1;
    row[ht].first++;
    col[wt].first++;
  }

  sort(row.begin(), row.end(), greater<pair<int, int>>());
  sort(col.begin(), col.end(), greater<pair<int, int>>());

  int rt = row[0].first, ct = col[0].first, cnt = 0;
  int ans = rt + ct - mp[make_pair(row[0].second, col[0].second)];
  for (int i = 0; row[i].first == rt && cnt <= m + 1; ++i) {
    for (int j = 0; col[j].first == ct && cnt <= m + 1; ++j) {
      ht = row[i].second, wt = col[j].second;
      int tmp = row[i].first + col[j].first - mp[make_pair(ht, wt)];
      if (ans < tmp) {
        ans = tmp;
        break;
      }
      if (mp[make_pair(ht, wt)] == 1)
        cnt++;
    }
  }

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

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

*/
map<pair<ll, ll>, ll> MP;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> Y(M, 0), X(M, 0), YM(H, 0), XM(W, 0);
  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    YM[h - 1]++;
    XM[w - 1]++;
    Y[i] = h;
    X[i] = w;
    MP[{h, w}]++;
  }
  ll ans = 0, tmp = 0;
  vector<ll> YK(0, 0), XK(0, 0);
  rep(i, H) tmp = max(tmp, YM[i]);
  ans += tmp;
  // cout<<"1tmp:"<<tmp<<endl;
  rep(i, H) if (YM[i] == tmp) YK.push_back(i);
  tmp = 0;
  rep(i, W) tmp = max(tmp, XM[i]);
  // cout<<"2tmp:"<<tmp<<endl;
  ans += tmp;
  rep(i, W) if (XM[i] == tmp) XK.push_back(i);
  ll xs = XK.size(), ys = YK.size();
  bool dup = true;
  rep(i, ys) rep(j, xs) {
    if (MP[{YK[i] + 1, XK[j] + 1}] == 0) {
      dup = false;
      break;
    }
  }
  if (dup)
    ans--;
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

*/
map<pair<ll, ll>, ll> MP;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> Y(M, 0), X(M, 0), YM(H, 0), XM(W, 0);
  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    YM[h - 1]++;
    XM[w - 1]++;
    Y[i] = h;
    X[i] = w;
    MP[{h, w}]++;
  }
  ll ans = 0, tmp = 0;
  vector<ll> YK(0, 0), XK(0, 0);
  rep(i, H) tmp = max(tmp, YM[i]);
  ans += tmp;
  // cout<<"1tmp:"<<tmp<<endl;
  rep(i, H) if (Y[i] == tmp) YK.push_back(Y[i]);
  tmp = 0;
  rep(i, W) tmp = max(tmp, XM[i]);
  // cout<<"2tmp:"<<tmp<<endl;
  ans += tmp;
  rep(i, W) if (X[i] == tmp) XK.push_back(X[i]);
  ll xs = XK.size(), ys = YK.size();
  bool dup = true;
  rep(i, ys) rep(j, xs) {
    if (MP[{YK[i], XK[j]}] == 0) {
      dup = false;
      break;
    }
  }
  if (dup)
    ans--;
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

map<int, map<int, int>> mp;

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

  int H, W, m;
  cin >> H >> W >> m;
  vector<int> h(m), w(m);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    h[i] = x;
    w[i] = y;
    mp[x][y] = 1;
  }
  vector<int> yoko(H, 0), tate(W, 0);
  vector<vector<int>> a(H), b(W);
  rep(i, m) {
    ++yoko[h[i]];
    ++tate[w[i]];
    a[h[i]].push_back(w[i]);
    b[w[i]].push_back(h[i]);
  }
  int maxt = 0, maxy = 0;
  rep(i, H) { maxy = max(maxy, yoko[i]); }
  rep(i, W) { maxt = max(maxt, tate[i]); }
  vector<int> t, y;
  rep(i, H) {
    if (yoko[i] == maxy)
      y.push_back(i);
  }
  rep(i, W) {
    if (tate[i] == maxt)
      t.push_back(i);
  }
  ll cnt = y.size() * t.size();
  ll mm = m;
  if (cnt > mm) {
    cout << maxy + maxt << "\\n";
    return 0;
  }
  bool ok = true;
  for (auto u : y) {
    for (auto v : t) {
      if (mp[u][v] == 0) {
        cout << maxt + maxy << "\\n";
        return 0;
      }
    }
  }
  cout << maxt + maxy - 1 << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

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

  int H, W, m;
  cin >> H >> W >> m;
  vector<int> h(m), w(m);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    h[i] = x;
    w[i] = y;
  }
  vector<int> yoko(H, 0), tate(W, 0);
  vector<vector<int>> a(H);
  rep(i, m) {
    ++yoko[h[i]];
    a[h[i]].push_back(w[i]);
  }
  rep(i, m) { ++tate[w[i]]; }
  int maxt = 0, maxy = 0;
  rep(i, H) { maxy = max(maxy, yoko[i]); }
  rep(i, W) { maxt = max(maxt, tate[i]); }
  vector<int> t, y;
  rep(i, H) {
    if (yoko[i] == maxy)
      y.push_back(i);
  }
  rep(i, W) {
    if (tate[i] == maxt)
      t.push_back(i);
  }
  ll cnt = y.size() * t.size();
  ll mm = m;
  if (cnt > mm) {
    cout << maxy + maxt << "\\n";
    return 0;
  }
  for (auto v : t) {
    for (auto r : y) {
      bool ok = false;
      for (auto u : a[r]) {
        if (v == u) {
          ok = true;
          break;
        }
      }
      if (ok)
        continue;
      else {
        cout << maxy + maxt << "\\n";
        return 0;
      }
    }
  }
  cout << maxt + maxy - 1 << "\\n";
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const int n = 300005;

void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hd(h + 1, 0);
  vector<int> wd(w + 1, 0);

  set<pair<int, int>> st;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    hd[x]++;
    wd[y]++;
    st.insert({x, y});
  }

  vector<int> hv;
  vector<int> wv;

  int hx = *max_element(hd.begin(), hd.end());
  int wx = *max_element(wd.begin(), wd.end());

  for (int i = 1; i <= h; i++)
    if (hd[i] == hx)
      hv.push_back(i);
  for (int i = 1; i <= w; i++)
    if (wd[i] == wx)
      wv.push_back(i);

  for (int i : hv) {
    for (int j : wv) {
      if (st.find({i, j}) == st.end()) {
        cout << hx + wx << "\\n";
        return;
      }
    }
  }

  cout << hx + wx - 1 << "\\n";
}

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const int n = 300005;

void solve() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hd(h + 1, 0);
  vector<int> wd(w + 1, 0);

  set<pair<int, int>> st;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    hd[x]++;
    wd[y]++;
    st.insert({x, y});
  }

  int hx = *max_element(hd.begin(), hd.end());
  int wx = *max_element(wd.begin(), wd.end());

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (hd[i] == hx && wd[j] == wx && st.find({i, j}) == st.end()) {
        cout << hx + wx << "\\n";
        return;
      }
    }
  }

  cout << hx + wx - 1 << "\\n";
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll, ll>

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, t, n) for (ll i = (t); i < (n); i++)
#define FORD(i, t, n) for (ll i = (n); i >= t; i--)
#define ALL(x) x.begin(), x.end()
#define asort(x) sort(ALL(x))

ll row[300100], col[300100];
ll X[300100], Y[300100];
ll vr[300100], vc[300100];

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> R, C;
  ll rm = 0, cm = 0;
  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    row[h]++;
    col[w]++;
    X[i] = h;
    Y[i] = w;
  }
  rep(i, H + 1) {
    if (row[i] > rm) {
      rm = row[i];
      R.clear();
      R.push_back(i);
    } else if (row[i] == rm) {
      R.push_back(i);
    }
  }
  rep(i, W + 1) {
    if (col[i] > cm) {
      cm = col[i];
      C.clear();
      C.push_back(i);
    } else if (col[i] == cm) {
      C.push_back(i);
    }
  }
  rep(i, R.size()) { vr[R[i]] = 1; }
  rep(i, C.size()) { vc[C[i]] = 1; }
  int cnt = 0;
  rep(i, M) {
    if (vr[X[i]] && vc[Y[i]])
      cnt++;
  }
  if (cnt == R.size() * C.size())
    cout << rm + cm - 1 << endl;
  else
    cout << rm + cm << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll, ll>

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, t, n) for (ll i = (t); i < (n); i++)
#define FORD(i, t, n) for (ll i = (n); i >= t; i--)
#define ALL(x) x.begin(), x.end()
#define asort(x) sort(ALL(x))

int main() {
  ll H, W, M;
  ll line_max = 0, row_max = 0;
  cin >> H >> W >> M;
  bool table[H + 1][W + 1];
  vector<ll> line(H + 1), row(W + 1);
  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    line[h]++;
    row[w]++;
    if (line[line_max] < line[h])
      line_max = h;
    if (row[row_max] < row[w])
      row_max = w;
    table[h][w] = true;
  }
  ll res = line[line_max] + row[row_max];
  if (table[line_max][row_max])
    res--;
  cout << res << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x[c + 50], y[c + 50], mx = 0, my = 0, cntx[a + 50] = {0},
                            cnty[b + 50] = {0};
  for (int i = 0; i < c; i++) {
    cin >> x[i] >> y[i];
    cntx[x[i]]++;
    mx = max(mx, cntx[x[i]]);
    cnty[y[i]]++;
    my = max(my, cnty[y[i]]);
  }
  int t1 = 0, t2 = 0;
  for (int i = 1; i <= a; i++)
    if (cntx[i] == mx)
      t1++;
  for (int i = 1; i <= b; i++)
    if (cnty[i] == my)
      t2++;
  int t = t1 * t2;
  for (int i = 0; i < c; i++) {
    if (cntx[x[i]] == mx && cnty[y[i]] == my)
      t--;
  }
  if (t)
    cout << mx + my;
  else
    cout << mx + my - 1;
  cout << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e9 + 7
#define pll pair<ll, ll>
#define ff first
#define ss second
#define PI acos(-1)
#define prm 998244353
#define endl '\\n'
using namespace std;
ll h, w, m;

int main() {
  fastio;
  ll T = 1;
  // cin>>T;
  while (T--) {
    cin >> h >> w >> m;
    ll x, y;
    ll col[h + 2][w + 2];
    ll b[h + 2][w + 2];
    ll row[h + 2][w + 2];
    for (ll i = 0; i <= h + 1; i++)
      for (ll j = 0; j <= w + 1; j++)
        col[i][j] = 0, row[i][j] = 0, b[i][j] = 0;
    ;
    for (ll i = 0; i < m; i++) {
      cin >> x >> y;
      row[x][y] = 1;
      col[x][y] = 1;
      b[x][y] = 1;
    }

    for (ll i = 1; i <= h; i++) {
      for (ll j = 1; j <= w; j++) {
        if (b[i][j] == 1)
          row[i][j] = row[i][j - 1] + 1;
        else
          row[i][j] = row[i][j - 1];
      }
    }
    for (ll i = 1; i <= w; i++) {
      for (ll j = 1; j <= h; j++) {
        if (b[j][i] == 1)
          col[j][i] = col[j - 1][i] + 1;
        else
          col[j][i] = col[j - 1][i];
      }
    }
    /*for(ll i=1;i<=h;i++)
    {
            for(ll j=1;j<=w;j++)
            {
                    cout<<col[i][j]<<" ";
            }
            cout<<endl;
    }*/
    ll ans = 0;
    for (ll i = 1; i <= h; i++) {
      for (ll j = 1; j <= w; j++) {
        ll tmp = row[i][w] + col[j][h];
        if (b[i][j] == 1)
          tmp--;
        ans = max(ans, tmp);
        //
      }
    }
    cout << ans << endl;
  }
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); 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() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> cntH(H), cntW(W), bombH(M), bombW(M);
  int max_h = -1, max_w = -1;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    cntH[a]++, cntW[b]++;
    chmax(max_h, cntH[a]);
    chmax(max_w, cntW[b]);
    bombH[i] = a, bombW[i] = b;
  }
  int res = max_h + max_w;
  ll maxh_cnt = 0, maxw_cnt = 0, closs_cnt = 0;

  rep(i, H) {
    if (cntH[i] == max_h)
      maxh_cnt++;
  }
  rep(i, W) {
    if (cntW[i] == max_w)
      maxw_cnt++;
  }

  rep(i, M) {
    int a = bombH[i], b = bombW[i];
    if (cntH[a] == max_h && cntW[b] == max_w)
      closs_cnt++;
  }
  if (closs_cnt == maxh_cnt * maxw_cnt)
    res--;
  cout << res << ln;
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rept(i, j, n) for (int i = (j); 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() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> maxH(H), maxW(W);
  ll gyoretu[H][W];
  rep(i, H) rep(j, W) gyoretu[H][W] = 0;
  map<pii, int> mp;
  int mxh = -1;
  int mxw = -1;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    maxH[a]++;
    chmax(mxh, maxH[a]);
    maxW[b]++;
    chmax(mxw, maxW[b]);
    mp[{a, b}] = 1;
  }
  int res = mxh + mxw;
  ll cnt1 = 0, cnt2 = 0, cnt3 = 0;

  rep(i, H) {
    if (maxH[i] == mxh)
      cnt1++;
  }
  rep(i, W) {
    if (maxW[i] == mxw)
      cnt2++;
  }
  ll sumcnt = cnt1 * cnt2;
  for (auto m : mp) {
    int a = m.first.first, b = m.first.second;
    if (maxH[a] == mxh && maxW[b] == mxw)
      cnt3++;
  }
  if (cnt3 == sumcnt)
    res--;
  /*cout << mxh << " " << mxw << ln;
  cout << sumcnt << " " << cnt3 << ln;*/
  cout << res << ln;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

const int MAXN = 300005;
int X[MAXN], Y[MAXN];
struct square {
  int x, y;
} sq[MAXN];

int main() {
  // 1.输入
  int H, W, M;
  scanf("%d%d%d", &H, &W, &M);
  // 2.统计目标
  int max_x = 0, max_y = 0;
  int u, v;
  for (int i = 1; i <= M; ++i) {
    scanf("%d%d", &u, &v);
    ++X[u];
    ++Y[v];
    sq[i].x = u;
    sq[i].y = v;
  }
  // 3.搜索最大目标数
  for (int i = 1; i <= H; ++i)
    if (X[i] > max_x)
      max_x = X[i];
  for (int i = 1; i <= W; ++i)
    if (Y[i] > max_y)
      max_y = Y[i];
  // 4.找出最大行数
  int x_ = 0, y_ = 0;
  for (int i = 1; i <= H; ++i)
    if (X[i] == max_x)
      x_++;
  for (int i = 1; i <= W; i++)
    if (Y[i] == max_y)
      y_++;
  int cnt = 0;
  for (int i = 1; i <= M; ++i)
    if (X[sq[i].x] == max_x && Y[sq[i].y] == max_y)
      ++cnt;
  if (cnt == x_ * y_)
    printf("%d", max_x + max_y - 1);
  else
    printf("%d", max_x + max_y);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

const int MAXN = 300005;
int X[MAXN], Y[MAXN];
struct square {
  int x, y;
} sq[MAXN];

int main() {
  // 1.输入
  int H, W, M;
  scanf("%d%d%d", &H, &W, &M);
  // 2.统计目标
  int max_x = 0, max_y = 0;
  int u, v;
  for (int i = 1; i <= M; ++i) {
    scanf("%d%d", &u, &v);
    ++X[u];
    ++Y[v];
    sq[i].x = u;
    sq[i].y = v;
  }
  // 3.搜索最大目标数
  for (int i = 1; i <= H; ++i)
    if (X[i] > max_x)
      max_x = X[i];
  for (int i = 1; i <= W; ++i)
    if (Y[i] > max_y)
      max_y = Y[i];

  int warn = 0; // 是否存在多组最大值且存在不重复的最大值
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j) {
      int flag = 0; // 判断炸弹是否放在目标上
      if (X[i] == max_x && Y[j] == max_y) {
        for (int k = 1; k <= M; k++)
          if (i == sq[k].x && j == sq[k].y)
            flag = 1;
        if (flag == 0)
          warn = 1;
      }
    }
  if (warn == 1)
    printf("%d", max_x + max_y);
  else
    printf("%d", max_x + max_y - 1);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INFTY 10000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int, int>;
typedef long long int ll;
const int MOD = 1000000007;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hs(h, 0), ws(w, 0);
  set<P> s;
  rep(i, m) {
    int c, r;
    cin >> c >> r;
    --c;
    --r;
    hs[c]++;
    ws[r]++;
    s.emplace(c, r);
  }
  vector<int> is, js;
  int mi = 0, mj = 0;
  rep(i, h) mi = max(mi, hs[i]);
  rep(j, w) mj = max(mj, ws[j]);
  rep(i, h) if (mi == hs[i]) is.emplace_back(i);
  rep(j, w) if (mj == ws[j]) js.emplace_back(j);

  int ans = mi + mj;
  for (int i : is)
    for (int j : js) {
      if (s.count(P(i, j)))
        continue;
      cout << ans << endl;
      return 0;
    }
  ans--;
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define INFTY 1 << 20
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
using ipair = pair<int, int>;
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int hn, wn, m;
  cin >> hn >> wn >> m;
  vector<int> h(m), w(m);
  vector<int> retu(wn, 0), gyo(hn, 0);
  vector<vector<int>> s(hn, vector<int>(wn, 0));
  rep(i, m) {
    cin >> h[i] >> w[i];
    --h[i];
    --w[i];
    retu[w[i]]++;
    gyo[h[i]]++;
    s[h[i]][w[i]] = 1;
  }
  int ans = 0;
  auto iter = max_element(retu.begin(), retu.end());
  ans = retu[iter - retu.begin()];
  vector<int> rr;
  rep(i, wn) {
    if (retu[i] == retu[iter - retu.begin()])
      rr.emplace_back(i);
  }
  int mx = 0;
  int sz = rr.size();
  rep(i, sz) {
    rep(j, hn) {
      if (s[j][rr[i]] == 1)
        mx = max(mx, gyo[j] - 1);
      else
        mx = max(mx, gyo[j]);
    }
  }
  ans += mx;
  cout << ans << endl;
  return 0;
}