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

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<long long>> points;
void rotate() {
  for (auto &p : points) {
    int nx = p[1];
    int ny = 200005 - p[0];
    p[0] = nx;
    p[1] = ny;
    p[2]++;
    p[2] %= 4;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    char dir;
    cin >> dir;
    if (dir == 'R')
      points.push_back({x, y, 0});
    if (dir == 'D')
      points.push_back({x, y, 1});
    if (dir == 'L')
      points.push_back({x, y, 2});
    if (dir == 'U')
      points.push_back({x, y, 3});
  }
  long long ans = 1 << 30;
  for (int u = 0; u < 4; u++) {
    vector<vector<pair<long long, long long>>> v(202020);
    for (auto &p : points) {
      if (p[2] == 0 || p[2] == 2)
        v[p[1]].emplace_back(p[0], p[2]);
    }
    for (auto &line : v) {
      long long l = -(1 << 30);
      sort(line.begin(), line.end());
      for (auto &p : line) {
        if (p.second == 0)
          l = max(l, p.first);
        else
          ans = min(ans, p.first - l);
      }
    }
    v = vector<vector<pair<long long, long long>>>(404040);
    for (auto &p : points) {
      if (p[2] == 0 || p[2] == 3)
        v[p[0] + p[1]].emplace_back(p[0], p[2]);
    }
    for (auto &line : v) {
      sort(line.begin(), line.end());
      long long l = -(1 << 30);
      for (auto &p : line) {
        if (p.second == 0)
          l = max(l, p.first);
        else
          ans = min(ans, 2LL * (p.first - l));
      }
    }
    rotate();
  }
  if (ans == 1 << 30)
    cout << "SAFE" << endl;
  else
    cout << ans * 5 << endl;
  return 0;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<long long>> points;
void rotate() {
  for (auto &p : points) {
    int nx = p[1];
    int ny = 202020 - p[0];
    p[0] = nx;
    p[1] = ny;
    p[2]++;
    p[2] %= 4;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    char dir;
    cin >> dir;
    if (dir == 'R')
      points.push_back({x, y, 0});
    if (dir == 'D')
      points.push_back({x, y, 1});
    if (dir == 'L')
      points.push_back({x, y, 2});
    if (dir == 'U')
      points.push_back({x, y, 3});
  }
  long long ans = 1 << 30;
  for (int u = 0; u < 4; u++) {
    vector<vector<pair<long long, long long>>> v(202020);
    for (auto &p : points) {
      if (p[2] == 0 || p[2] == 2)
        v[p[1]].emplace_back(p[0], p[2]);
    }
    for (auto &line : v) {
      long long l = -(1 << 30);
      sort(line.begin(), line.end());
      for (auto &p : line) {
        if (p.second == 0)
          l = max(l, p.first);
        else
          ans = min(ans, p.first - l);
      }
    }
    v = vector<vector<pair<long long, long long>>>(404040);
    for (auto &p : points) {
      if (p[2] == 0 || p[2] == 3)
        v[p[0] + p[1]].emplace_back(p[0], p[2]);
    }
    for (auto &line : v) {
      sort(line.begin(), line.end());
      long long l = -(1 << 30);
      for (auto &p : line) {
        if (p.second == 0)
          l = max(l, p.first);
        else
          ans = min(ans, 2LL * (p.first - l));
      }
    }
    rotate();
  }
  if (ans == 1 << 30)
    cout << "SAFE" << endl;
  else
    cout << ans * 5 << endl;
  return 0;
}