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

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be(), (a).en()
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)       // repeat n times
#define REP2(i, s, n) for (int(i) = (s); (i) < (n); (i)++) // repeat from s to n
#define REPD(i, n) for (int(i) = (n); (i) >= 0; (i)--)     // repeat from n to 0
#define REPD2(i, s, e)                                                         \\
  for (int(i) = (s); (i) >= (e); (i)--)     // repeat from s to e
#define RANGE(i, v) for (auto &(i) : v)     // repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0])) // array size

using LL = long long;

template <typename T> using V = vector<T>;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

const int INF = 1999999999;

template <typename T> T vec_max(V<T> v) { return *max_element(ALL(v)); }

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;

  Vi cnt(N);
  REP(i, N) {
    REP2(j, i, N) {
      int dist = min(abs(i - j), abs(i - (X - 1)) + 1 + abs((Y - 1) - j));
      cnt[dist]++;
    }
  }

  REP(i, N - 1) { cout << cnt[i + 1] << endl; }

  return 0;
}

Error: TLE

Fixed submission:

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be(), (a).en()
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)       // repeat n times
#define REP2(i, s, n) for (int(i) = (s); (i) < (n); (i)++) // repeat from s to n
#define REPD(i, n) for (int(i) = (n); (i) >= 0; (i)--)     // repeat from n to 0
#define REPD2(i, s, e)                                                         \\
  for (int(i) = (s); (i) >= (e); (i)--)     // repeat from s to e
#define RANGE(i, v) for (auto &(i) : v)     // repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0])) // array size

using LL = long long;

template <typename T> using V = vector<T>;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

const int INF = 1999999999;

template <typename T> T vec_max(V<T> v) { return *max_element(ALL(v)); }

struct edge {
  int src;
  int dst;
  int weight;
  edge() : src(0), dst(0), weight(0) {}
  edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};

using edges = V<edge>;
using graph = V<edges>;

void add_edge(edges &g, int s, int d, int w = 1, bool undirected = true) {
  g.pb(edge(s, d, w));
  if (undirected)
    g.pb(edge(d, s, w));
}
void add_edge(graph &g, int s, int d, int w = 1, bool undirected = true) {
  g[s].pb(edge(s, d, w));
  if (undirected)
    g[d].pb(edge(d, s, w));
}

V<Vi> floyd(const graph &g) {
  int n = g.size();
  V<Vi> dist(n, Vi(n, INF / 2));
  REP(i, n) { dist[i][i] = 0; }
  REP(i, n) {
    for (auto &e : g[i]) {
      dist[e.src][e.dst] = e.weight;
    }
  }
  REP(k, n) {
    REP(i, n) {
      REP(j, n) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); }
    }
  }
  return dist;
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  graph G(N);
  REP(i, N - 1) { add_edge(G, i, i + 1); }

  add_edge(G, X - 1, Y - 1);

  auto dist = floyd(G);

  Vi cnt(N);
  REP(i, dist.size()) {
    REP2(j, i, dist[i].size()) { cnt[dist[i][j]]++; }
  }

  REP(i, N - 1) { cout << cnt[i + 1] << endl; }

  return 0;
}