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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1 << 30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (ll i = 0; i < (ll)v.size(); i++)
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}

ll n, x, y;

void solve() {
  cin >> n >> x >> y;
  x--, y--;
  vector<vector<ll>> G(n);
  for (ll i = 0; i < n - 1; i++) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[x].push_back(y);
  G[y].push_back(x);

  map<ll, ll> mp;
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll k = min(abs(i - j), abs(i - x) + abs(j - y) + 1);
      mp[k]++;
    }
  }
  for (ll k = 1; k < n; k++) {
    cout << mp[k] << endl;
  }
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1 << 30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (ll i = 0; i < (ll)v.size(); i++)
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}

ll n, x, y;

void solve() {
  cin >> n >> x >> y;
  x--, y--;
  vector<vector<ll>> dp(n, vector<ll>(n, INF));
  for (ll i = 0; i < n; i++)
    dp[i][i] = 0;
  for (ll i = 0; i < n - 1; i++) {
    dp[i][i + 1] = 1;
    dp[i + 1][i] = 1;
  }
  dp[x][y] = 1;
  dp[y][x] = 1;
  for (ll k = 0; k < n; k++) {
    for (ll i = 0; i < n; i++) {
      for (ll j = 0; j < n; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  map<ll, ll> mp;
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      mp[dp[i][j]]++;
    }
  }
  for (ll k = 1; k < n; k++) {
    cout << mp[k] << endl;
  }
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF (INT32_MAX / 4)

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

  vector<vector<int>> m(N, vector<int>(N, INF));
  for (int i = 0; i < N; i++)
    m[i][i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        continue;
      m[i][j] = abs(i - j);
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      m[i][j] = min(m[i][j], min(m[i][X] + m[Y][j] + 1, m[i][Y] + m[X][j] + 1));
    }
  }
  vector<int> ans(N - 1);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (m[i][j] < 1)
        continue;
      ans[m[i][j] - 1]++;
    }
  }
  for (int i = 0; i < N - 1; i++) {
    cout << ans[i] << endl;
  }
}


Error: TLE

Fixed submission:

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

#define INF (INT32_MAX / 4)

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

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

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

  // 隣接関係を表すグラフ
  using Graph = vector<vector<int>>;
  Graph G(n);
  for (int i = 0; i < n - 1; i++) {
    G[i + 1].push_back(i);
    G[i].push_back(i + 1);
  }
  G[x - 1].push_back(y - 1);
  G[y - 1].push_back(x - 1);

  vector<vector<int>> distance_pair(n, vector<int>(n, -1));

  // 各点ごとにBFSをして各点から各点への距離を計算する
  for (int i = 0; i < n; i++) {
    // BFSを行うために必要な道具
    vector<int> dist(n, -1);
    queue<int> que;

    // 初期状態(iから辿った距離を計算するので、iを初期点とする)
    dist[i] = 0;
    que.push(i);

    // BFS
    while (!que.empty()) {
      int v = que.front();
      que.pop();

      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue; // 発見済みの頂点は探索しない

        // 新規発見した頂点nvに関しては距離情報を更新後キューに追加する
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }

    for (int v = 0; v < n; ++v) {
      distance_pair.at(i).at(v) = dist[v];
    }
  }

  map<int, int> answers_double;
  for (int k = 1; k < n; k++) {
    answers_double[k] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      answers_double[distance_pair.at(i).at(j)]++;
    }
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

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

  // 隣接関係を表すグラフ
  using Graph = vector<vector<int>>;
  Graph G(n);
  for (int i = 0; i < n - 1; i++) {
    G[i + 1].push_back(i);
    G[i].push_back(i + 1);
  }
  G[x - 1].push_back(y - 1);
  G[y - 1].push_back(x - 1);

  vector<vector<int>> distance_pair(n, vector<int>(n, -1));

  // 各点ごとにBFSをして各点から各点への距離を計算する
  for (int i = 0; i < n; i++) {
    // BFSを行うために必要な道具
    vector<int> dist(n, -1);
    queue<int> que;

    // 初期状態(iから辿った距離を計算するので、iを初期点とする)
    dist[i] = 0;
    que.push(i);

    // BFS
    while (!que.empty()) {
      int v = que.front();
      que.pop();

      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue; // 発見済みの頂点は探索しない

        // 新規発見した頂点nvに関しては距離情報を更新後キューに追加する
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }

    for (int v = 0; v < n; ++v) {
      distance_pair.at(i).at(v) = dist[v];
    }
  }

  vector<int> answers(n - 1, 0);
  for (int k = 1; k <= n - 1; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (distance_pair.at(i).at(j) == k)
          answers.at(k - 1)++;
      }
    }
    answers.at(k - 1) /= 2;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << answers.at(i) << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

using pil = pair<int, ll>;
void dijkstra(int s, vector<ll> &d, const vector<vector<ll>> &G) {
  queue<int> que;
  fill(All(d), INF);
  d[s] = 0;
  que.push(s);

  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (auto e : G[v]) {
      if (d[e] == INF) {
        d[e] = d[v] + 1;
        que.push(e);
      }
    }
  }
}

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<vector<ll>> G(N, vector<ll>());
  rep(i, N - 1) {
    G[i].pb(i + 1);
    G[i + 1].pb(i);
  }
  G[X].pb(Y);
  G[Y].pb(X);
  map<ll, int> mp;
  rep(i, N) {
    vector<ll> dist(N);
    dijkstra(i, dist, G);
    rep(j, N) mp[dist[j]]++;
  }
  for (int i = 1; i < N; i++) {
    cout << mp[i] / 2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<vector<ll>> dist(N, vector<ll>(N));
  rep(i, N) {
    rep(j, N) { dist[i][j] = LINF; }
  }
  rep(i, N - 1) {
    dist[i][i + 1] = 1;
    dist[i + 1][i] = 1;
  }
  dist[X][Y] = 1;
  dist[Y][X] = 1;

  rep(k, N) {
    rep(i, N) {
      rep(j, N) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); }
    }
  }
  map<ll, int> mp;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      mp[dist[i][j]]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << mp[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

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

  vector<int> ans(n + 1);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (i <= x && j <= y) {
        ans[min(j - i, x - i + 1 + y - j)] += 1;
      } else if (i <= x && j > y) {
        ans[x - i + j - y + 1] += 1;
      } else if (i >= x && j <= y) {
        ans[min(j - i, i - x + y - j + 1)] += 1;
      } else if (i >= x && j > y) {
        ans[min(j - i, i - x + j - y + 1)] += 1;
      }
    }
  }

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

  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

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

  vector<int> ans(n + 1);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (i <= x && j <= y) {
        int mn = n;
        mn = min(j - i, x - i + 1 + y - j);
        ans[mn] += 1;
      } else if (i <= x && j > y) {
        ans[x - i + j - y + 1] += 1;
      } else if (i >= x && j <= y) {
        ans[min(j - i, i - x + y - j + 1)] += 1;
      } else if (i >= x && j > y) {
        ans[min(j - i, i - x + j - y + 1)] += 1;
      }
    }
  }

  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;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

  vector<int> counter(n, 0);
  for (int start = 0; start < n; start++) {
    queue<int> q;
    q.push(start);
    vector<int> dist(n, 1e9);
    dist[start] = 1;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int to : adj[now]) {
        if (dist[to] != 1e9)
          continue;
        if (dist[to] > dist[now] + 1) {
          dist[to] = dist[now] + 1;
          q.push(to);
        }
      }
    }
    for (int i = start + 1; i < n; i++) {
      counter[dist[i] - 1]++;
    }
    // cout << "start: " << start << ", counter: ";
    // for (int i = 0; i < n; i++) {
    //     cout << counter[i] << " ";
    // }
    // cout << endl;
  }
  for (int i = 1; i < n; i++) {
    cout << counter[i] << endl;
  }
}

Error: 0

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;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<int> adj[1000];
  rep(i, n - 1) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);

  vector<int> counter(n, 0);
  for (int start = 0; start < n; start++) {
    queue<int> q;
    q.push(start);
    vector<int> dist(n, 1e9);
    dist[start] = 1;
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int to : adj[now]) {
        if (dist[to] != 1e9)
          continue;
        if (dist[to] > dist[now] + 1) {
          dist[to] = dist[now] + 1;
          q.push(to);
        }
      }
    }
    for (int i = start + 1; i < n; i++) {
      counter[dist[i] - 1]++;
    }
    // cout << "start: " << start << ", counter: ";
    // for (int i = 0; i < n; i++) {
    //     cout << counter[i] << " ";
    // }
    // cout << endl;
  }
  for (int i = 1; i < n; i++) {
    cout << counter[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int a[n][n + 1];
  int d[n] = {0};
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      a[i][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
      d[a[i][j]]++;
    }
  }
  for (int k = 1; k < n; k++) {
    cout << d[k] << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, x, y;
  int b = 0;
  cin >> n >> x >> y;
  int a[n][n + 1];
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      a[i][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
    }
  }
  for (int k = 1; k < n; k++) {
    for (int i = 1; i < n; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        if (a[i][j] == k)
          b++;
      }
    }
    cout << b << '\\n';
    b = 0;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d", &x)
#define scll(x) scanf("%lld", &x)
int main() {
  int n, x, y, tmp = 0;
  sc(n), sc(x), sc(y);
  x--, y--;
  vector<int> ans(n, 0);
  rep(i, 0, n - 1) {
    rep(j, i + 1, n) {
      if (j <= x)
        tmp = j - i;
      else if (i >= y)
        tmp = j - i;
      else if (i <= x) {
        if (j < y)
          tmp = min(j - i, x + y - i - j + 1);
        else
          tmp = x - y + j - i + 1;
      } else {
        if (j < y)
          tmp = min(j - i, i - x + y - j + 1);
        else
          tmp = min(j - i, i + j - x - y + 1);
      }
      ans[tmp] += 1;
    }
  }
  rep(i, 1, n) { cout << ans[i] << endl; }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d", &x)
#define scll(x) scanf("%lld", &x)
int main() {
  int n, x, y, tmp = 0;
  cin >> n >> x >> y;
  x--, y--;
  vector<int> ans(n, 0);
  rep(i, 0, n) {
    rep(j, 0, n) {
      if (j <= x)
        tmp = j - i;
      else if (i >= y)
        tmp = j - i;
      else if (i <= x) {
        if (j < y)
          tmp = min(j - i, x + y - i - j + 1);
        else
          tmp = x - y + j - i + 1;
      } else {
        if (j < y)
          tmp = min(j - i, i - x + y - j + 1);
        else
          tmp = min(j - i, i + j - x - y + 1);
      }
      ans[tmp] += 1;
    }
  }
  rep(i, 1, n) { cout << ans[i] << endl; }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define mod ((int)1e9 + 7)
using namespace std;
typedef pair<int, int> pi;
typedef long long int ll;

const int N = (int)2e3 + 5;

vector<int> v[N];
int dp[N][N];
void bfs(int source) {
  dp[source][source] = 0;
  queue<pair<int, int>> q;
  q.push({0, source});
  while (!q.empty()) {
    pair<int, int> x = q.front();
    q.pop();
    for (auto it : v[x.second]) {
      if (dp[source][it] == (-1)) {
        dp[source][it] = 1 + x.first;
        q.push({dp[source][it], it});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, x, y;
  cin >> n >> x >> y;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i < n; i++) {
    v[i].push_back(i + 1);
    v[i + 1].push_back(i);
  }
  v[x].push_back(y);
  v[y].push_back(x);
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  vector<int> ans(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (dp[i][j] > 0 && dp[i][j] < n) {
        ans[dp[i][j]]++;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << "\\n";
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod ((int)1e9 + 7)
using namespace std;
typedef pair<int, int> pi;
typedef long long int ll;

const int N = (int)2e3 + 5;

int dp[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = (i == j) ? 0 : mod;
    }
  }
  for (int i = 1; i < n; i++) {
    dp[i][i + 1] = dp[i + 1][i] = 1;
  }
  dp[x][y] = dp[y][x] = 1;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  vector<int> ans(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (dp[i][j] > 0 && dp[i][j] < n) {
        ans[dp[i][j]]++;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << "\\n";
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int n;

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

  VI ans(n, 0);
  int d;

  REP(i, n - 1) {
    FOR(j, i + 1, n - 1) {
      if (i <= x) {
        if (j <= x) {
          d = j - i;
        } else if (x <= j && j <= y) {
          d = min(j - i, x - i + 1 + y - j);
        } else if (y <= j) {
          d = x - i + j - y + 1;
        }
      } else if (x <= i && i <= y) {
        if (j <= y) {
          d = min(j - i, i - x + 1 + y - j);
        } else if (y <= j) {
          d = min(j - i, j - y + 1 + i - x);
        }
      } else {
        d = j - i;
      }
      ans[d]++;
      // cout << i << " " << j << " " << d << endl;
    }
  }

  FOR(k, 1, n - 1) { ANS(ans[k]); }

  return 0;
}


Error: TLE

Fixed submission:

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

const int INF = 100000000;

int n;
vector<vector<int>> d;

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() {
  cin >> n;
  int x, y;
  cin >> x >> y;
  x--;
  y--;

  d = vector<vector<int>>(n, vector<int>(n, INF));
  for (int i = 0; i < n; i++)
    d[i][i] = 0;

  REP(i, n - 1) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }

  d[x][y] = 1;
  d[y][x] = 1;

  warshall_floyd(n);

  VI ans(n, 0);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j && d[i][j] != INF)
        ans[d[i][j]]++;
    }
  }

  FOR(i, 1, n - 1) { ANS(ans[i] / 2); }

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

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define mod 1000000007
#define M 1000000
using namespace std;

vector<ll> adj[2002], final(2002, 0);

void answer() {
  ll n, m, ans1 = 0, k, x;
  cin >> n >> m >> k;
  for (int i = 0; i < n - 1; i++) {
    adj[i + 2].pb(i + 1);
    adj[i + 1].pb(i + 2);
  }
  adj[m].pb(k);
  adj[k].pb(m);

  for (int i = 1; i <= n; i++) {
    std::queue<int> q;
    std::vector<int> vis(2002, 0), dis(2002, 0);
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int j = 0; j < adj[v].size(); j++) {
        if (vis[adj[v][j]] == 0) {
          dis[adj[v][j]] = dis[v] + 1;
          q.push(adj[v][j]);
          vis[adj[v][j]] = 1;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      final[dis[i]]++;
    }
  }
  final[2] -= n;
  for (int i = 1; i < n; i++)
    cout << final[i] / 2 << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  // cin>>q; while(q--)
  answer();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define mod 1000000007
#define M 1000000
using namespace std;

vector<ll> adj[1002], final(1002, 0);

void answer() {
  ll n, m, ans1 = 0, k, x;
  cin >> n >> m >> k;
  for (int i = 0; i < n - 1; i++) {
    adj[i + 2].pb(i + 1);
    adj[i + 1].pb(i + 2);
  }
  adj[m].pb(k);
  adj[k].pb(m);

  for (int i = 1; i <= n; i++) {
    std::queue<int> q;
    std::vector<int> vis(1002, 0), dis(1002, 0);
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int j = 0; j < adj[v].size(); j++) {
        if (vis[adj[v][j]] == 0) {
          dis[adj[v][j]] = dis[v] + 1;
          q.push(adj[v][j]);
          vis[adj[v][j]] = 1;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      final[dis[i]]++;
    }
  }
  final[2] -= n;
  for (int i = 1; i < n; i++)
    cout << final[i] / 2 << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  // cin>>q; while(q--)
  answer();
  return 0;
}