alexjercan/bugnet huggingface dataset:
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int n, x, y;

  cin >> n >> x >> y;
  x--;
  y--;

  vector<int> distance(n, 0);

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

    for (int j = i + 1; j < n; ++j) {

      int d = min(
          j - i, min(abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j)));

      // cout << i << ":" << j << " = " << d << endl;

      distance[d]++;
    }
  }

  for (int i = 1; i < n; ++i)
    cout << distance[i] << endl;

  return 0;
}

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


Fixed submission:

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

int main() {

  int n, x, y;

  vector<int> distance(n, 0);

  cin >> n >> x >> y;
  x--;
  y--;

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

    for (int j = i + 1; j < n; ++j) {

      int d = min(
          j - i, min(abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j)));

      // cout << i << ":" << j << " = " << d << endl;

      if (d < n)
        distance[d]++;
    }
  }

  for (int i = 1; i < n; ++i)
    cout << distance[i] << endl;

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

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

int main() {
  int x, n, y;
  string s;
  cin >> n >> x >> y;
  //    map<int, int> cnt;
  int cnt[2000] = {};
  for (int i = 1; i < n; i++) {
    int dis = 0;
    for (int j = i + 1; j <= n; j++) {
      dis = min(j - i, abs(x - i) + 1 + abs(y - j));
      cnt[dis]++;
      // cout << i << " " << dis << " " << j << endl;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int x, n, y;
  string s;
  cin >> n >> x >> y;
  //    map<int, int> cnt;
  int cnt[1000] = {};
  for (int i = 1; i < n; i++) {
    int dis = 0;
    for (int j = i + 1; j <= n; j++) {
      dis = min(j - i, abs(x - i) + 1 + abs(y - j));
      cnt[dis]++;
      // cout << i << " " << dis << " " << j << endl;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << cnt[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <vector>

int main() {
  int N, X, Y;
  scanf("%d %d %d", &N, &X, &Y);
  std::vector<int> count;
  for (int i = 0; i < N; i++) {
    count.push_back(0);
  }
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j < N + 1; j++) {
      count[std::min({abs(i - j), abs(X - i) + 1 + abs(j - Y),
                      abs(Y - i) + 1 + abs(j - X)})] += 1;
    }
  }
  for (int i = 1; i < N; i++) {
    printf("%d\\n", count[i]);
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y;
  std::vector<int> lis;
  scanf("%d %d %d", &N, &X, &Y);
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j < N + 1; j++) {
      lis.push_back(std::min({abs(i - j), abs(X - i) + 1 + abs(j - Y),
                              abs(Y - i) + 1 + abs(j - X)}));
    }
  }
  for (int i = 1; i < N; i++) {
    std::cout << std::count(lis.begin(), lis.end(), i) << std::endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<int> ans(n);
  rep(sv, n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF)
        return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (v - 1 >= 0)
        push(v - 1, d + 1);
      if (v + 1 < n)
        push(v + 1, d + 1);
      if (v == x)
        push(y, d + 1);
      if (v == y)
        push(x, d + 1);
    }
    rep(i, n) ans[dist[i]]++;
  }
  rep(i, n) ans[i] /= 2;
  for (int i = 1; i <= n - 1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

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 k = 0; k < n; k++) {
    mat[k][k] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j + 1 || j == i + 1)
          mat[i][j] = 1;
        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 <bits/stdc++.h>
#define MAX 2001
using namespace std;
int K[MAX] = {};
int N, X, Y, ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> X >> Y;
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      int k = min(min(abs(j - i), abs(X - i) + 1 + abs(j - Y)),
                  abs(Y - i) + 1 + abs(j - X));
      K[k]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << K[i] << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define MAX 2001
using namespace std;
int graph[MAX][MAX] = {};
int N, X, Y, ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> X >> Y;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++) {
      graph[i][j] = min(min(abs(j - i), abs(X - i) + 1 + abs(j - Y)),
                        abs(Y - i) + 1 + abs(j - X));
    }
  }
  for (int k = 1; k < N; k++) {
    int ans = 0;
    for (int i = 1; i <= N; i++) {
      for (int j = i; j <= N; j++) {
        if (graph[i][j] == k)
          ans++;
      }
    }
    cout << ans << "\\n";
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define ll long long

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

  vector<int> ans(n, 0);
  for (int start = 0; start < n - 1; ++start) {
    vector<int> dist(n, 1000000000);
    dist[start] = 0;
    queue<int> next;
    next.push(start);

    while (next.size() > 0) {
      int node = next.front();

      if (node - 1 > -1 && dist[node - 1] > dist[node] + 1) {
        next.push(node - 1);
        dist[node - 1] = dist[node] + 1;
      }

      if (node + 1 < n && dist[node + 1] > dist[node] + 1) {
        next.push(node + 1);
        dist[node + 1] = dist[node] + 1;
      }

      if (node == x && dist[y] > dist[x] + 1) {
        next.push(y);
        dist[y] = dist[x] + 1;
      }

      if (node == y && dist[x] > dist[y] + 1) {
        next.push(x);
        dist[x] = dist[y] + 1;
      }

      next.pop();
    }

    for (int i = start; i < dist.size(); ++i) {
      ans[dist[i]] += 1;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

#define ll long long

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

  vector<vector<int>> dist(n, vector<int>(n, 100000000));

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

  dist[x - 1][y - 1] = 1;
  dist[y - 1][x - 1] = 1;

  for (int dist_num = 2; dist_num < n; ++dist_num) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (dist[i][j] == dist_num - 1) {
          for (int k = 0; k < n; ++k) {
            if (i != k) {
              dist[i][k] = min(dist[i][k], dist[j][k] + dist[i][j]);
            }
          }
        }
      }
    }
  }

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

    cout << ans << endl;
  }

  // cout << endl;

  // for(int i = 0;i < n;i++){
  //     for(int j = 0;j < n;++j){
  //         cout << dist[i][j] << " ";
  //     }
  //     cout << endl;
  // }

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

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vvll A(N, vll(N, INF));
  vll count(N, 0);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      A.at(i).at(j) = abs(j - i);
      chmin(A.at(i).at(j), abs(i - X) + 1LL + abs(j - Y));
      chmin(A.at(i).at(j), abs(i - Y) + 1LL + abs(j - X));
      count.at(A.at(i).at(j))++;
    }
  }

  for (int i = 1; i <= N - 1; i++) {
    cout << count.at(i) / 2 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vvll dp(N, vll(N, INF));
  for (int i = 0; i < N - 1; i++) {
    dp.at(i).at(i) = 0;
    dp.at(i).at(i + 1) = 1;
    dp.at(i + 1).at(i) = 1;
  }
  dp.at(N - 1).at(N - 1) = 0;
  dp.at(X).at(Y) = 1;
  dp.at(Y).at(X) = 1;

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        chmin(dp.at(i).at(j), dp.at(i).at(k) + dp.at(k).at(j));
      }
    }
  }
  vll count(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      count.at(dp.at(i).at(j))++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << count.at(i) / 2 << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define MAX_V 2048
#define INF 1e9

int n, x, y;

vector<int> get_neighbors(int i) {
  vector<int> nb;
  if (i > 0) {
    nb.push_back(i - 1);
  }
  if (i < n - 1) {
    nb.push_back(i + 1);
  }
  if (i == x) {
    nb.push_back(y);
  }
  if (i == y) {
    nb.push_back(x);
  }
  return nb;
}

int main() {
  cin >> n >> x >> y;
  --x;
  --y;
  vector<int> cnt(n, 0);
  for (int i = 0; i < n; ++i) {
    vector<int> d(n, INF);
    d[i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int t = q.front();
      q.pop();
      for (int nb : get_neighbors(t)) {
        if (d[nb] != INF)
          continue;
        d[nb] = min(d[nb], d[t] + 1);
        q.push(nb);
      }
    }
    for (int x : d)
      ++cnt[x];
  }
  for (int k = 1; k < n; ++k) {
    cout << cnt[k] / 2 << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define MAX_V 2048
#define INF 100000000

int d[MAX_V][MAX_V];
int V;
int cnt[MAX_V];

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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  V = n;
  for (int i = 0; i < V; ++i) {
    for (int j = 0; j < V; ++j) {
      if (i != j)
        d[i][j] = INF;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }
  d[x][y] = 1;
  d[y][x] = 1;
  warshall_floyd();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      if (d[i][j] > 0 && d[i][j] != INF) {
        ++cnt[d[i][j]];
      }
    }
  }
  for (int k = 1; k < n; ++k) {
    cout << cnt[k] << "\\n";
  }
}
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(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> ans(n);
  rep(sv, n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF)
        return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (v - 1 >= 0)
        push(v - 1, d + 1);
      if (v + 1 < n)
        push(v + 1, d + 1);
      if (v == x)
        push(y, d + 1);
      if (v == y)
        push(x, d + 1);
    }
    rep(i, n) ans[dist[i]]++;
  }
  rep(i, n) ans[i] /= 2;
  for (int i = 1; i <= n - 1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> ans(n);
  rep(sv, n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF)
        return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (v - 1 >= 0)
        push(v - 1, d + 1);
      if (v + 1 < 0)
        push(v + 1, d + 1);
      if (v == x)
        push(y, d + 1);
      if (v == y)
        push(x, d + 1);
    }
    rep(i, n) ans[dist[i]]++;
  }
  rep(i, n) ans[i] /= 2;
  for (int i = 1; i <= n - 1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

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

  Graph dist(n, vector<int>(n, 1002003004));
  vector<int> ans(n - 1, 0);

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

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

  rep(i, n - 1) cout << ans[i] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

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

  Graph dist(n, vector<int>(n, 1002003004));

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

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

  rep(k, n - 1) {
    int tmp = k + 1;
    int ans = 0;

    for (int i = 0; i <= n - 2; i++) {
      for (int j = i + 1; j <= n - 1; j++) {
        if (dist[i][j] == tmp)
          ans++;
      }
    }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  int n, x, y, i, j;
  cin >> n >> x >> y;
  x--;
  y--;
  int dist[n][n];
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      dist[i][j] = min(abs(i - j), min(abs(i - x) + 1 + abs(y - j),
                                       abs(i - y) + 1 + abs(x - j)));
  }
  int cnt[n];
  for (i = 0; i < n; i++)
    cnt[i] = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      cnt[dist[i][j]]++;
  }
  for (i = 1; i < n; i++)
    cout << cnt[i] / 2 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
// floyd warshall
int main() {
  int n, x, y, i, j, k;
  cin >> n >> x >> y;
  x--;
  y--;
  int arr[n][n];
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      arr[i][j] = INT_MAX / 2;
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (i - j == 1)
        arr[i][j] = arr[j][i] = 1;
      if (i == j)
        arr[i][j] = 0;
    }
  }
  arr[x][y] = arr[y][x] = 1;
  for (k = 0; k < n; k++) {
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        arr[i][j] = min(arr[i][j], arr[i][k] + arr[k][j]);
      }
    }
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<vector<int>> g(n);
  rep(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);
  vector<vector<ll>> len(n, vector<ll>(n, INF));
  rep(i, n) {
    queue<P> que;
    que.push(P(i, 0));
    vector<bool> used(n, false);
    while (1) {
      if (que.empty()) {
        break;
      }
      P k = que.front();
      que.pop();
      ll num = k.first;
      ll cost = k.second;
      used[num] = true;
      len[i][num] = min(len[i][num], cost);
      len[num][i] = min(len[num][i], cost);
      int t = g[num].size();
      rep(j, t) {
        if (!used[g[num][j]]) {
          que.push(P(g[num][j], cost + 1));
        }
      }
    }
  }
  vector<int> ans(n);
  rep(i, n) {
    rep(j, n) { ans[len[i][j]]++; }
  }
  rep(i, n) { ans[i] /= 2; }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<vector<ll>> g(n, vector<ll>(n, INF));
  rep(i, n) { g[i][i] = 0; }
  rep(i, n - 1) {
    g[i][i + 1] = 1;
    g[i + 1][i] = 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);
  rep(i, n) {
    rep(j, n) { ans[g[i][j]]++; }
  }
  rep(i, n) { ans[i] /= 2; }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

long long p[10004];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  long long n, x, y, k;
  cin >> n >> x >> y;
  for (long long i = 1; i < n; ++i) {
    for (long long j = i + 1; j <= n; ++j) {
      k = min(j - i, abs(x - i) + 1 + abs(y - j));
      ++p[k];
    }
  }
  for (long long i = 1; i < n; ++i)
    cout << p[i] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long p[10004];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  long long n, x, y, k;
  cin >> n >> x >> y;
  for (long long i = 1; i < n; ++i) {
    for (long long j = 2; j <= n; ++j) {
      k = min(j - i, abs(x - i) + 1 + abs(y - j));
      ++p[k];
    }
  }
  for (long long i = 1; i < n; ++i)
    cout << p[i] << endl;

  return 0;
}