alexjercan/bugnet huggingface dataset:
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vi = vector<int>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// pow(llpow,modpow)
template <class T> ll llpow(ll x, T n) {
  ll ans = 1;
  if (x == 0)
    ans = 0;
  while (n) {
    if (n & 1)
      ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
// 最大公約数
template <class T> inline T gcd(T x, T y) {
  if (y == 0)
    return x;
  else {
    return gcd(y, x % y);
  }
}
// 最小公倍数
template <class T> inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
// 逆元
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

int INF = 1 << 30;

using pii = pair<int, int>;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> conne[n];
  x--;
  y--;
  rep(i, 0, n - 1) {
    conne[i].push_back(i + 1);
    conne[i + 1].push_back(i);
  }
  conne[x].push_back(y);
  conne[y].push_back(x);
  vll ans(n, 0);

  rep(start, 0, n) {
    vector<int> res(n, INF);
    queue<pair<int, int>> q;
    q.emplace(start, 0);
    while (!q.empty()) {
      pii t = q.front();
      q.pop();
      chmin(res[t.first], t.second);

      for (int e : conne[t.first]) {
        if (res[e] > t.second + 1) {
          q.emplace(e, t.second + 1);
        }
      }
    }
    rep(c, start + 1, n) {
      int t = res[c] - 1;
      ans[t]++;
    }
  }
  rep(i, 0, n - 1) { cout << ans[i] << endl; }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

typedef vector<vector<int>> Matrix;

const int INF = 100000000;
Matrix
    d; // グラフの距離を格納した2次元配列（隣接行列）
       // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) {      // nは頂点数
  for (int i = 0; i < n; i++)     // 経由する頂点
    for (int j = 0; j < n; j++)   // 開始頂点
      for (int k = 0; k < n; k++) // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
  int n;
  cin >> n;
  int x, y;
  cin >> x >> y;
  x--;
  y--;
  d = Matrix(n, vector<int>(n, INF));
  for (int i = 0; i < n; i++)
    d[i][i] = 0;
  rep(i, 0, n) {
    rep(j, 0, n) {
      if (i - j == 1)
        d[i][j] = d[j][i] = 1;
    }
  }
  d[x][y] = d[y][x] = 1;

  warshall_floyd(n);

  vector<long long> res(n, 0);

  rep(i, 0, n) {
    rep(j, i + 1, n) {
      int t = d[i][j] - 1;
      res[t]++;
    }
  }
  rep(i, 0, n - 1) { cout << res[i] << endl; }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<vector<int>> dist(N, vector<int>(N));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      dist[i][j] = abs(i - j);
  int l, r;
  cin >> l >> r;
  --l;
  --r;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      dist[i][j] = min({dist[i][j], dist[i][l] + 1 + dist[r][j],
                        dist[i][r] + 1 + dist[l][j]});
    }
  vector<int> cnt(N);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      cnt[dist[i][j]]++;
  for (int k = 1; k <= N - 1; k++)
    cout << cnt[k] / 2 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> d(N, vector<int>(N, 1e7));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      if (i == j)
        d[i][j] = 0;
      else if (i + 1 == j || (i == X - 1 && j == Y - 1))
        d[i][j] = 1, d[j][i] = 1;
    }
  // for (int i=0;i<N;i++) {
  //     for (int j=0;j<N;j++) cout << d[i][j] << " ";
  //     cout << endl;
  // }
  for (int s = 0; s < N; s++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][s] + d[s][j]);
      }
    }
  }
  // for (int i=0;i<N;i++) {
  //     for (int j=0;j<N;j++) cout << d[i][j] << " ";
  //     cout << endl;
  // }
  vector<int> num_k(N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i >= j)
        continue;
      num_k[d[i][j]]++;
    }
  }
  for (int k = 1; k <= N - 1; k++)
    cout << num_k[k] << "\\n";
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

// typedef vector<pair<int, int>> Numbers;
int n, x, y;

int main() {
  cin >> n >> x >> y;
  // Numbers numbers;
  vector<int> nums(n);
  for (int i = 1; i < n + 1; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      nums[min(
          {j - i, abs(x - i) + abs(j - y) + 1, abs(y - i) + abs(j - x) + 1})]++;
    }
  }
  // あとでキューでも早さがどうなるか試してみる。

  int cnt;
  for (int j = 1; j < n; j++) {
    cout << nums[j] << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

// typedef vector<pair<int, int>> Numbers;
int n, x, y;

int main() {
  cin >> n >> x >> y;
  // Numbers numbers;
  vector<int> nums;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      nums.push_back(min(
          {j - i, abs(x - i) + abs(j - y) + 1, abs(y - i) + abs(j - x) + 1}));
    }
  }
  // あとでキューでも早さがどうなるか試してみる。

  int cnt;
  for (int j = 1; j < n; j++) {
    cnt = 0;
    for (int i = 0; i < nums.size(); i++) {
      if (j == nums[i]) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <boost/dynamic_bitset.hpp>
#include <boost/multi_array.hpp>
#include <boost/operators.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main() {
  int N, X, Y;
  std::cin >> N >> X >> Y;
  std::vector<int> count(N);
  --X;
  --Y;
  for (auto i : boost::irange(0, N - 1)) {
    for (auto j : boost::irange(i + 1, N)) {
      auto min = std::min({j - i, std::abs(i - X) + std::abs(j - X),
                           std::abs(i - Y) + std::abs(j - Y),
                           std::abs(i - X) + std::abs(j - Y) + 1});
      ++count[min];
    }
  }
  for (auto i : boost::irange(1, N)) {
    std::cout << count[i] << std::endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <boost/dynamic_bitset.hpp>
#include <boost/multi_array.hpp>
#include <boost/operators.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void warshall_floyd(boost::multi_array<int, 2> &ar, int N) {
  for (int k : boost::irange(0, N)) {
    for (int i : boost::irange(0, N)) {
      for (int j : boost::irange(0, N)) {
        ar[i][j] = std::min(ar[i][j], ar[i][k] + ar[k][j]);
      }
    }
  }
}

void Main() {
  int N, X, Y;
  std::cin >> N >> X >> Y;
  boost::multi_array<int, 2> ar(boost::extents[N][N]);
  for (auto i : boost::irange(0, N)) {
    for (auto j : boost::irange(0, N)) {
      ar[i][j] = N;
    }
  }
  for (auto i : boost::irange(0, N - 1)) {
    ar[i][i + 1] = ar[i + 1][i] = 1;
  }
  ar[X - 1][Y - 1] = ar[Y - 1][X - 1] = 1;
  warshall_floyd(ar, N);
  std::vector<int> count(N);
  for (auto i : boost::irange(0, N)) {
    for (auto j : boost::irange(i + 1, N)) {
      ++count[ar[i][j]];
    }
  }
  for (auto i : boost::irange(1, N)) {
    std::cout << count[i] << std::endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<vector<int>> dist_mat(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++)
      dist_mat[i][j] = j - i;
    ;
  }
  // bypass
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int i_dist = abs(X - 1 - i);
      int j_dist = abs(Y - 1 - j);
      dist_mat[i][j] = min(dist_mat[i][j], 1 + i_dist + j_dist);
    }
  }
  vector<int> counts(N, 0);
  for (const auto &row : dist_mat)
    for (const auto &col : row)
      counts[col] += 1;
  for (int k = 1; k < N; k++)
    cout << counts[k] << endl;
}


Error: TLE

Fixed submission:

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

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

  vector<vector<int>> dist_mat(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++)
      dist_mat[i][j] = j - i;
    ;
  }
  // bypass
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int i_dist = abs(X - 1 - i);
      int j_dist = abs(Y - 1 - j);
      dist_mat[i][j] = min(dist_mat[i][j], 1 + i_dist + j_dist);
    }
  }

  for (int k = 1; k < N; k++) {
    int count = 0;
    for (const auto &row : dist_mat)
      for (const auto &col : row)
        if (col == k)
          count++;
    cout << count << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

// int main(){
//   int n,x,y;
//   std::cin >> n>>x>>y;
//   std::vector<std::vector<int> > G(n+1);
//   std::vector<int> ans(n+1,0);
//
//   for (int i = 1; i < n; i++) {
//     G[i].push_back(i+1);
//     G[i+1].push_back(i);
//   }
//   G[x].push_back(y);
//   G[y].push_back(x);
//
//
//   rep(i,n+1){
//     std::vector<int> dist(n+1,-1);
//     queue<int> que;
//     dist[i]=0;
//     que.push(i);
//
//     while (!(que.empty())) {
//       int v=que.front();
//       que.pop();
//       for (int nv : G[v]) {
//         if(dist[nv]!=-1)continue;
//         dist[nv]=dist[v]+1;
//         que.push(nv);
//       }
//       break;
//     }
//     rep(j,n+1)ifans[dist[j]]++;
//
//   }
//
//   for (int i = 1; i < n; i++)std::cout << ans[i]/2 << '\\n';
//
//
//   return 0;
// }

#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, x, y;
  std::cin >> n >> x >> y;
  std::vector<std::vector<int>> G(n + 1);
  std::vector<int> ans(n + 1, 0);

  for (int i = 1; i < n; i++) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[x].push_back(y);
  G[y].push_back(x);

  rep(i, n + 1) {
    std::vector<int> dist(n + 1, -1);
    queue<int> que;
    dist[i] = 0;
    que.push(i);

    while (!(que.empty())) {
      int v = que.front();
      que.pop();
      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue;
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }
    rep(j, n + 1) if (dist[j] >= 0) ans[dist[j]]++;
  }

  for (int i = 1; i < n; i++)
    std::cout << ans[i] / 2 << '\\n';

  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, x, y;
  std::cin >> n >> x >> y;
  std::vector<std::vector<int>> G(n + 1);
  std::vector<int> ans(n + 1, 0);

  for (int i = 1; i < n; i++) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[x].push_back(y);
  G[y].push_back(x);

  rep(i, n + 1) {
    std::vector<int> dist(n + 1, -1);
    queue<int> que;
    dist[i] = 0;
    que.push(i);
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue;
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }
    rep(i, n + 1) ans[dist[i]]++;
  }

  for (int i = 1; i < n; i++)
    std::cout << ans[i] / 2 << '\\n';

  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n, 0);
  vector<vector<int>> d(n, vector<int>(n));
  for (int i = 0; i < n - 1; i++) {
    d.at(i).at(i + 1) = 1;
    d.at(i + 1).at(i) = 1;
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      d.at(i).at(j) = min(j - i, abs(i - x + 1) + 1 + abs(j - y + 1));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      ans.at(d.at(i).at(j))++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans.at(i) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n, 0); // i番目の要素は、距離がiの個数です。
  vector<vector<int>> cost(n, vector<int>(n, 10000000));
  for (int i = 0; i < n - 1; i++) {
    cost.at(i).at(i + 1) = 1;
    cost.at(i + 1).at(i) = 1;
  }
  // cout<<cost.at(0).at(0)<<endl;
  cost.at(x - 1).at(y - 1) = 1;
  cost.at(y - 1).at(x - 1) = 1;
  for (int i = 0; i < n; i++) {
    vector<int> d(n, 1000000);
    vector<bool> used(n, false);
    d.at(i) = 0;
    while (true) {
      int v = -1;
      for (int u = 0; u < n; u++) {
        if (!used[u] && (v == -1 || d[u] < d[v]))
          v = u;
      }
      if (v == -1)
        break;
      used[v] = true;
      for (int u = 0; u < n; u++) {
        d[u] = min(d[u], d[v] + cost[v][u]);
      }
    }
    for (int u = 0; u < n; u++) {
      ans.at(d.at(u)) += 1;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans.at(i) / 2 << '\\n';
  }

  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<int> dif(N - 1, 0);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int dis1 = abs(j - i);
      int dis2 = abs(X - i) + 1 + abs(j - Y);
      int dis3 = abs(Y - i) + 1 + abs(j - X);

      int k = min({dis1, dis2, dis3});
      dif[k - 1]++;
    }
  }
  for (int m : dif) {
    cout << m << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<int> dif(N - 1);

  // 頂点Xと頂点Yを結ぶ辺を使う場合と使わない場合に分けて考える.
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (0 <= i < j <= X || Y <= i < j < N) {
        for (int k = 0; k < N; k++) {
          if (j - i == k) {
            dif[k]++;
          }
        }
      } else {
        for (int k = 0; k < N; k++) {
          if (min(min(abs(j - i), abs(X - i) + 1 + abs(Y - j)),
                  abs(Y - i) + 1 + abs(X - j)) == k) {
            dif[k]++;
          }
        }
      }
    }
  }
  for (int k : dif) {
    cout << dif[k] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> graph(n);
  graph[0].push_back(1);
  graph[n - 1].push_back(n - 2);
  for (int i = 1; i < n - 1; i++) {
    graph[i].push_back(i + 1);
    graph[i].push_back(i - 1);
  }
  graph[x - 1].push_back(y - 1);
  graph[y - 1].push_back(x - 1);
  int INF = 1e9 + 7;
  vector<int> ans(n, 0);
  vector<vector<int>> dist(n, vector<int>(n, INF));
  for (int i = 0; i < n; i++) {
    dist[i][i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto it = graph[u].begin(); it != graph[u].end(); it++) {
        if (dist[i][*it] > 1 + dist[i][u]) {
          dist[i][*it] = 1 + dist[i][u];
          ans[dist[i][*it]]++;
          q.push(*it);
        }
      }
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] / 2 << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> graph(n);
  graph[0].push_back(1);
  graph[n - 1].push_back(n - 2);
  for (int i = 1; i < n - 1; i++) {
    graph[i].push_back(i + 1);
    graph[i].push_back(i - 1);
  }
  graph[x - 1].push_back(y - 1);
  graph[y - 1].push_back(x - 1);
  int INF = 1e9 + 7;
  vector<vector<int>> dist(n, vector<int>(n, INF));
  for (int i = 0; i < n; i++) {
    dist[i][i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto it = graph[u].begin(); it != graph[u].end(); it++) {
        if (dist[i][*it] > 1 + dist[i][u]) {
          dist[i][*it] = 1 + dist[i][u];
          q.push(*it);
        }
      }
    }
  }
  for (int k = 1; k < n; k++) {
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (k == dist[i][j])
          count++;
      }
    }
    cout << count << endl;
  }

  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
int n, x, y;
int f[2001][2001];
int vis[20001];
int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      f[i][j] = f[j][i] = j - i;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i <= x && j >= y)
        f[i][j] -= y - x - 1;
      if (i > x && i < y)
        f[i][j] = min(f[i][j], f[i][x] + f[y][j] + 1);
      if (j > x && j < y)
        f[i][j] = min(f[i][j], f[j][y] + f[x][i] + 1);
      f[j][i] = f[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      vis[f[i][j]]++;
  for (int i = 1; i <= n - 1; i++)
    printf("%d\\n", vis[i]);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  ll adj[n][n];
  ll ans[n];
  for (ll i = 0; i < n; i++)
    ans[i] = 0;
  ll i = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      adj[i][j] = 1e10;
    }
  }
  for (ll i = 0; i < n - 1; i++) {
    adj[i][i + 1] = 1;
    adj[i + 1][i] = 1;
    adj[i][i] = 0;
  }
  adj[n - 1][n - 1] = 0;
  adj[x - 1][y - 1] = adj[y - 1][x - 1] = 1;
  for (ll k = 0; k < n; k++) {
    for (ll i = 0; i < n; i++) {
      for (ll j = 0; j < n; j++) {
        if (adj[i][j] > (adj[i][k] + adj[k][j]))
          adj[i][j] = adj[i][k] + adj[k][j];
      }
    }
  }
  for (ll i = 0; i < n; i++) {
    for (ll j = i; j < n; j++) {
      if (adj[i][j] != 1e10)
        ans[adj[i][j]]++;
    }
  }
  for (ll i = 1; i < n; i++)
    cout << ans[i] << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define endl "\\n"
#define maxn 100000
#define OO 1e5
#define F first
#define S second
#define B begin()
#define E end()
#define PB push_back
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  //	freopen("name.in","r",stdin);
  //	freopen("name.out","w",stdout);

  int n, x, y;
  cin >> n >> x >> y;

  int dist[n + 2][n + 2];
  memset(dist, 0, sizeof(dist));
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dist[i][j] = j - i;
      dist[j][i] = j - i;
    }
  }

  int d = abs(x - y);
  d /= 2;
  d--;
  dist[x][y] = 1;
  for (int i = 1; i <= x + d; i++) {
    for (int j = y - d; j <= n; j++) {
      dist[i][j] = min(dist[i][j], 1 + dist[i][x] + dist[y][j]);
      dist[j][i] = dist[i][j];
    }
  }

  int arr[n + 1];
  memset(arr, 0, sizeof(arr));
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      arr[dist[i][j]]++;
  for (int i = 1; i <= n - 1; i++)
    cout << arr[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define endl "\\n"
#define maxn 100000
#define OO 1e5
#define F first
#define S second
#define B begin()
#define E end()
#define PB push_back
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  //	freopen("name.in","r",stdin);
  //	freopen("name.out","w",stdout);

  int n, x, y;
  cin >> n >> x >> y;

  int dist[n + 2][n + 2];
  memset(dist, 0, sizeof(dist));

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dist[i][j] = j - i;
      dist[j][i] = j - i;
    }
  }

  dist[min(x, y)][max(y, x)] = 1;

  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        dist[j][i] = dist[i][j];
      }
  int arr[n + 3];
  memset(arr, 0, sizeof(arr));
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      arr[dist[i][j]]++;

  for (int i = 1; i < n; i++)
    cout << arr[i] << endl;

  return 0;
}