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

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int g[2002][2002];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n, x, y;
  cin >> n >> x >> y;
  rep(i, n + 1) rep(j, n + 1) g[i][j] = 1e9 + 7;

  g[x][y] = 1;
  g[y][x] = 1;

  for (int i = 1; i <= n; i++) {
    g[i][i] = 0;
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  vector<int> ans(n + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      // 点(i,j)について考える
      // 何事もなければ距離は j-iだが、その間に辺があると距離はj-i-1になる
      int dis = j - i;
      chmin(dis, abs(i - x) + abs(j - y) + 1);
      ans[dis]++;
    }
  }
  for (int k = 1; k <= n - 1; k++) {
    cout << ans[k] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int g[2002][2002];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n, x, y;
  cin >> n >> x >> y;
  rep(i, n + 1) rep(j, n + 1) g[i][j] = 1e9 + 7;

  g[x][y] = 1;
  g[y][x] = 1;

  for (int i = 1; i <= n; i++) {
    g[i][i] = 0;
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        chmin(g[i][j], g[i][k] + g[k][j]);
      }

  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++) {
        if (g[i][j] == k)
          ans++;
      }
    }
    cout << ans << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

// file creato da gio il 2020-03-31 21:23:51.244903

#include <iostream>
#define FAST

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \\
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;
int arr[2000];
//[2000]
int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

  int N, X, Y;
  cin >> N >> X >> Y;
  X -= 1;
  Y -= 1;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int d = j - i;
      arr[min(d, abs(X - i) + abs(Y - j) + 1)]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << arr[i] << endl;
  }
}

Error: 0

Fixed submission:

// file creato da gio il 2020-03-31 21:23:51.244903

#include <iostream>
#define FAST

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target(                                                            \\
    "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;
int arr[2000];
//[2000]
int main() {
  // freopen("output","w",stdout);
  // freopen("input","r",stdin);
#ifdef FAST
  ios::sync_with_stdio(0);
  cin.tie(0);
#endif

  int N, X, Y;
  cin >> N >> X >> Y;
  X -= 1;
  Y -= 1;
  for (int i = 1; i < N; i++) {
    arr[i] = N - i;
  }
  for (int i = 0; i <= X; i++) {
    for (int j = Y; j < N; j++) {
      arr[j - i]--;
      arr[j - i - (Y - X) + 1]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << arr[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <fstream>
#include <iostream>
using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x = x - 1;
  y = y - 1;
  int dist_hist[n];
  int i, j, k;

  for (k = 0; k < n; k++)
    dist_hist[k] = 0;

  for (i = 0; i < n - 1; i++)
    for (j = i + 1; j < n; j++)
      dist_hist[min(j - i, abs(x - i) + 1 + abs(y - j))]++;

  for (k = 1; k < n; k++)
    cout << dist_hist[k] << "\\n";
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <fstream>
#include <iostream>
using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x = x - 1;
  y = y - 1;
  int dist_list[n][n];
  int i, j, k;

  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      dist_list[i][j] = -1;

  for (i = 0; i < n - 1; i++)
    for (j = i + 1; j < n; j++)
      dist_list[i][j] = min(j - i, abs(x - i) + 1 + abs(y - j));

  int cnt;
  for (k = 1; k < n; k++) {
    cnt = 0;
    for (i = 0; i < n - 1; i++)
      for (j = i + 1; j < n; j++)
        if (dist_list[i][j] == k)
          cnt++;
    cout << cnt << "\\n";
  }
}
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> a;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      int b = j - i;
      int c = abs(i - x) + abs(j - y) + 1;
      a.push_back(min(b, c));
    }
  }
  int d = a.size();
  sort(a.begin(), a.end());
  int de = 0;
  for (int k = 1; k < n; k++) {
    int ans = 0;
    for (int i = de; i < d; i++) {
      if (a[i] == k)
        ans++;
      else
        break;
      de++;
    }
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> a;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      int b = j - i;
      int c = abs(i - x) + abs(j - y) + 1;
      a.push_back(min(b, c));
    }
  }
  int d = a.size();

  for (int k = 1; k < n; k++) {
    int ans = 0;
    for (int i = 0; i < d; i++) {
      if (a[i] == k)
        ans++;
    }
    cout << ans << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
vector<vector<ll>> arr;

ll bfs(ll start, ll goal) {
  vector<ll> dist(2010, -1);
  queue<ll> que;
  que.push(start); // start
  dist[start] = 0;
  while (!que.empty()) {
    const ll current = que.front();
    que.pop();
    if (current == goal) {
      break;
    }
    for (const auto &next : arr[current]) {
      if (dist[next] == -1) {
        que.push(next);
        dist[next] = dist[current] + 1;
      }
    }
  }
  return dist[goal];
}

int main() {
  // init
  ll N, X, Y;
  cin >> N >> X >> Y;
  // 0-index;
  X--;
  Y--;

  // 距離を計算する
  map<ll, ll> dist;
  for (ll i = 0; i < N - 1; i++) {
    for (ll j = i + 1; j < N; j++) {
      const ll guchoku = j - i;
      const ll start_X = abs(X - i);
      const ll goal_Y = abs(Y - j);
      ll dis = min(guchoku, (start_X + goal_Y + 1));
      dist[dis]++;
    }
  }

  for (ll i = 1; i < N; i++) {
    // 順番に出力。
    try {
      ll count = dist.at(i);
      cout << count << endl;
    } catch (...) {
      cout << 0 << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
vector<vector<ll>> arr;

ll bfs(ll start, ll goal) {
  vector<ll> dist(2010, -1);
  queue<ll> que;
  que.push(start); // start
  dist[start] = 0;
  while (!que.empty()) {
    const ll current = que.front();
    que.pop();
    if (current == goal) {
      break;
    }
    for (const auto &next : arr[current]) {
      if (dist[next] == -1) {
        que.push(next);
        dist[next] = dist[current] + 1;
      }
    }
  }
  return dist[goal];
}

int main() {
  // init
  ll N, X, Y;
  cin >> N >> X >> Y;
  // 0-index;
  X--;
  Y--;

  // 隣接行列
  for (ll i = 0; i < N; i++) {
    if (i == 0) {
      arr.push_back({i + 1});
    } else if (i == N - 1) {
      arr.push_back({i - 1});
    } else {
      arr.push_back({i - 1, i + 1});
    }
  }
  arr[X].push_back(Y);
  arr[Y].push_back(X);

  // 距離を計算する
  map<ll, ll> dist;

  // 基本はj-iが距離なのだが、XYの影響で短くなりうる。無効グラフなので戻る作戦もありうる。全通りなのか

  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j < N; j++) {
      if (j == i + 1 || (j == X && i == Y) || (j == Y && i == X)) {
        dist[1]++;
        continue;
      }
      // 隣接行列で探索する
      ll dis = bfs(i, j);
      dist[dis]++;
    }
  }
  for (ll i = 1; i < N; i++) {
    // 順番に出力。
    try {
      ll count = dist.at(i);
      cout << count << endl;
    } catch (...) {
      cout << 0 << endl;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
int fg(int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
signed main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  int x = X - 1;
  int y = Y - 1;
  vector<int> vec(N - 1);
  rep(i, N - 1) { vec[i] = 0; }
  for (int j = 0; j < N - 1; j++) {
    for (int k = j + 1; k < N; k++) {
      int a = min(k - j, abs(j - x) + abs(k - y) + 1);
      vec[a - 1]++;
    }
  }
  for (int l = 0; l < N - 1; l++) {
    cout << vec[l] << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
int fg(int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
signed main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> vec(N - 1);
  rep(i, N - 1) { vec[i] = 0; }
  for (int j = 0; j < N - 2; j++) {
    for (int k = j + 1; k < N - 1; k++) {
      int a = min(k - j, abs(j - X) + abs(k - Y));
      vec[a - 1]++;
    }
  }
  for (int l = 0; l < N - 1; l++) {
    cout << vec[l] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define ll long long int
vector<int> adj[2007];
ll dp[2007][2007];
int vis[2007];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);
  unordered_map<ll, ll> mp;
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    vector<ll> dist(n + 1);
    queue<int> q;
    q.push(i);
    dist[i] = 0;
    vis[i] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto v : adj[u]) {
        if (!vis[v]) {
          dist[v] = dist[u] + 1;
          vis[v] = 1;
          q.push(v);
        }
      }
    }
    for (int j = 1; j <= n; j++)
      mp[dist[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 ll long long int

ll dp[2007][2007];
int main() {
  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] = INT_MAX;
  for (int i = 1; i < n; i++) {
    dp[i][i + 1] = 1;
    dp[i + 1][i] = 1;
    dp[i][i] = 0;
  }
  dp[n][n] = 0;
  dp[x][y] = 1;
  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]);
      }
    }
  }
  unordered_map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      mp[dp[i][j]]++;
    }
    // cout << endl;
  }
  for (int i = 1; i < n; i++) {
    cout << mp[i] / 2 << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 2e3 + 3;
const int INF = 0x3f3f3f3f;
int e[maxn][maxn];
int n, x, y;
int ans[maxn];
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    // also
    // x=(x<<3)+(x<<1)+(c^48)
    c = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  x = read();
  y = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      e[i][j] = INF;
  for (int i = 1; i <= n - 1; i++) {
    e[i][i + 1] = 1;
    e[i + 1][i] = 1;
  }
  e[x][y] = 1;
  e[y][x] = 1;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      if (k != i) {
        int t = (k < i) ? e[i][k] : e[k][i];
        if (t == INF)
          continue;
        for (int j = 1; j <= min(k, i); j++) {
          e[i][j] = min(e[i][j], t + e[k][j]);
        }
        for (int j = k + 1; j <= i; j++) {
          e[i][j] = min(e[i][j], t + e[j][k]);
        }
      }
    }
  }
  for (int j = 1; j <= n - 1; j++)
    for (int i = j + 1; i <= n; i++) {
      if (e[i][j] != INF)
        ans[e[i][j]]++;
    }

  for (int i = 1; i <= n - 1; i++) {
    printf("%d\\n", ans[i]);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 2e3 + 3;
int e[maxn][maxn];
int n, x, y;
int ans[maxn];
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    // also
    // x=(x<<3)+(x<<1)+(c^48)
    c = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  x = read();
  y = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      e[i][j] = 9999;
  for (int i = 1; i <= n - 1; i++) {
    e[i][i + 1] = 1;
    e[i + 1][i] = 1;
  }
  e[x][y] = 1;
  e[y][x] = 1;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      int t = e[i][k];
      for (int j = 1; j <= i; j++) {
        e[i][j] = min(e[i][j], t + e[k][j]);
        e[j][i] = e[i][j];
      }
    }
  }
  for (int i = 1; i <= n - 1; i++)
    for (int j = i + 1; j <= n; j++) {
      if (e[i][j] != 9999)
        ans[e[i][j]]++;
    }

  for (int i = 1; i <= n - 1; i++) {
    printf("%d\\n", ans[i]);
  }

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

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
using namespace std;

int d[2001][2001] = {3000};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, X, Y;
  cin >> N >> X >> Y;

  int counts[N] = {0};
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int dist = min(min(abs(j - i), abs(X - 1 - i) + 1 + abs(j - Y + 1)),
                     abs(Y - 1 - i) + 1 + abs(j - X + 1));
      counts[dist]++;
    }
  }

  for (int i = 1; i < N; i++) {
    cout << counts[i] << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
using namespace std;

int d[2001][2001] = {3000};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, X, Y;
  cin >> N >> X >> Y;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        d[i][j] = 0;
      if (i == j - 1) {
        d[i][j] = 1;
        d[j][i] = 1;
      }
      if (i == X - 1 && j == Y - 1) {
        d[i][j] = 1;
        d[j][i] = 1;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int dist = min(min(abs(j - i), abs(X - 1 - i) + 1 + abs(j - Y + 1)),
                     abs(Y - 1 - i) + 1 + abs(j - X + 1));
      d[i][j] = dist;
      d[j][i] = dist;
    }
  }

  for (int i = 1; i < N; i++) {
    int count = 0;
    for (int j = 0; j < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (d[j][k] == i) {
          count++;
        }
      }
    }
    cout << count << endl;
  }

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

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  const int INF = 1e8;
  vector<vector<int>> v(N + 1);
  for (int i = 1; i < N; i++) {
    v.at(i).push_back(i + 1);
    v.at(i + 1).push_back(i);
  }
  v.at(X).push_back(Y);
  v.at(Y).push_back(X);

  vector<int> ans(N, 0);
  vector<vector<int>> dist(N + 1, vector<int>(N + 1, INF));
  for (int i = 1; i <= N; i++) {
    queue<int> que;
    que.push(i);
    dist.at(i).at(i) = 0;
    while (!que.empty()) {
      int a = que.front();
      que.pop();
      for (auto b : v.at(a)) {
        if (dist.at(i).at(b) == INF) {
          que.push(b);
          dist.at(i).at(b) = dist.at(i).at(a) + 1;
          ans.at(dist.at(i).at(b))++;
        }
      }
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans.at(i) / 2 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  const int INF = 1e8;
  vector<vector<int>> v(N + 1);
  for (int i = 1; i < N; i++) {
    v.at(i).push_back(i + 1);
    v.at(i + 1).push_back(i);
  }
  v.at(X).push_back(Y);
  v.at(Y).push_back(X);

  vector<int> ans(N, 0);
  for (int i = 1; i <= N; i++) {
    queue<int> que;
    vector<vector<int>> dist(N + 1, vector<int>(N + 1, INF));
    que.push(i);
    dist.at(i).at(i) = 0;
    while (!que.empty()) {
      int a = que.front();
      que.pop();
      for (auto b : v.at(a)) {
        if (dist.at(i).at(b) == INF) {
          que.push(b);
          dist.at(i).at(b) = dist.at(i).at(a) + 1;
          ans.at(dist.at(i).at(b))++;
        }
      }
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans.at(i) / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int N, X, Y;
int ans[2005] = {0};
int d[2005][2005];
vector<int> dist;

int main() {
  cin >> N >> X >> Y;
  Graph G(N);

  rep(i, N - 1) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X - 1].push_back(Y - 1);
  G[Y - 1].push_back(X - 1);

  rep(i, N) rep(j, N) d[N][N] = 1001001001;

  rep(i, N) {
    dist.assign(N, -1);
    queue<int> q;
    dist[i] = 0;
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();

      for (auto nv : G[v]) {
        if (dist[nv] != -1)
          continue;

        dist[nv] = dist[v] + 1;
        q.push(nv);
      }
    }

    rep(j, N) {
      if (j == i)
        continue;
      d[min(i, j)][max(i, j)] = dist[j];
    }
  }
  rep(i, N) rep(j, N) {
    if (i >= j)
      continue;
    if (d[i][j] == 1001001001)
      continue;
    ans[d[i][j]]++;
  }
  for (int i = 1; i < N; i++)
    cout << ans[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  Graph G(N);
  rep(i, N - 1) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X - 1].push_back(Y - 1);
  G[Y - 1].push_back(X - 1);

  vector<int> ans(N + 5, 0);
  int d[N][N];
  rep(i, N) rep(j, N) d[N][N] = 1001001001;

  rep(i, N) {
    int dist[N + 5];
    rep(i, N) dist[i] = -1;
    queue<int> q;
    dist[i] = 0;
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();

      for (auto nv : G[v]) {
        if (dist[nv] != -1)
          continue;

        dist[nv] = dist[v] + 1;
        q.push(nv);
      }
    }

    rep(j, N) {
      if (j == i)
        continue;
      d[min(i, j)][max(i, j)] = dist[j];
    }
  }
  rep(i, N) rep(j, N) {
    if (i >= j)
      continue;
    if (d[i][j] == 1001001001)
      continue;
    ans[d[i][j]]++;
  }
  for (int i = 1; i < N; i++)
    cout << ans[i] << endl;
  return 0;
}