Problem p02726 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vvi a(n, vi(n));
  rep(i, n) {
    rep(j, n) {
      if (i < j) {
        a[i][j] = abs(i - j);
        if ((i >= x && i <= y) && (j >= x && j <= y)) {
          a[i][j] = min(a[i][j], (i - x) + 1 + (y - j));
        }
        if (x >= i && (j >= x && j <= y)) {
          a[i][j] = min(a[i][j], (x - i) + 1 + (y - j));
        }
        if (j >= y && (i >= x && i <= y)) {
          a[i][j] = min(a[i][j], (j - y) + 1 + (i - x));
        }
        if (i <= x && y <= j) {
          a[i][j] = min(a[i][j], (x - i) + 1 + (j - y));
        }
      } else
        a[i][j] = 100000000;
    }
  }
  int d = 0, cnt = 0;
  while (d < n - 1) {
    d++;
    rep(i, n) {
      rep(j, n) {
        if (a[i][j] == d) {
          cnt++;
        }
      }
    }
    cout << cnt << endl;
    cnt = 0;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vvi a(n, vi(n));
  rep(i, n) {
    rep(j, n) {
      if (i < j) {
        a[i][j] = abs(i - j);
        if ((i >= x && i <= y) && (j >= x && j <= y)) {
          a[i][j] = min(a[i][j], (i - x) + 1 + (y - j));
        }
        if (x >= i && (j >= x && j <= y)) {
          a[i][j] = min(a[i][j], (x - i) + 1 + (y - j));
        }
        if (j >= y && (i >= x && i <= y)) {
          a[i][j] = min(a[i][j], (j - y) + 1 + (i - x));
        }
        if (i <= x && y <= j) {
          a[i][j] = min(a[i][j], (x - i) + 1 + (j - y));
        }
      } else
        a[i][j] = 100000000;
    }
  }
  map<int, int> d;
  rep(i, n) {
    rep(j, n) { d[a[i][j]]++; }
  }
  for (int i = 1; i < n; ++i) {
    cout << d[i] << endl;
  }
}