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

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

template <typename T>
void print_vec(const vector<T> &v, bool is_reverse = false, ll num = 0) {
  if (num == 0)
    num = (ll)v.size();
  if (is_reverse)
    for (ll i = num - 1; i >= 0; i--) {
      cout << v[i];
      if (i != 0)
        cout << " ";
    }
  else
    for (ll i = 0; i < num; i++) {
      cout << v[i];
      if (i != num - 1)
        cout << " ";
    }
  cout << endl;
}

template <typename T> void print_pairvec(const vector<T> &v, ll num = 0) {
  if (num == 0)
    num = (ll)v.size();
  cout << endl;
  for (ll i = 0; i < num; i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}

template <typename T> void print_vec2(const vector<vector<T>> &v) {
  cout << endl;
  cout << "       ";
  for (ll i = 0; i < v[0].size(); i++)
    cout << i << "   ";
  cout << endl;
  for (ll i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   ";
    for (ll j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\\x1B[31m" << v[i][j]
             << "   "; // https://stackoverrun.com/ja/q/12618775
    }
    cout << "\\x1B[0m" << endl;
  }
}

// const int SIZE = 3e5+1;
// vector<vector<bool>> is_bomb(SIZE, vector<bool>(SIZE, false));
bool is_bomb[1][1];
int main() {
  ll H, W;
  cin >> H >> W;
  ll M;
  cin >> M;

  // vector<vector<bool>> is_bomb(H, vector<bool>(W, false));//
  // 配列がでかすぎるとREになるらしい  かわりにmapでやってみる
  using P = pair<int, int>;
  map<P, int> mp;
  vector<ll> num_h(H, 0), num_w(W, 0);
  for (ll i = 0; i < M; i++) {
    ll h, w;
    cin >> h >> w;
    h--;
    w--;
    // is_bomb[h][w] = true;
    mp[P(h, w)]++;
    num_h[h]++;
    num_w[w]++;
  }

  ll h_num_max = 0, w_num_max = 0;
  for (ll i = 0; i < H; i++)
    h_num_max = max(h_num_max, num_h[i]);
  for (ll i = 0; i < W; i++)
    w_num_max = max(w_num_max, num_w[i]);

  vector<ll> maxs_h, maxs_w;
  for (ll i = 0; i < H; i++)
    if (num_h[i] == h_num_max)
      maxs_h.emplace_back(i);
  for (ll i = 0; i < W; i++)
    if (num_w[i] == w_num_max)
      maxs_w.emplace_back(i);

  ll ans = 0;
  for (ll i = 0; i < (ll)maxs_h.size(); i++) {
    for (ll j = 0; j < (ll)maxs_w.size(); j++) {
      ll tmp = num_h[maxs_h[i]] + num_w[maxs_w[j]];
      // if(is_bomb[maxs_h[i]][maxs_w[j]] == true) tmp--;
      if (mp[P(maxs_h[i], maxs_w[j])])
        tmp--;
      else {
        cout << tmp << endl;
        return 0;
      }
      ans = max(ans, tmp);
    }
  }

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


Error: WA

Fixed submission:

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

template <typename T>
void print_vec(const vector<T> &v, bool is_reverse = false, ll num = 0) {
  if (num == 0)
    num = (ll)v.size();
  if (is_reverse)
    for (ll i = num - 1; i >= 0; i--) {
      cout << v[i];
      if (i != 0)
        cout << " ";
    }
  else
    for (ll i = 0; i < num; i++) {
      cout << v[i];
      if (i != num - 1)
        cout << " ";
    }
  cout << endl;
}

template <typename T> void print_pairvec(const vector<T> &v, ll num = 0) {
  if (num == 0)
    num = (ll)v.size();
  cout << endl;
  for (ll i = 0; i < num; i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}

template <typename T> void print_vec2(const vector<vector<T>> &v) {
  cout << endl;
  cout << "       ";
  for (ll i = 0; i < v[0].size(); i++)
    cout << i << "   ";
  cout << endl;
  for (ll i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   ";
    for (ll j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\\x1B[31m" << v[i][j]
             << "   "; // https://stackoverrun.com/ja/q/12618775
    }
    cout << "\\x1B[0m" << endl;
  }
}

// const int SIZE = 3e5+1;
// vector<vector<bool>> is_bomb(SIZE, vector<bool>(SIZE, false));
int main() {
  ll H, W;
  cin >> H >> W;
  ll M;
  cin >> M;

  vector<vector<bool>> is_bomb(H, vector<bool>(W, false));
  vector<ll> num_h(H, 0), num_w(W, 0);
  for (ll i = 0; i < M; i++) {
    ll h, w;
    cin >> h >> w;
    h--;
    w--;
    // is_bomb[h][w] = true;
    num_h[h]++;
    num_w[w]++;
  }

  // ll h_num_max = 0, w_num_max = 0;
  // for(ll i=0; i<H; i++) h_num_max = max(h_num_max, num_h[i]);
  // for(ll i=0; i<W; i++) w_num_max = max(w_num_max, num_w[i]);

  // vector<ll> maxs_h, maxs_w;
  // for(ll i=0; i<H; i++) if(num_h[i] == h_num_max) maxs_h.emplace_back(i);
  // for(ll i=0; i<W; i++) if(num_w[i] == w_num_max) maxs_w.emplace_back(i);

  // ll ans = 0;
  // for(ll i=0; i<(ll)maxs_h.size(); i++){
  //   for(ll j=0; j<(ll)maxs_w.size(); j++){
  //       ll tmp = num_h[maxs_h[i]] + num_w[maxs_w[j]];
  //       if(is_bomb[maxs_h[i]][maxs_w[j]] == true) tmp--;
  //       else{
  //         cout << tmp << endl;
  //         return 0;
  //       }
  //       ans = max(ans, tmp);
  //   }
  // }

  // cout << ans << endl;
  return 0;
}