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

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define INF 1e9
#define MAXN 2005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N, X, Y;
map<int, int> mp;

int d[MAXN][MAXN];

// void warshall_floyd() {
//     for(int i = 0; i < N; i++) {
//         for(int j = i+1; j < N; j++) {
//             for(int k = 0; k < N; k++) {
//                     d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
//                     d[j][i] = d[i][j];
//             }
//         }
//     }

// }

int calc_dist(int i, int j) {
  if (i == X && j == Y)
    return 1;

  if ((i <= X && j <= X) || (Y <= i && Y <= j))
    return abs(i - j);
  else {
    int tmp = abs(X - i) + 1 + abs(Y - j);

    return min(abs(i - j), tmp);
  }
}

void solve() {
  rep(i, N) {
    for (int j = i + 1; j < N; ++j) {
      // cout << "Node " << i << " to " << j << ": " << d[i][j] << endl;
      mp[calc_dist(i, j)]++;
    }
  }

  // for(auto itr = mp.begin(); itr!=mp.end(); ++itr){
  //     cout << itr->first << " " << itr->second << endl;
  // }

  auto itr = mp.begin();
  for (int i = 1; i < N; ++i) {
    if (itr->first == i) {
      cout << itr->second << endl;
      ++itr;
    } else
      cout << 0 << endl;
  }
}

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

  rep(i, N) fill(d[i], d[i] + N, INF);

  rep(i, N - 1) {
    d[i][i] = 0;
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }

  d[X][Y] = 1;
  d[Y][X] = 1;

  solve();
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define INF 1e9
#define MAXN 2005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N, X, Y;
map<int, int> mp;

int d[MAXN][MAXN];

void warshall_floyd() {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if ((i <= X && j <= X) || (Y <= i && Y <= j)) {
          d[i][j] = abs(j - i);
        } else
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

void solve() {
  warshall_floyd();

  rep(i, N) {
    for (int j = i + 1; j < N; ++j) {
      // cout << "Node " << i << " to " << j << ": " << d[i][j] << endl;
      mp[d[i][j]]++;
    }
  }

  // for(auto itr = mp.begin(); itr!=mp.end(); ++itr){
  //     cout << itr->first << " " << itr->second << endl;
  // }

  auto itr = mp.begin();
  for (int i = 1; i < N; ++i) {
    if (itr->first == i) {
      cout << itr->second << endl;
      ++itr;
    } else
      cout << 0 << endl;
  }
}

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

  rep(i, N) fill(d[i], d[i] + N, INF);

  rep(i, N - 1) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }

  d[X][Y] = 1;
  d[Y][X] = 1;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 10101;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n, 0);
  for (int i = 1; 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;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 10101;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> d(n + 1, vector<int>(n + 1, INF));
  rep(i, n) d[i][i] = 0; // 自身にはコスト0
  map<int, int> m;
  rep(i, n) {
    d[i][i + 1] = min(d[i][i + 1], 1);
    d[i + 1][i] = min(d[i + 1][i], 1);
    // 小さいコストを使う
  }
  d[x - 1][y - 1] = 1;
  d[y - 1][x - 1] = 1;
  // ここから
  rep(k, n) rep(i, n) rep(j, n) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
  rep(i, n - 1) {
    for (int j = i; j < n; j++) {
      m[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << m[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> MX;

const ll MOD = 1e9 + 7;
const int INF = 100000000;

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

  vector<vector<int>> v(N);
  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);

  vector<int> R = vector<int>(N + 1, 0);
  for (int s = 0; s < N; s++) {
    queue<int> Q;
    Q.push(s);
    vector<int> d(N, INF);
    d[s] = 0;
    while (!Q.empty()) {
      int p = Q.front();
      Q.pop();
      for (int j = 0; j < v[p].size(); j++) {
        if (d[v[p][j]] > d[p] + 1) {
          d[v[p][j]] = d[p] + 1;
          Q.push(v[p][j]);
        }
      }
    }
    for (int i = 0; i < N; i++)
      if (d[i] != INF)
        R[d[i]]++;
  }

  for (int i = 1; i < N; i++)
    cout << R[i] / 2 << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> MX;

const ll MOD = 1e9 + 7;
const int INF = 100000000;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  MX d = MX(N, vector<int>(N, INF));
  for (int i = 0; i < N; i++)
    d[i][i] = 0;
  for (int i = 0; i < N - 1; i++) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }
  d[X - 1][Y - 1] = 1;
  d[Y - 1][X - 1] = 1;
  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]);
  vector<int> R = vector<int>(N + 1, 0);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      R[d[i][j]]++;
  for (int i = 1; i < N; i++)
    cout << R[i] / 2 << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 2e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn], ans[maxn];
int main() {
  int n, k, x, y;
  cin >> n >> x >> y;
  fo(i, 1, n - 1) {
    fo(j, i + 1, n) {
      if (i <= x && j >= y)
        a[i][j] = j - i - (y - x - 1), a[j][i] = j - i - (y - x - 1);
      else
        a[i][j] = a[j][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
    }
  }
  fo(i, 1, n) {
    fo(j, i + 1, n) { ans[a[i][j]]++; }
  }
  fo(i, 1, n - 1) { cout << ans[i] << endl; }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn], ans[maxn];
int main() {
  int n, k, x, y;
  cin >> n >> x >> y;
  fo(i, 1, n - 1) {
    fo(j, i + 1, n) {
      if (i <= x && j >= y)
        a[i][j] = j - i - (y - x - 1), a[j][i] = j - i - (y - x - 1);
      else
        a[i][j] = a[j][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
    }
  }
  fo(i, 1, n) {
    fo(j, i + 1, n) { ans[a[i][j]]++; }
  }
  fo(i, 1, n - 1) { cout << ans[i] << endl; }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
// using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;
const double eps = DBL_EPSILON;

map<int, int> cnt;
vector<int> g[201000];

void go(int v, int n) {
  vector<bool> used(n + 1);
  vector<int> d(n + 1);
  queue<int> q;
  q.push(v);
  used[v] = true;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i : g[cur]) {
      if (!used[i]) {
        used[i] = true;
        d[i] = d[cur] + 1;
        q.push(i);
      }
    }
  }
  for (int &i : d)
    cnt[i]++;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEBUG
  freopen("input.txt", "r", stdin);
#endif
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    g[i].push_back(i + 1);
    g[i + 1].push_back(i);
  }
  g[y].push_back(x);
  g[x].push_back(y);
  for (int i = 1; i <= n; i++)
    go(i, n);
  for (int i = 1; i < n; i++)
    cout << cnt[i] / 2 << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
// using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;
const double eps = DBL_EPSILON;

struct edge {
  int a, b, cost;
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEBUG
  freopen("input.txt", "r", stdin);
#endif
  int n, x, y;
  cin >> n >> x >> y;
  vector<edge> e;
  for (int i = 1; i < n; i++) {
    e.push_back({i - 1, i, 1});
    e.push_back({i, i - 1, 1});
  }
  e.push_back({x - 1, y - 1, 1});
  e.push_back({y - 1, x - 1, 1});
  int m = e.size();
  map<int, int> cnt;
  for (int k = 0; k < n; k++) {
    vector<int> d(n, 1e9);
    d[k] = 0;
    for (int i = 0; i < n - 1; ++i) {
      for (int j = 0; j < m; ++j) {
        if (d[e[j].a] < 1e9)
          d[e[j].b] = min(d[e[j].b], d[e[j].a] + e[j].cost);
      }
    }
    for (int &i : d)
      cnt[i]++;
  }
  for (int i = 1; i < n; i++)
    cout << cnt[i] / 2 << "\\n";
  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<int> vec(N - 1, 0);
  int k;
  for (int i = 1; i <= N - 1; i++) {
    for (int j = i + 1; j <= N; j++) {
      k = min(j - i, abs(X - i) + 1 + abs(j - Y));
      vec.at(k - 1)++;
    }
  }
  for (int i = 0; i < N - 1; i++)
    cout << vec.at(i) << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  for (int k = 1; k < N; k++) {
    int ans = 0;
    for (int i = 1; i <= N - k; i++) {
      for (int j = i + 1; j <= N; j++) {
        if (k == min(j - i, abs(X - i) + 1 + abs(j - Y))) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;

#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define tcase()                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

void setIO(string name = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (sz(name)) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}

int main() {

  setIO();

  int n, l, r;
  cin >> n >> l >> r;

  int dif = r - l - 1;

  int arr[n + 1] = {0};

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      arr[min(
          {j - i, abs(l - i) + 1 + abs(j - r), abs(r - i) + 1 + abs(j - l)})]++;
    }
  }

  for (int i = 1; i < n; i++)
    cout << arr[i] << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int INF = 0x3f3f3f3f;

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

  cin >> n >> x >> y;
  vector<vector<int>> mat;
  mat.resize(n, vector<int>(n, INF));
  mat[x - 1][y - 1] = 1;
  mat[y - 1][x - 1] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        mat[i][j] = 0;
      if (i == j + 1 || j == i + 1)
        mat[i][j] = 1;
    }
  }

  for (int k = 0; k < n; k++) {

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

      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        if (mat[i][k] + mat[k][j] < mat[i][j])
          mat[i][j] = mat[i][k] + mat[k][j];
      }
    }
  }
  int cont;
  for (int i = 1; i < n; i++) {
    cont = 0;
    for (int k = 0; k < n - 1; k++) {
      for (int j = k + 1; j < n; j++) {
        if (mat[k][j] == i)
          cont++;
      }
    }
    cout << cont << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#pragma GCC optimize(2)

// #define int long long
#define mm(i, v) memset(i, v, sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second
// 你冷静一点，确认思路再敲！！！

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
priority_queue<PII, vector<PII>, greater<PII>> que;
stringstream ssin; //  ssin << string   while ( ssin >> int)

const int N = 3e5 + 5, M = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
int n, x, y;
int a[N];

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

const int maxn = 2 * 1000 + 10;
vector<int> graph[maxn];
int used[maxn][maxn];

void finddis(int dis, int &cnt, int start, int end) {
  if (dis == 0) {
    if (used[start][end] == 0 && end > start) {
      used[start][end] = 1;
      cnt++;
    }
    return;
  }
  dis--;
  for (int i = 0; i < graph[end].size(); i++) {
    finddis(dis, cnt, start, graph[end][i]);
  }
}

int main() {
  int n, x, y;
  memset(used, 0, sizeof(used));
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 0; i < n; i++) {
    if (i != 0) {
      graph[i].push_back(i - 1);
    }
    if (i != n - 1) {
      graph[i].push_back(i + 1);
    }
  }
  graph[x - 1].push_back(y - 1);
  graph[y - 1].push_back(x - 1);
  for (int i = 1; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      finddis(i, cnt, j, j);
    }
    printf("%d\\n", cnt);
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
const ll N = 11000, M = 1001001;
ll n, m, T, cnt, f[N][N], p[M], col[N][N], ans[N], x, y, z, k;
string s;
int main() {
  scanf("%lld%lld%lld", &n, &x, &y);
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      ll mi = (j - i);
      mi = min(mi, 1 + abs(i - x) + abs(j - y));
      mi = min(mi, 1 + abs(i - y) + abs(j - x));
      ans[mi]++;
    }
  for (int i = 1; i < n; i++)
    printf("%lld\\n", ans[i]);
}

Error: 0

Fixed submission:

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

int n, x, y;
int dis[1010][1010];
int cnt[1010];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      dis[i][j] = min(
          j - i, min(abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1));
      cnt[dis[i][j]]++;
    }
  for (int i = 1; i < n; i++)
    printf("%d\\n", cnt[i]);
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define for_tests(t, tt)                                                       \\
  int t;                                                                       \\
  scanf("%d", &t);                                                             \\
  for (int tt = 1; tt <= t; tt++)
#ifndef ONLINE_JUDGE
#define debug(args...) fprintf(stderr, args)
#else
#define debug(args...)
#endif // ONLINE_JUDGE
template <typename T> inline T abs(T t) { return t < 0 ? -t : t; }
const ll modn = 1000000007;
inline ll mod(ll x) { return x % modn; }

const int MAXN = 212345;

int n, m, k;

int mrk[MAXN], tempo;
int d[MAXN];
int cnt[MAXN];

int main() {
  int x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int ini = 1; ini <= n; ini++) {
    queue<int> q;
    q.push(ini);
    d[ini] = 0;
    tempo++;
    mrk[ini] = tempo;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      cnt[d[u]]++;
      if (u + 1 <= n && mrk[u + 1] != tempo) {
        q.push(u + 1);
        d[u + 1] = d[u] + 1;
        mrk[u + 1] = tempo;
      }
      if (u - 1 >= 1 && mrk[u - 1] != tempo) {
        q.push(u - 1);
        d[u - 1] = d[u] + 1;
        mrk[u - 1] = tempo;
      }
      int nxt = -1;
      if (u == x)
        nxt = y;
      if (u == y)
        nxt = x;
      if (nxt != -1 && mrk[nxt] != tempo) {
        q.push(nxt);
        mrk[nxt] = tempo;
        d[nxt] = d[u] + 1;
      }
    }
  }
  for (int a = 1; a < n; a++) {
    printf("%d\\n", cnt[a] / 2);
  }
}


Error: 0

Fixed submission:

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

typedef pair<int, int> ii;

const int N = 1e3 + 5;
const int oo = 1e9;

int n;
int res[N] = {0}, dist[N];
vector<int> AdjList[N];

void bfs(int s) {
  // cout<<"s:"<<s<<endl;
  for (int i = 0; i < n; ++i)
    dist[i] = oo;
  priority_queue<ii, vector<ii>, greater<ii>> pq;
  dist[s] = 0;
  pq.push({0, s});
  while (!pq.empty()) {
    ii nodo = pq.top();
    pq.pop();
    int d = nodo.first, u = nodo.second;
    // if(d > dist[u]) continue;
    res[d]++;
    for (int v : AdjList[u]) {

      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        // cout<<u<<"-"<<v<<" "<<dist[v]<<endl;
        pq.push({dist[v], v});
      }
    }
  }
}

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

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

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

  for (int i = 1; i < n; ++i) {
    cout << (res[i] >> 1) << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\\n'

constexpr int N = 2020;
constexpr int INF = 1e9;
int dp[N][N];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  x--, y--;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;

      int a = i, b = j;
      if (a > b)
        swap(a, b);
      dp[i][j] = b - a;
    }
  }

  dp[x][y] = 1;
  dp[y][x] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      dp[i][j] =
          min({dp[i][j], dp[i][x] + dp[y][j] + 1, dp[i][y] + dp[x][j] + 1});
    }
  }

  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      mp[dp[i][j]]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << mp[i] / 2 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\\n'

constexpr int N = 2020;
constexpr int INF = 1e9;
int dp[N][N];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  x--, y--;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = INF;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;

      int a = i, b = j;
      if (a > b)
        swap(a, b);
      dp[i][j] = b - a;
    }
  }

  dp[x][y] = 1;
  dp[y][x] = 1;

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }

  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dp[i][j] == INF)
        continue;

      mp[dp[i][j]]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << mp[i] / 2 << endl;
  }
}