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

#include <algorithm>
#include <cassert>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main() {
  ll H, W, M;
  scanf("%lld", &H);
  scanf("%lld", &W);
  scanf("%lld", &M);

  map<ll, ll> lineTargets, rowTargets;
  map<pair<ll, ll>, bool> targetMap;
  for (ll i = 0; i < M; i++) {
    ll h, w;
    scanf("%lld", &h);
    scanf("%lld", &w);
    h--;
    w--;
    lineTargets[h]++;
    rowTargets[w]++;
    targetMap[{h, w}] = true;
  }

  vector<pair<ll, ll>> lineVector(lineTargets.begin(), lineTargets.end());
  vector<pair<ll, ll>> rowVector(rowTargets.begin(), rowTargets.end());
  sort(
      lineVector.begin(), lineVector.end(),
      [](auto const &lhs, auto const &rhs) { return lhs.second > rhs.second; });
  sort(
      rowVector.begin(), rowVector.end(),
      [](auto const &lhs, auto const &rhs) { return lhs.second > rhs.second; });
  auto line = *lineVector.begin();
  auto row = *rowVector.begin();
  bool isNone = false;
  for (auto &&i : lineVector) {
    if (i.second < line.second)
      break;
    for (auto &&j : rowVector) {
      if (j.second < row.second)
        break;

      if (!targetMap[{i.first, j.first}]) {
        isNone = true;
        break;
      }
    }
  }

  ll ans = line.second + row.second - (isNone ? 0 : 1);
  printf("%lld\\n", ans);
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main() {
  ll H, W, M;
  scanf("%lld", &H);
  scanf("%lld", &W);
  scanf("%lld", &M);

  map<ll, ll> lineTargets, rowTargets;
  vector<vector<bool>> targetMap(H, vector<bool>(W, false));
  for (ll i = 0; i < M; i++) {
    ll h, w;
    scanf("%lld", &h);
    scanf("%lld", &w);
    h--;
    w--;
    lineTargets[h]++;
    rowTargets[w]++;
    targetMap[h][w] = true;
  }

  vector<pair<ll, ll>> lineVector(lineTargets.begin(), lineTargets.end());
  vector<pair<ll, ll>> rowVector(rowTargets.begin(), rowTargets.end());
  sort(
      lineVector.begin(), lineVector.end(),
      [](auto const &lhs, auto const &rhs) { return lhs.second > rhs.second; });
  sort(
      rowVector.begin(), rowVector.end(),
      [](auto const &lhs, auto const &rhs) { return lhs.second > rhs.second; });
  auto line = *lineVector.begin();
  auto row = *rowVector.begin();
  bool isNone = false;
  for (auto &&i : lineVector) {
    if (i.second < line.second)
      break;
    for (auto &&j : rowVector) {
      if (j.second < row.second)
        break;

      if (!targetMap[i.first][j.first]) {
        isNone = true;
        break;
      }
    }
  }

  ll ans = line.second + row.second - (isNone ? 0 : 1);
  printf("%lld\\n", ans);
}