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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
ll n, x, y;
/******* define variable end *******/
ll solve() {
  cin >> n >> x >> y;
  vector<vector<ll>> dist(n + 10, vector<ll>(n + 10));
  vector<ll> ans(n + 10);
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      if (i <= x && y <= j) {
        dist[i][j] = min(j - i, x - i + 1 + j - y);
      } else if (x < i && y <= j) {
        dist[i][j] = min((i - x) + 1 + (j - y), j - i);
      } else if (i <= x && j < y) {
        dist[i][j] = min(j - i, (y - j) + 1 + (x - i));
      } else {
        dist[i][j] = min(j - i, (i - x) + 1 + (y - j));
      }
      ans[dist[i][j]]++;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
int main() {
  // clock_t start = clock();
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll end_solve = solve();
  /*
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
  1000.0; printf("time %lf[ms]\\n", time);
  */

  return (int)end_solve;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
vector<vector<ll>> depth;

// d: 頂点 v の深さ
void dfs(const Graph &G, int v, int p, int d, ll i) {
  depth[i][v] = d;
  for (auto nv : G[v]) {
    if (nv == p)
      continue;              // nv が親 p だったらダメ
    dfs(G, nv, v, d + 1, i); // d を 1 増やして子ノードへ
  }
}
/****** define variable start ******/
ll n, x, y;
/******* define variable end *******/
ll solve() {
  cin >> n >> x >> y;
  vector<vector<ll>> dist(n, vector<ll>(n));
  vector<ll> ans(n);
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      if (i <= x && y <= j) {
        dist[i][j] = min(j - i, x - i + 1 + j - y);
      } else if (x < i && y <= j) {
        dist[i][j] = min((i - x) + 1 + (j - y), j - i);
      } else if (i <= x && j < y) {
        dist[i][j] = min(j - i, (y - j) + 1 + (x - i));
      } else {
        dist[i][j] = min(j - i, (i - x) + 1 + (y - j));
      }
      ans[dist[i][j]]++;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
int main() {
  // clock_t start = clock();
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll end_solve = solve();
  /*
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
  1000.0; printf("time %lf[ms]\\n", time);
  */

  return (int)end_solve;
}