Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#if __has_include("D:/dhiraj/Programming/debug.h")
#include "D:/dhiraj/Programming/debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull unsigned long long int
#define ll long long int
#define ld long double

// Loops --------------------------------------------------------------------

#define loop(i, s, e) for (ll i = (s); i < (e); i++)
#define rloop(i, s, e) for (ll i = (s); i >= (e); i--)
#define iter(it, var) for (auto it = var.begin(); it != var.end(); it++)
#define riter(it, var) for (auto it = var.rbegin(); it != var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

// Extra --------------------------------------------------------------------

#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define print(any)                                                             \\
  for (auto &i : any)                                                          \\
    cout << i << " ";                                                          \\
  nl;
#define precise(a) cout << fixed << setprecision(a)
#define nl std::cout << '\\n'
#define INF LLONG_MAX
#define endl '\\n'

// Template -----------------------------------------------------------------

template <typename T> inline bool inrange(T a, T l, T r) {
  if (l > r)
    swap(l, r);
  return (a >= l and a <= r);
}
template <typename T, typename U> inline bool exist(T val, U &any) {
  return (any.find(val) != any.end());
}
// multiple input
template <typename T> inline void inp(T &any) { cin >> any; }
template <typename T, typename... U> inline void inp(T &a, U &...b) {
  cin >> a;
  inp(b...);
}
// scan vector
template <typename T> inline istream &operator>>(istream &in, vector<T> &a) {
  for (auto &x : a)
    in >> x;
  return in;
}
// scan pair
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.ff >> a.ss;
  return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T) {
  ll n, x, y;
  inp(n, x, y);

  vll ans(n + 1);
  loop(i, 1, n + 1) {
    loop(j, i + 1, n + 1) {
      ll z = abs(j - i);
      z = min(z, abs(i - x) + 1 + abs(j - y));
      z = min(z, abs(j - x) + 1 + abs(i - y));
      ans[z]++;
    }
  }
  loop(i, 1, n) std::cout << ans[i] << "\\n";
}

// Main ---------------------------------------------------------------------

int main() {
#ifdef Dhiraj
  freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
  freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
#endif

  fast;
  int t = 1;
  loop(i, 1, t + 1) solve(i);
  return 0;
}

Error: TLE

Fixed submission:

/****************************************************************************

        " Peace begins with a smile. "
        -- Mother Teresa

******************************************************************************
*                                                                            *
*                       Author : Dhiraj Govindvira                           *
*                         Date : 28-Mar-2020 ~ Saturday                      *
*                         Time : 6:22:38 PM                                  *
*                                                                            *
*****************************************************************************/

#if __has_include("D:/dhiraj/Programming/debug.h")
#include "D:/dhiraj/Programming/debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull unsigned long long int
#define ll long long int
#define ld long double

// Loops --------------------------------------------------------------------

#define loop(i, s, e) for (ll i = (s); i < (e); i++)
#define rloop(i, s, e) for (ll i = (s); i >= (e); i--)
#define iter(it, var) for (auto it = var.begin(); it != var.end(); it++)
#define riter(it, var) for (auto it = var.rbegin(); it != var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define ff first
#define ss second
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

// Extra --------------------------------------------------------------------

#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define print(any)                                                             \\
  for (auto &i : any)                                                          \\
    cout << i << " ";                                                          \\
  nl;
#define precise(a) cout << fixed << setprecision(a)
#define nl std::cout << '\\n'
#define INF LLONG_MAX
#define endl '\\n'

// Template -----------------------------------------------------------------

template <typename T> inline bool inrange(T a, T l, T r) {
  if (l > r)
    swap(l, r);
  return (a >= l and a <= r);
}
template <typename T, typename U> inline bool exist(T val, U &any) {
  return (any.find(val) != any.end());
}
// multiple input
template <typename T> inline void inp(T &any) { cin >> any; }
template <typename T, typename... U> inline void inp(T &a, U &...b) {
  cin >> a;
  inp(b...);
}
// scan vector
template <typename T> inline istream &operator>>(istream &in, vector<T> &a) {
  for (auto &x : a)
    in >> x;
  return in;
}
// scan pair
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.ff >> a.ss;
  return in;
}

// Solve --------------------------------------------------------------------

using graph = vector<vector<ll>>;
void solve(ll &T) {
  ll n, x, y;
  inp(n, x, y);

  graph g(n);
  loop(i, 0, n) g[i].resize(n);

  loop(i, 0, n) loop(j, 0, n) g[i][j] = INT_MAX;

  loop(i, 0, n - 1) {
    g[i][i] = 0;
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  g[x - 1][y - 1] = g[y - 1][x - 1] = 1;
  g[n - 1][n - 1] = 0;

  loop(i, 0, n) loop(j, 0, n) loop(k, 0, n) g[j][k] =
      min(g[j][k], g[j][i] + g[i][k]);

  vll ans(n);
  loop(i, 0, n) loop(j, 0, n) ans[g[i][j]]++;

  loop(i, 1, n) std::cout << ans[i] / 2 << endl;
}

// Main ---------------------------------------------------------------------

int main() {
#ifdef Dhiraj
  freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
  freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
#endif

  fast;
  int t = 1;
  loop(i, 1, t + 1) solve(i);
  return 0;
}