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

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

int intabs(int a) {
  if (a < 0) {
    a = -a;
  }
  return a;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<int> c(n - 1, 0);
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        continue;
      // int idx = 1;
      int idx = intabs(i - j);
      if (idx > intabs(x - i) + 1 + intabs(y - j)) {
        idx = intabs(x - i) + 1 + intabs(y - j);
      }
      if (idx > intabs(y - i) + 1 + intabs(x - j)) {
        idx = intabs(y - i) + 1 + intabs(x - j);
      }

      --idx;
      ++c.at(idx);
    }
  }
  rep(i, n - 1) { printf("%d\\n", c.at(i) / 2); }
}

Error: TLE

Fixed submission:

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

vector<int> check(int p1, int p2, int d2, vector<int> c) {
  int n = c.size();
  if (p1 >= p2 || p1 < 0 || p2 > n - 1) {
    return c;
  }
  int d1 = p2 - p1;
  if (d1 > d2) {
    c.at(d1) -= 1;
    c.at(d2) += 1;
  }
  return c;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<int> c;
  rep(i, n) { c.push_back(n - i); }
  rep(i, n) {
    rep(j, n) {
      if (i == 0 && j == 0) {
        c = check(x, y, 1, c);
      } else if (i == 0) {
        c = check(x, y + j, 1 + j, c);
        c = check(x, y - j, 1 + j, c);
      } else if (j == 0) {
        c = check(x + i, y, 1 + i, c);
        c = check(x - i, y, 1 + i, c);
      } else {
        c = check(x + i, y + j, 1 + i + j, c);
        c = check(x + i, y - j, 1 + i + j, c);
        c = check(x - i, y + j, 1 + i + j, c);
        c = check(x - i, y - j, 1 + i + j, c);
      }
    }
  }
  c.erase(c.begin());
  rep(i, n - 1) { printf("%d\\n", c.at(i)); }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1e9 + 7;
int main() {
  ll n, val, i, j, k, c, s = 0, x, y, a, b;
  string ss;
  cin >> n >> x >> y;
  vector<ll> v;
  for (i = 0; i < n - 1; i++)
    v.push_back(0);
  //
  ll dp[n + 2][n + 2];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++)
      dp[i][j] = 0;
  }
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++) {
      dp[i][j] = min(abs(j - i), abs(x - i) + 1 + abs(y - j));
    }
  }

  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j++) {
      //	cout<<dp[i][j]<<"   ";
      //	cout<<endl;
      v[dp[i][j]]++;
    }
    //	cout<<endl;
  }
  for (i = 1; i < n; i++) {
    cout << v[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1e9 + 7;
int main() {
  ll n, val, i, j, k, c, s = 0, x, y;
  string ss;
  cin >> n >> x >> y;
  ll dp[n + 2][n + 2];

  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++)
      dp[i][j] = inf;
  }
  for (i = 1; i <= n; i++)
    dp[i][i] = 0;
  for (i = 1; i < n; i++) {
    dp[i][i + 1] = 1;
    dp[i + 1][i] = 1;
  }

  dp[x][y] = 1;
  dp[y][x] = 1;
  for (k = 1; k <= n; k++) {
    for (j = 1; j <= n; j++) {
      for (i = 1; i <= n; i++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  for (k = 1; k < n; k++) {
    s = 0;
    for (j = 1; j <= n; j++) {
      for (i = j + 1; i <= n; i++) {
        if (dp[i][j] == k)
          s++;
      }
    }
    cout << s << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

int main() {
  ll n, x, y, ans, i, j;
  cin >> n >> x >> y;
  vector<ll> k(n - 1, 0);
  for (i = 2; i <= n; i++) {
    for (j = 1; j < i; j++) {
      k[min({i - j, abs(x - i) + abs(y - j) + 1, abs(x - j) + abs(y - i) + 1}) -
        1]++;
      // cout<<i<<"_"<<j<<"_"<<min({i-j,abs(x-i)+abs(y-j)+1,abs(x-j)+abs(y-i)+1})<<endl;
    }
  }

  for (i = 0; i < n - 1; i++)
    cout << k[i] << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

int main() {
  ll n, x, y, ans, i, j;
  cin >> n >> x >> y;
  vector<ll> k(n - 1);
  for (i = 0; i < n - 1; i++) {
    for (j = 0; j < i; j++) {
      k[min({i - j, abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)}) - 1]++;
    }
  }

  for (i = 0; i < n - 1; i++)
    cout << k[i] << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  map<ll, ll> mp;
  for (int i = 1; i < n; i++)
    mp[i] = 0;

  for (ll i = 1; i < n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      mp[min(min(j - i, abs(x - i) + 1 + abs(j - y)),
             abs(y - i) + 1 + abs(j - x))]++;
    }
  }

  for (int i = 1; i < n; i++)
    cout << mp[i] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  x--, y--;
  rep(_k, n - 1) {
    ll k = _k + 1;
    ll count = 0;
    for (ll start = 0; start < n; start++) {
      for (ll end = start + 1; end < n; end++) {
        ll mdis;
        if ((start <= x && end <= x) || (y < start && y < end)) {
          mdis = end - start;
        } else if ((start <= x && x < end && end <= y)) {
          mdis = min(end - start, (x - start) + abs(y - end) + 1);
        } else if ((start <= x && y < end)) {
          mdis = (x - start) + (end - y) + 1;
        } else if (x < start && start <= y && x < end && end <= y) {
          mdis = min(end - start, start - x + y - end + 1);
        } else if (x < start && start <= y && y < end) {
          mdis = min(end - start, end - y + start - x + 1);
        }
        if (mdis == k) {
          // cout << "start: " << start << " " << "end: " << end << endl;
          count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define D(x) cout << "D: " << #x << '=' << x << endl;
#define R(x, l)                                                                \\
  cout << "R: Array " << #x << endl;                                           \\
  for (int i = 0; i < l; i++)                                                  \\
    cout << ' ' << i << ':' << *(x + i) << endl;
#define pb push_back
using namespace std;

int n, x, y;
int ans[2005];

int main(void) {
  cin >> n >> x >> y;
  x--;
  y--;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      ans[min(j - i, (abs(x - i) + abs(y - j)) + 1)]++;
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int n, x, y, sum;
int ans[205];
bool vis[205];
vector<int> v[205];

int dfs(int a, int b, int M) {
  if (vis[a])
    return 0;
  vis[a] = true;
  for (int i = 0; i < v[a].size(); i++) {
    if (v[a][i] == b) {
      sum = min(sum, M);
      vis[a] = false;
      return 0;
    } else
      dfs(v[a][i], b, M + 1);
  }
  vis[a] = false;
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);

  cin >> n >> x >> y;
  for (int i = 0; i < n - 1; i++) {
    v[i].push_back(i + 1);
    v[i + 1].push_back(i);
  }
  v[x - 1].push_back(y - 1);
  v[y - 1].push_back(x - 1);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      memset(vis, 0, sizeof(vis));
      sum = 205;
      dfs(i, j, 1);
      ans[sum]++;
    }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int n, x, y;

void solve() {
  vector<int> cnt(n + 1);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist =
          min(j - i, min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1);
      cnt[dist]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}

int main() {
  cin >> n >> x >> y;
  solve();
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int n, x, y;

void solve() {
  vector<int> cnt(n + 1);
  for (int i = 1; i < n; i++) {
    for (int j = 2; j <= n; j++) {
      int dist =
          min(j - i, min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1);
      cnt[dist]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}

int main() {
  cin >> n >> x >> y;
  solve();
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int64_t N, X, Y;
vector<int64_t> D(2010, -1);
vector<vector<int64_t>> Graph(2010);
vector<int64_t> Count(2010, 0);
queue<int64_t> Q;

int main() {
  cin >> N >> X >> Y;
  for (int i = 1; i <= N; i++) {
    if (i != N)
      Graph.at(i).push_back(i + 1);
    if (i != 0)
      Graph.at(i + 1).push_back(i);
  }
  Graph.at(X).push_back(Y);
  Graph.at(Y).push_back(X);
  for (int k = 1; k <= N; k++) {
    Q.push(k);
    D.at(k) = 0;
    while (!Q.empty()) {
      int64_t node = Q.front();
      Q.pop();
      for (int64_t i = 0; i < Graph.at(node).size(); i++) {
        int64_t nextNode = Graph.at(node).at(i);
        if (D.at(nextNode) == -1) {
          int64_t nextNodeCopy = nextNode;
          Q.push(nextNodeCopy);
          int64_t nextStep = D.at(node) + 1;
          D.at(nextNode) = nextStep;
          Count.at(nextStep)++;
        }
      }
    }
    for (int64_t i = 0; i < D.size(); i++)
      D.at(i) = -1;
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << Count.at(i) / 2 << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int64_t N, X, Y;
vector<int64_t> D(2001, -1);
vector<vector<int64_t>> Graph(2001);
vector<int64_t> Count(2001, 0);
queue<int64_t> Q;

int main() {
  cin >> N >> X >> Y;
  for (int i = 1; i <= N; i++) {
    if (i != N)
      Graph.at(i).push_back(i + 1);
    if (i != 0)
      Graph.at(i + 1).push_back(i);
  }
  Graph.at(X).push_back(Y);
  Graph.at(Y).push_back(X);
  for (int k = 1; k <= N; k++) {
    Q.push(k);
    D.at(k) = 0;
    while (!Q.empty()) {
      int64_t node = Q.front();
      Q.pop();
      for (int64_t i = 0; i < Graph.at(node).size(); i++) {
        int64_t nextNode = Graph.at(node).at(i);
        if (D.at(nextNode) == -1) {
          Q.push(nextNode);
          int64_t nextStep = D.at(node) + 1;
          D.at(nextNode) = nextStep;
          Count.at(nextStep)++;
        }
      }
    }
    for (int64_t i = 0; i < D.size(); i++)
      D.at(i) = -1;
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << Count.at(i) / 2 << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int ml[100009];

  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int len = min(min(abs(j - i), abs(x - i) + 1 + abs(j - y)),
                    abs(y - i) + 1 + abs(j - x));
      ml[len]++;
    }
  }

  for (int k = 1; k < n; k++) {
    cout << ml[k] << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;

  for (int k = 1; k < n; k++) {
    int cnt = 0;
    for (int i = 1; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int min_len = min(min(abs(j - i), abs(x - i) + 1 + abs(j - y)),
                          abs(y - i) + 1 + abs(j - x));
        if (min_len == k)
          cnt++;
      }
    }
    cout << cnt << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 200;
typedef long long ll;
ll n, X, Y;
ll cnt[N];
int main() {
  cin >> n >> X >> Y;
  X--, Y--;
  for (ll i = 0; i < n; i++) {
    ll v;
    for (ll j = i + 1; j < n; j++) {
      v = min(
          {j - i, abs(i - X) + abs(j - Y) + 1, abs(i - Y) + abs(j - X) + 1});
      cnt[v]++;
    }
  }
  for (int i = 1; i < n; i++) {
    printf("%lld\\n", cnt[i]);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 200;
typedef long long ll;
int mp[N][N], n, X, Y;
int cnt[N];
int main() {
  cin >> n >> X >> Y;
  X--, Y--;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      mp[i][j] = mp[j][i] = 1e9;
    }
    mp[i][i] = 0;
  }
  for (int i = 0; i < n - 1; i++)
    mp[i][i + 1] = mp[i + 1][i] = 1;
  mp[X][Y] = mp[Y][X] = 1;
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
      }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      cnt[mp[i][j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++)
    printf("%d\\n", cnt[i]);
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

static const int INF = (1 << 21);

int n, x, y;
int cou[2001], d[2001][2001];
vector<int> M[2001];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i < n; i++) {
    d[s][i] = INF;
  }
  d[s][s] = 0;
  int u = 0;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int v : M[u]) {
      if (d[s][v] != INF)
        continue;
      d[s][v] = d[s][u] + 1;
      q.push(v);
    }
  }
}

int main() {
  cin >> n >> x >> y;
  x--;
  y--;

  M[x].push_back(y);
  M[y].push_back(x);

  for (int i = 0; i < n - 1; i++) {
    M[i].push_back(i + 1);
    M[i + 1].push_back(i);
  }

  for (int i = 0; i < n; i++)
    bfs(i);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] == INF)
        continue;
      else
        cou[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << cou[i] / 2 << endl;
}

Error: TLE

Fixed submission:

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

static const int INF = (1 << 21);

int n, x, y;
int cou[2001], M[2001][2001], d[2001][2001];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i < n; i++) {
    d[s][i] = INF;
  }
  d[s][s] = 0;
  int u = 0;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int v = 0; v < n; v++) {
      if (M[u][v] == 0)
        continue;
      if (d[s][v] != INF)
        continue;
      d[s][v] = d[s][u] + 1;
      q.push(v);
    }
  }
}

int main() {
  cin >> n >> x >> y;
  x--;
  y--;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      M[i][j] = 0;
  }

  M[x][y] = 1;
  M[y][x] = 1;

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

  for (int i = 0; i < n; i++)
    bfs(i);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] == INF)
        continue;
      else
        cou[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << cou[i] / 2 << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int zet(int a, int b) {
  if (a - b >= 0) {
    return a - b;
  }
  if (a - b < 0) {
    return b - a;
  }
}
int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> vec(N + 1);
  vector<vector<int>> A(N + 1, vector<int>(N + 1));
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j < N + 1; j++) {
      A.at(i).at(j) = min(
          zet(i, j), min(zet(X, i) + zet(Y, j) + 1, zet(X, j) + zet(Y, i) + 1));
    } // A.at(i).at(j)=(i,j)の最短距離
  }

  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j < N + 1; j++) {
      vec.at(A.at(i).at(j))++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << vec.at(i) << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int zet(int a, int b) {
  if (a - b >= 0) {
    return a - b;
  }
  if (a - b < 0) {
    return b - a;
  }
}
int main() {
  int N, X, Y;
  vector<int> vec(N + 1);
  cin >> N >> X >> Y;
  vector<vector<int>> A(N + 1, vector<int>(N + 1));
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N + 1; j++) {
      A.at(i).at(j) = min(
          zet(i, j), min(zet(X, i) + zet(Y, j) + 1, zet(X, j) + zet(Y, i) + 1));
    } // A.at(i).at(j)=(i,j)の最短距離
  }
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N + 1; j++) {
      vec.at(A.at(i).at(j))++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << vec.at(i) << endl;
    cout << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, y, i, j, k, a, b;
  cin >> n >> x >> y;
  long long int arr[n + 1][n + 1];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      arr[i][j] = max(i - j, j - i);
    }
  }
  arr[x][y] = 1;
  arr[y][x] = 1;
  /*for(i=1;i<=n;i++){
          for(j=1;j<=n;j++){
                  cout<<arr[i][j]<<" ";
          }
          cout<<endl;
  }*/
  // cout<<endl;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      /*if(arr[i][y]>arr[i][x]+1){
              arr[i][y]=arr[i][x]+1;
              arr[y][i]=arr[i][x]+1;
      }
      else if(arr[i][x]>arr[i][y]+1){
              arr[i][x]=arr[i][y]+1;
              arr[x][i]=arr[i][y]+1;
      }*/
      if (arr[i][j] > arr[i][x] + arr[y][j] + 1) {
        arr[i][j] = arr[i][x] + arr[y][j] + 1;
        arr[j][i] = arr[i][x] + arr[y][j] + 1;
      }
    }
  }

  /*}
   */
  /*for(i=1;i<=n;i++){
          for(j=1;j<=n;j++){
                  cout<<arr[i][j]<<" ";
          }
          cout<<endl;
  }*/
  long long int res[n];
  for (i = 0; i < n; i++) {
    res[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      res[arr[i][j]]++;
    }
  }
  for (i = 1; i < n; i++) {
    cout << res[i] / 2 << endl;
  }
  /*for(i=1;i<n;i++){
          k=0;
          for(a=1;a<=n;a++){
                  for(b=a;b<=n;b++){
                          if(arr[a][b]==i){
                                  k++;
                          }
                  }
          }
          cout<<k<<endl;
  }*/
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, y, i, j, k, a, b;
  cin >> n >> x >> y;
  long long int arr[n + 1][n + 1];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      arr[i][j] = max(i - j, j - i);
    }
  }
  arr[x][y] = 1;
  arr[y][x] = 1;
  /*for(i=1;i<=n;i++){
          for(j=1;j<=n;j++){
                  cout<<arr[i][j]<<" ";
          }
          cout<<endl;
  }*/
  // cout<<endl;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      /*if(arr[i][y]>arr[i][x]+1){
              arr[i][y]=arr[i][x]+1;
              arr[y][i]=arr[i][x]+1;
      }
      else if(arr[i][x]>arr[i][y]+1){
              arr[i][x]=arr[i][y]+1;
              arr[x][i]=arr[i][y]+1;
      }*/
      if (arr[i][j] > arr[i][x] + arr[y][j] + 1) {
        arr[i][j] = arr[i][x] + arr[y][j] + 1;
        arr[j][i] = arr[i][x] + arr[y][j] + 1;
      }
    }
  }

  /*}
   */
  /*for(i=1;i<=n;i++){
          for(j=1;j<=n;j++){
                  cout<<arr[i][j]<<" ";
          }
          cout<<endl;
  }*/
  for (i = 1; i < n; i++) {
    k = 0;
    for (a = 1; a <= n; a++) {
      for (b = a; b <= n; b++) {
        if (arr[a][b] == i) {
          k++;
        }
      }
    }
    cout << k << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

#define INF 1000000001

using namespace std;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  int ans[N];
  fill(ans, ans + N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      int dist = min(j - i, abs(i - X) + 1 + abs(j - Y));
      ans[dist]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

#define INF 1000000001

using namespace std;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  int d[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++)
      d[i][j] = INF;
  }
  for (int i = 0; i < N; i++) {
    d[i][i] = 0;
    if (i < N - 1) {
      d[i][i + 1] = 1;
      d[i + 1][i] = 1;
    }
  }
  d[X - 1][Y - 1] = 1;
  d[Y - 1][X - 1] = 1;
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (d[i][j] > d[i][k] + d[j][k]) {
          d[i][j] = d[i][k] + d[j][k];
        }
      }
    }
  }
  int ans[N];
  fill(ans, ans + N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      ans[d[i][j]]++;
    }
  }
  for (int i = 1; i < N; i++)
    cout << ans[i] / 2 << endl;
  return 0;
}