Problem p02580 (C++) — buggy submission, verdict: Runtime Error


// Problem : E - Bomber
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_e
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define endl '\\n'
#define pb push_back
#define int long long
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define fill(a, b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i, x, y) for (int i = (int)x; i < y; i++)
#define px(a)                                                                  \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << '\\n';
#define pxy(a, n) rep(i, 0, n){px(a[i])};
/*_________________________________________________________*/

const long long MOD = 1e9 + 7, N = 1e5 + 5;
int solve() {
  int n, m, t, ans = 0;
  cin >> n >> m >> t;
  int row[n], col[m];
  map<pii, int> a;
  fill(row, 0);
  fill(col, 0);
  rep(i, 0, t) {
    int x, y;
    cin >> x >> y;
    row[x - 1]++;
    col[y - 1]++;
    a[{x - 1, y - 1}] = 1;
  }
  int mxr = *max_element(row, row + n);
  int mxc = *max_element(col, col + m);
  vi v1, v2;
  rep(i, 0, n) if (row[i] == mxr) v1.pb(i);
  rep(i, 0, m) if (col[i] == mxc) v2.pb(i);
  for (int x : v1)
    for (int y : v2)
      if (a[{x, y}] == 0)
        return (mxr + mxc);
  return mxr + mxc - 1;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    // solve();
    cout << solve() << endl;
  // cout<<(solve()?"YES":"NO")<<endl;
}

Error: 0

Fixed submission:


// Problem : E - Bomber
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_e
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define endl '\\n'
#define pb push_back
#define int long long
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define fill(a, b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i, x, y) for (int i = (int)x; i < y; i++)
#define px(a)                                                                  \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << '\\n';
#define pxy(a, n) rep(i, 0, n){px(a[i])};
/*_________________________________________________________*/

const long long MOD = 1e9 + 7, N = 1e5 + 5;
int solve() {
  int n, m, t, ans = 0;
  cin >> n >> m >> t;
  int a[n][m];
  fill(a, 0);
  int row[n], col[m];
  fill(row, 0);
  fill(col, 0);
  rep(i, 0, t) {
    int x, y;
    cin >> x >> y;
    row[x - 1]++;
    col[y - 1]++;
    a[x - 1][y - 1] = 1;
  }
  rep(i, 0, n) rep(j, 0, m) {
    int temp = row[i] + col[j] - (a[i][j] == 1);
    ans = max(ans, temp);
  }
  return ans;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    // solve();
    cout << solve() << endl;
  // cout<<(solve()?"YES":"NO")<<endl;
}