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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int mid = (y + x) / 2;

  vector<int> count(n * n, 0);

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

  for (int k = 1; k <= n - 1; k++) {
    cout << count[k] << endl;
  }
  // for(int k=1; k<=n-1; k++){
  //     int ans = 0;
  //     for(int i=1; i<n; i++){
  //         for(int j=i+1; j<=n; j++){
  //             int res = min(j-i, abs(x-i) + 1 + abs(y-j));
  //             if(res == k) ans++;
  //         }
  //     }
  //     // ans += max(0, n - (y-x-1) - k);
  //     // cout << ans << "\\t";
  //     // for(int i=max(1, x-k+1); i+k<=mid && i<x; i++) ans++;
  //     // cout << ans << "\\t";
  //     // for(int i=x; i<=y; i++){
  //     //     if(i+k < y-x+1-k + i && i-k > x){
  //     //         ans++;
  //     //     }
  //     // }
  //     // cout << ans << "\\t";
  //     // for(int i=x; i+k<=y; i++){
  //     //     if(i+k >= y-x+1-k + i){
  //     //         ans++;
  //     //     }
  //     // }
  //     // cout << ans << "\\t";

  //     // for(int i=y-k+1; i<=y-1 && i+k<n; i++) ans++;

  //     cout << ans << endl;

  // }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int mid = (y + x) / 2;

  vector<vector<int>> res(n + 1, vector<int>(n + 1, 0));

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

  for (int k = 1; k <= n - 1; k++) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += count(res[i].begin(), res[i].end(), k);
    }
    cout << ans << endl;
  }
  // for(int k=1; k<=n-1; k++){
  //     int ans = 0;
  //     for(int i=1; i<n; i++){
  //         for(int j=i+1; j<=n; j++){
  //             int res = min(j-i, abs(x-i) + 1 + abs(y-j));
  //             if(res == k) ans++;
  //         }
  //     }
  //     // ans += max(0, n - (y-x-1) - k);
  //     // cout << ans << "\\t";
  //     // for(int i=max(1, x-k+1); i+k<=mid && i<x; i++) ans++;
  //     // cout << ans << "\\t";
  //     // for(int i=x; i<=y; i++){
  //     //     if(i+k < y-x+1-k + i && i-k > x){
  //     //         ans++;
  //     //     }
  //     // }
  //     // cout << ans << "\\t";
  //     // for(int i=x; i+k<=y; i++){
  //     //     if(i+k >= y-x+1-k + i){
  //     //         ans++;
  //     //     }
  //     // }
  //     // cout << ans << "\\t";

  //     // for(int i=y-k+1; i<=y-1 && i+k<n; i++) ans++;

  //     cout << ans << endl;

  // }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
using ll = long long;

const int mx = 2e3 + 5;
const int inf = 1e9 + 9;
const int mod = 1e9 + 7;

int n, ans[mx];
vector<int> adj[mx];

void bfs(int s) {
  vector<int> vis(n + 5, 0);
  vector<int> dis(n + 5, inf);

  vis[s] = 1;
  dis[s] = 0;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int &v : adj[u]) {
      if (!vis[v]) {
        vis[v] = 1;
        dis[v] = dis[u] + 1;
        if (v > s)
          ans[dis[v]]++;
        q.push(v);
      }
    }
  }
}

int main(int argc, const char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int x, y;

  cin >> n;
  for (int i = 1; i < n; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  cin >> x >> y;
  adj[x].pb(y);
  adj[y].pb(y);

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

  for (int i = 1; i < n; i++)
    cout << ans[i] << '\\n';
  return 0;
}

Error: 0

Fixed submission:

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

#define pb push_back
using ll = long long;

const int mx = 1e3 + 5;
const int inf = 1e9 + 9;
const int mod = 1e9 + 7;

int n, ans[mx];
vector<int> adj[mx];

void bfs(int s) {
  vector<int> vis(n + 5, 0);
  vector<int> dis(n + 5, inf);

  vis[s] = 1;
  dis[s] = 0;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int &v : adj[u]) {
      if (!vis[v]) {
        vis[v] = 1;
        dis[v] = dis[u] + 1;
        ans[dis[v]]++;
        q.push(v);
      }
    }
  }
}

int main(int argc, const char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int x, y;

  cin >> n;
  for (int i = 1; i < n; i++)
    adj[i].pb(i + 1);
  cin >> x >> y;
  adj[x].pb(y);

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

  for (int i = 1; i < n; i++)
    cout << ans[i] << '\\n';
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 2003
#define endl "\\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1 % mod;
  ll u = fpow(x, n / 2, mod);
  u = (u * u) % mod;
  if (n % 2 == 1)
    u = (u * x) % mod;
  return u;
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int N, X, Y;
vector<int> adj[MAXN];
int dist[MAXN], freq[MAXN];
bool visited[MAXN];
queue<int> q;

void BFS(int x) {
  memset(visited, false, sizeof visited);
  memset(dist, 0, sizeof dist);
  visited[x] = true;
  dist[x] = 0;
  q.push(x);
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto u : adj[s]) {
      if (visited[u])
        continue;
      visited[u] = true;
      dist[u] = dist[s] + 1;
      q.push(u);
    }
  }
}
int main() {
  // freopen("data.txt","r",stdin);
  cin >> N >> X >> Y;
  for (int i = 1; i < N; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  adj[X].pb(Y);
  adj[Y].pb(X);
  for (int i = 1; i <= N; i++) {
    BFS(i);
    for (int j = 1; j <= N; j++) {
      freq[dist[j]]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << freq[i] / 2 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 1003
#define endl "\\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1 % mod;
  ll u = fpow(x, n / 2, mod);
  u = (u * u) % mod;
  if (n % 2 == 1)
    u = (u * x) % mod;
  return u;
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int N, X, Y;
vector<int> adj[MAXN];
int dist[MAXN], freq[MAXN];
bool visited[MAXN];
queue<int> q;

void BFS(int x) {
  memset(visited, false, sizeof visited);
  memset(dist, 0, sizeof dist);
  visited[x] = true;
  dist[x] = 0;
  q.push(x);
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto u : adj[s]) {
      if (visited[u])
        continue;
      visited[u] = true;
      dist[u] = dist[s] + 1;
      q.push(u);
    }
  }
}
int main() {
  // freopen("data.txt","r",stdin);
  cin >> N >> X >> Y;
  for (int i = 1; i < N; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  adj[X].pb(Y);
  adj[Y].pb(X);
  for (int i = 1; i <= N; i++) {
    BFS(i);
    for (int j = 1; j <= N; j++) {
      freq[dist[j]]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << freq[i] / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: 0

Fixed submission:

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

int a[1111];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      a[min({abs(i - j), abs(i - x) + 1 + abs(y - j),
             abs(i - y) + 1 + abs(x - j)})]++;
  for (int i = 1; i < n; i++)
    cout << a[i] << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll n, x, y;

vector<vector<int>> graph(10001);
vector<int> counter(10001);

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

  REP(i, n - 1) {
    graph[i].push_back(i + 1);
    graph[i + 1].push_back(i);
  }

  graph[x - 1].push_back(y - 1);
  graph[y - 1].push_back(x - 1);

  REP(j, n) {
    queue<int> que;
    vector<bool> seen(n + 10);
    vector<int> d(n + 10);
    que.push(j);
    d[j] = 0;
    int res = 0;
    seen[j] = true;
    while (!que.empty()) {
      int c = que.front();
      que.pop();

      if (j < c) {
        counter[d[c]]++;
      }

      for (int k = 0; k < graph[c].size(); k++) {
        int nex = graph[c][k];

        if (seen[nex]) {
          continue;
        }

        seen[nex] = true;

        que.push(nex);
        d[nex] = d[c] + 1;
      }
    }
  }

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll n, x, y;

vector<vector<int>> graph(1001);
vector<int> counter(1001);
vector<pair<int, int>> comb(1001);

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

  REP(i, n - 1) {
    graph[i].push_back(i + 1);
    graph[i + 1].push_back(i);
  }

  graph[x - 1].push_back(y - 1);
  graph[y - 1].push_back(x - 1);

  REP(j, n) {
    queue<int> que;
    vector<bool> seen(n);
    vector<int> d(n);
    que.push(j);
    d[j] = 0;
    int res = 0;
    seen[j] = true;
    while (!que.empty()) {
      int c = que.front();
      que.pop();

      if (j < c) {
        counter[d[c]]++;
      }

      // if(d[c] == 2) {
      //     cout << "(" << j+1 << "," << c+1 << ")" << endl;
      // }

      for (int k = 0; k < graph[c].size(); k++) {
        int nex = graph[c][k];

        // if(c >= nex) {
        //     continue;
        // }

        if (seen[nex]) {
          continue;
        }

        seen[nex] = true;

        que.push(nex);
        d[nex] = d[c] + 1;
      }
    }
  }

  REP(i, n - 1) { cout << counter[i + 1] << endl; }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\\n';
#define OUT(n) cout << (n) << '\\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

  vector<int> ans(n + 1);
  REP(i, n) FOR(j, i + 1, n) {
    int d = j - i;
    int dx = abs(x - i);
    int dy = abs(y - j);
    d = min(d, dx + dy + 1);
    ans[d]++;
  }

  FOR(i, 1, n) { OUT(ans[i]) }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\\n';
#define OUT(n) cout << (n) << '\\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS const int INF = 1e9;
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<vector<int>> g(n, vector<int>(n, INF));
  REP(i, n) {
    if (i != 0)
      g[i][i - 1] = 1;
    if (i != n - 1)
      g[i][i + 1] = 1;
  }
  g[x][y] = 1;
  g[y][x] = 1;

  REP(k, n) REP(i, n) REP(j, n) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); }
  vector<int> ans(n + 1);
  REP(i, n) FOR(j, i + 1, n) { ans[g[i][j]]++; }

  FOR(i, 1, n) { OUT(ans[i]) }

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

#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
vector<bool> seen;
vector<int> ans(3000, 0);
int d[3000][3000];
vector<vector<int>> G(3000);

void bfs(int s) {
  queue<int> q;
  q.push(s);
  seen[s] = true;

  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto next_v : G[v]) {
      if (seen[next_v])
        continue;
      seen[next_v] = true;
      q.push(next_v);
      d[s][next_v] = d[s][v] + 1;
      ans[d[s][next_v]]++;
    }
  }
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  FOR(i, N - 1) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);
  FOR(i, N) FOR(j, N) d[i][j] = 0;

  FOR(i, N) {
    seen.assign(N, false);
    bfs(i);
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAX_N 3000
#define INF 10000000
typedef pair<int, int> P; // firstが最短距離 secondが頂点の番号
struct edge {
  int to, cost;
};
int N, X, Y;           // 頂点数と辺の張られるやつ
vector<edge> G[MAX_N]; // グラフ
int d[MAX_N];          // 頂点sからの最短距離
int ans, k;

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + N + 1, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }

  for (int i = 1; i <= N; i++) {
    if (d[i] == k)
      ans++;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> X >> Y;
  for (int i = 1; i <= N; i++) {
    if (i - 1 >= 1)
      G[i].push_back({i - 1, 1});
    if (i + 1 <= N)
      G[i].push_back({i + 1, 1});
    if (i == X)
      G[i].push_back({Y, 1});
    if (i == Y)
      G[i].push_back({X, 1});
  }

  cout << N << endl;
  for (k = 2; k <= N - 2; k++) {
    ans = 0;
    for (int i = 1; i <= N; i++)
      dijkstra(i);
    cout << ans / 2 << endl;
  }
  cout << 0 << endl;
  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;
  vector<int> cnt(N);

  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      int k;
      k = min(j - i, abs(i - X) + abs(j - Y) + 1);
      cnt[k]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << cnt[i] << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

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

int main() {
  int X, Y, A, B, C, a = 0, b = 0, c = 1;
  unsigned long long int sum = 0;
  bool a_ = true, b_ = true;
  cin >> X >> Y >> A >> B >> C;

  vector<int> p(A), q(B), r(C);

  rep(i, A) { cin >> p.at(i); }
  rep(i, B) { cin >> q.at(i); }
  rep(i, C) { cin >> r.at(i); }

  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());

  rep(i, C) {
    if (C - c >= 0) {
      if (p.at(A - X + a) > q.at(B - Y + b)) {
        if (q.at(B - Y + b) < r.at(C - c)) {
          q.at(B - Y + b) = r.at(C - c);
          b++;
          c++;
          if (B - Y + b == B) {
            b--;
            b_ = false;
          }
        }
      } else if (p.at(A - X + a) <= q.at(B - Y + b)) {
        if (p.at(A - X + a) < r.at(C - c)) {
          p.at(A - X + a) = r.at(C - c);
          a++;
          c++;
          if (A - X + a == A) {
            a--;
            a_ = false;
          }
        }
      }
    }
  }

  rep(i, X) { sum += p.at(A - i - 1); }

  rep(i, Y) { sum += q.at(B - i - 1); }

  cout << sum << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int k = 1;
  int num = 0;
  while (k < n) {
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (j <= x || i >= y) {
          if (j - i == k)
            // cout<<i<<"@"<<j<<"  ";
            num++;
        } else if (i <= x && j >= y) {
          if ((j - i) - (y - x) + 1 == k) // cout<<i<<"@"<<j<<"  ";
            num++;
        } else if (i >= x && j <= y) {
          int s1 = j - i, s2 = (y - j) + (i - x) + 1;
          int s3 = s1 > s2 ? s2 : s1;
          if (s3 == k) // cout<<i<<"@"<<j<<"  ";
            num++;
        } else if (i <= y && i >= x && j >= y) {
          int s1 = j - i, s2 = (j - y) + (i - x) + 1;
          int s3 = s1 > s2 ? s2 : s1;
          if (s3 == k) // cout<<i<<"@"<<j<<"  ";
            num++;
        } else if (i <= x && j <= y && j >= x) {
          int s1 = j - i, s2 = (y - j) + (x - i) + 1;
          int s3 = s1 > s2 ? s2 : s1;
          if (s3 == k) // cout<<i<<"@"<<j<<"  ";
            num++;
        }
      }
    }
    cout << num << endl;
    num = 0;
    k++;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

/*
  In the name of ALLAH
  Author : Raashid Anwar
*/

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

#define int int64_t
const int M = 1000000007;

int ans[2001];
int vis[2001];
vector<int> adj[2001];

void solve(int i) {
  memset(vis, 0, sizeof(vis));
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  int d, u;
  q.push({int(0), i});
  while (!q.empty()) {
    d = q.top().first;
    u = q.top().second;
    q.pop();
    if (vis[u])
      continue;
    vis[u] = 1;
    ans[d]++;
    for (int v : adj[u])
      if (!vis[v])
        q.push({d + 1, v});
  }
  return;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // #endif
  int n, x, y;
  cin >> n >> x >> y;
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 1; i <= n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    solve(i);
  for (int i = 1; i < n; i++)
    cout << (ans[i] / 2) << " ";
}

Error: WA

Fixed submission:

/*
  In the name of ALLAH
  Author : Raashid Anwar
*/

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

#define int int64_t
const int M = 1000000007;

int ans[1001];
int vis[1001];
vector<int> adj[1001];

void solve(int i) {
  memset(vis, 0, sizeof(vis));
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  int d, u;
  q.push({int(0), i});
  while (!q.empty()) {
    d = q.top().first;
    u = q.top().second;
    q.pop();
    if (vis[u])
      continue;
    vis[u] = 1;
    ans[d]++;
    for (int v : adj[u])
      if (!vis[v])
        q.push({d + 1, v});
  }
  return;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // #endif
  int n, x, y;
  cin >> n >> x >> y;
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 1; i <= n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    solve(i);
  for (int i = 1; i < n; i++)
    cout << (ans[i] / 2) << " ";
}
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;
  --x;
  --y;

  vector<int> v(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);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      dist[i][j] = min(dist[i][j], dist[i][x] + dist[y][j] + 1);
      dist[i][j] = min(dist[i][j], dist[i][y] + dist[x][j] + 1);
      ++v[dist[i][j]];
    }
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int sr, int ds, Weight we) : src(sr), dst(ds), weight(we) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight
             ? e.weight > f.weight
             : (e.src != f.src ? e.src < f.src : e.dst < f.dst);
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const int INF = 1e9;
// Warshall-Floyd法 O(V^3)
// main内でGraph g;vector<vector<Weight>> dist;vector<vector<int>> inter;を用意
// 引数
// g:隣接リスト,dist:各頂点から各頂点までの距離が入る,inter:最短路木の親頂点が入る
// 戻値 負閉路が存在しない場合:true,そうでないとき:false
bool spwf(const Graph &g, vector<vector<Weight>> &dist,
          vector<vector<int>> &inter) {
  int n = g.size();
  dist.assign(n, vector<Weight>(n, INF));
  for (int i = 0; i < n; i++)
    dist[i][i] = 0;
  for (int i = 0; i < n; i++) {
    for (auto f : g[i])
      dist[i][f.dst] = f.weight;
  }
  inter.assign(n, vector<int>(n, -1));
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dist[i][k] < INF && dist[k][j] < INF &&
            dist[i][j] > dist[i][k] + dist[k][j]) {
          dist[i][j] = dist[i][k] + dist[k][j];
          inter[i][j] = k;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (dist[i][i] < 0)
      return false;
  }
  return true;
}
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;

  Graph g(n);
  vector<vector<Weight>> dist;
  vector<vector<int>> inter;
  for (int i = 0; i < n - 1; ++i) {
    g[i].push_back(Edge(i, i + 1, 1));
    g[i + 1].push_back(Edge(i + 1, i, 1));
  }
  g[x].push_back(Edge(x, y, 1));
  g[y].push_back(Edge(y, x, 1));
  spwf(g, dist, inter);

  for (int k = 1; k < n; ++k) {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (dist[i][j] == k)
          ++cnt;
      }
    }
    cout << cnt << endl;
  }
}