Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;
int dist[202][202];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  rep(i, n) rep(j, n) {
    if (j <= i)
      continue;
    dist[i][j] = j - i;
  }
  dist[x][y] = 1;

  rep(i, n) {
    rep(j, n) {
      if (j <= i)
        continue;
      if (i == x && j == y)
        continue;

      if (i <= x && y <= j)
        dist[i][j] = min(dist[i][x] + dist[y][j] + 1, dist[i][j]);
      else if (i > x && y <= j)
        dist[i][j] = min(dist[x][i] + dist[y][j] + 1, dist[i][j]);
      else if (i <= x && y > j)
        dist[i][j] = min(dist[i][x] + dist[j][y] + 1, dist[i][j]);
      else if (i > x && y > j)
        dist[i][j] = min(dist[x][i] + dist[j][y] + 1, dist[i][j]);
      // if (i<=x && y<=j) dist[i][j] =
      // min(dist[i][x]+dist[y][j]+1,dist[i][j-1]+1); else if (i>x && y<=j)
      // dist[i][j] = min(dist[x][i]+dist[y][j]+1,dist[i][j-1]+1); else if (i<=x
      // && y>j) dist[i][j] = min(dist[i][x]+dist[j][y]+1,dist[i][j-1]+1); else
      // if (i>x && y>j) dist[i][j] =
      // min(dist[x][i]+dist[j][y]+1,dist[i][j-1]+1);
    }
  }
  map<int, int> mp;
  rep(i, n) {
    rep(j, n) {
      if (j <= i)
        continue;
      // cout << "i: " << i << " j: " << j << " dist: " << dist[i][j] << endl;
      mp[dist[i][j]]++;
    }
  }
  for (int i = 1; i <= n - 1; ++i) {
    cout << mp[i] << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;
int dist[2020][2020];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  rep(i, n) rep(j, n) {
    if (j <= i)
      continue;
    dist[i][j] = j - i;
  }
  dist[x][y] = 1;

  rep(i, n) {
    rep(j, n) {
      if (j <= i)
        continue;
      if (i == x && j == y)
        continue;

      if (i <= x && y <= j)
        dist[i][j] = min(dist[i][x] + dist[y][j] + 1, dist[i][j]);
      else if (i > x && y <= j)
        dist[i][j] = min(dist[x][i] + dist[y][j] + 1, dist[i][j]);
      else if (i <= x && y > j)
        dist[i][j] = min(dist[i][x] + dist[j][y] + 1, dist[i][j]);
      else if (i > x && y > j)
        dist[i][j] = min(dist[x][i] + dist[j][y] + 1, dist[i][j]);
      // if (i<=x && y<=j) dist[i][j] =
      // min(dist[i][x]+dist[y][j]+1,dist[i][j-1]+1); else if (i>x && y<=j)
      // dist[i][j] = min(dist[x][i]+dist[y][j]+1,dist[i][j-1]+1); else if (i<=x
      // && y>j) dist[i][j] = min(dist[i][x]+dist[j][y]+1,dist[i][j-1]+1); else
      // if (i>x && y>j) dist[i][j] =
      // min(dist[x][i]+dist[j][y]+1,dist[i][j-1]+1);
    }
  }
  map<int, int> mp;
  rep(i, n) {
    rep(j, n) {
      if (j <= i)
        continue;
      // cout << "i: " << i << " j: " << j << " dist: " << dist[i][j] << endl;
      mp[dist[i][j]]++;
    }
  }
  for (int i = 1; i <= n - 1; ++i) {
    cout << mp[i] << endl;
  }
  return 0;
}