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

/**
 * @author pr4shan7 (प्रशांत)
 */
// everything has a cost!

#ifdef _MAVERICK
#define _DEBUG
#else
#pragma GCC optimize("O2", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx,avx2,fma")
// #pragma GCC reset_options
#endif

#ifndef _DEBUG
#define NDEBUG
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define endl '\\n'
// #define cerr cout
// #define int long long
// #define double long double

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pb_set;
typedef unordered_set<int> usi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef set<int> si;
typedef long long ll;

#define pb push_back
#define x first
#define y second
#define cai static_cast<int>
#define cad static_cast<double>
#define cal static_cast<long long>
#define all(z) z.begin(), z.end()
#define tr(cont, itm) for (auto &&itm : cont)
#define rep(in, beg, sz) for (int in = beg; in < sz; in++)
#define rrep(in, sz, beg) for (int in = sz - 1; in >= beg; in--)
#define rtr(cont, itr)                                                         \\
  for (auto itr = cont.end() - 1; itr >= cont.begin(); itr--)

#ifdef _DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

template <typename... T> void debug_out(const T &...);
#else
#define debug(...) 42
#endif

template <typename T> constexpr istream &operator>>(istream &, vector<T> &);
template <typename T> ostream &operator<<(ostream &, const vector<T> &);
double time_it(const chrono::time_point<chrono::high_resolution_clock> &,
               const chrono::time_point<chrono::high_resolution_clock> &);
template <typename T> constexpr T pow(long long, long long, const T);

const int N = 1e5 + 5;
const int INF = 1e9;
const int MV = 1e9 + 7;

// beautiful things don't ask for attention

int32_t main() {
  const auto start = chrono::high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef _MAVERICK
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("err.txt", "w", stderr);
#endif

  int n, x, y;
  cin >> n >> x >> y;
  vi ans(n, 0);

  rep(i, 1, n) {
    rep(j, i + 1, n + 1) {
      int mdist = min(j - i, abs(x - i) + 1 + abs(j - y));
      if (mdist > 0 && mdist < n)
        ans[mdist]++;
    }
  }
  rep(i, 1, n) cout << ans[i] << endl;

  const auto end = chrono::high_resolution_clock::now();
  time_it(start, end);

  return 0;
}

#ifdef _DEBUG
template <typename... T> inline void debug_out(const T &...args) {
  ((cerr << ' ' << args), ...);
  cerr << endl;
}
#endif

template <typename T>
constexpr inline istream &operator>>(istream &in, vector<T> &ar) {
  for (auto &i : ar)
    in >> i;
  return in;
}

template <typename T>
inline ostream &operator<<(ostream &out, const vector<T> &ar) {
  for (int i = 0; i < ar.size() - 1; i++)
    out << ar[i] << ' ';
  if (ar.size())
    out << ar[ar.size() - 1];
  return out;
}

inline double
time_it(const chrono::time_point<chrono::high_resolution_clock> &start,
        const chrono::time_point<chrono::high_resolution_clock> &end) {
  chrono::duration<double, milli> time_taken = end - start;
#ifdef _MAVERICK
  cerr << endl
       << fixed << setprecision(3) << "time taken: " << time_taken.count()
       << " ms";
#endif
  return time_taken.count();
}

template <typename T> constexpr T pow(long long a, long long b, const T mv) {
  long long res = 1;
  a %= mv;
  while (b) {
    if (b & 1)
      res = (res * a) % mv;
    b >>= 1;
    a = (a * a) % mv;
  }
  return res;
}

// get busy living or get busy dying


Error: TLE

Fixed submission:

/**
 * @author pr4shan7 (प्रशांत)
 */
// everything has a cost!

#ifdef _MAVERICK
#define _DEBUG
#else
#pragma GCC optimize("O2", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx,avx2,fma")
// #pragma GCC reset_options
#endif

#ifndef _DEBUG
#define NDEBUG
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define endl '\\n'
// #define cerr cout
// #define int long long
// #define double long double

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pb_set;
typedef unordered_set<int> usi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef set<int> si;
typedef long long ll;

#define pb push_back
#define x first
#define y second
#define cai static_cast<int>
#define cad static_cast<double>
#define cal static_cast<long long>
#define all(z) z.begin(), z.end()
#define tr(cont, itm) for (auto &&itm : cont)
#define rep(in, beg, sz) for (int in = beg; in < sz; in++)
#define rrep(in, sz, beg) for (int in = sz - 1; in >= beg; in--)
#define rtr(cont, itr)                                                         \\
  for (auto itr = cont.end() - 1; itr >= cont.begin(); itr--)

#ifdef _DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

template <typename... T> void debug_out(const T &...);
#else
#define debug(...) 42
#endif

template <typename T> constexpr istream &operator>>(istream &, vector<T> &);
template <typename T> ostream &operator<<(ostream &, const vector<T> &);
double time_it(const chrono::time_point<chrono::high_resolution_clock> &,
               const chrono::time_point<chrono::high_resolution_clock> &);
template <typename T> constexpr T pow(long long, long long, const T);

const int N = 1e5 + 5;
const int INF = 1e9;
const int MV = 1e9 + 7;

// beautiful things don't ask for attention

int32_t main() {
  const auto start = chrono::high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifdef _MAVERICK
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("err.txt", "w", stderr);
#endif

  int n, x, y;
  cin >> n >> x >> y;
  rep(k, 1, n) {
    int ans{0};
    rep(i, 1, n) {
      rep(j, i + 1, n + 1) {
        int mdist = min(j - i, abs(x - i) + 1 + abs(j - y));
        if (mdist == k)
          ans++;
      }
    }
    cout << ans << endl;
  }

  const auto end = chrono::high_resolution_clock::now();
  time_it(start, end);

  return 0;
}

#ifdef _DEBUG
template <typename... T> inline void debug_out(const T &...args) {
  ((cerr << ' ' << args), ...);
  cerr << endl;
}
#endif

template <typename T>
constexpr inline istream &operator>>(istream &in, vector<T> &ar) {
  for (auto &i : ar)
    in >> i;
  return in;
}

template <typename T>
inline ostream &operator<<(ostream &out, const vector<T> &ar) {
  for (int i = 0; i < ar.size() - 1; i++)
    out << ar[i] << ' ';
  if (ar.size())
    out << ar[ar.size() - 1];
  return out;
}

inline double
time_it(const chrono::time_point<chrono::high_resolution_clock> &start,
        const chrono::time_point<chrono::high_resolution_clock> &end) {
  chrono::duration<double, milli> time_taken = end - start;
#ifdef _MAVERICK
  cerr << endl
       << fixed << setprecision(3) << "time taken: " << time_taken.count()
       << " ms";
#endif
  return time_taken.count();
}

template <typename T> constexpr T pow(long long a, long long b, const T mv) {
  long long res = 1;
  a %= mv;
  while (b) {
    if (b & 1)
      res = (res * a) % mv;
    b >>= 1;
    a = (a * a) % mv;
  }
  return res;
}

// get busy living or get busy dying