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

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

int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  int d[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = 1e6;
    }
  }
  for (int i = 0; i < n; i++) {
    d[i][i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }
  d[x - 1][y - 1] = 1;
  d[y - 1][x - 1] = 1;
  int count[n];
  for (int i = 0; i < n; i++)
    count[i] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = min({abs(j - i), abs(x - 1 - i) + abs(y - 1 - j) + 1,
                     abs(y - 1 - i) + abs(x - 1 - j) + 1});
      count[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    count[i] = count[i] / 2;
    printf("%d\\n", count[i]);
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  int d[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = 1e6;
    }
  }
  for (int i = 0; i < n; i++) {
    d[i][i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }
  d[x - 1][y - 1] = 1;
  d[y - 1][x - 1] = 1;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  for (int i = 1; i < n; i++) {
    int count = 0;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (d[j][k] == i)
          count++;
      }
    }
    count = count / 2;
    printf("%d\\n", count);
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

void bfs(const vvi &g, vi &ds, int i) {
  int n = g.size();

  vector<bool> seen(n, false);
  queue<int> queue;
  queue.push(i);
  ds[i] = 0;
  seen[i] = true;

  while (!queue.empty()) {
    int v = queue.front();
    queue.pop();

    for (auto itr = g[v].begin(); itr != g[v].end(); ++itr) {
      if (!seen[*itr]) {
        queue.push(*itr);
        ds[*itr] = ds[v] + 1;
        seen[*itr] = true;
      }
    }
  }

  rep(i, 0, n) {
    if (!seen[i]) {
      ds[i] = -1;
    }
  }
}

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

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

  vvi G(n);
  rep(i, 0, 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);

  vvi dists(n, vi(n));
  rep(i, 0, n) { bfs(G, dists[i], i); }

  vi ans(n, 0);
  rep(i, 0, n) {
    rep(j, i + 1, n) { ++ans[dists[i][j]]; }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

void warshall_floyd(vvi &G) {
  int v = G.size();
  rep(i, 0, v) { G[i][i] = 0; }
  rep(k, 0, v) {
    rep(i, 0, v) {
      if (G[i][k] == INT_MAX) {
        continue;
      }
      rep(j, 0, v) {
        if (G[k][j] == INT_MAX) {
          continue;
        }
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
}

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

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

  vvi G(n, vi(n, INT_MAX));
  rep(i, 0, n - 1) {
    G[i][i + 1] = 1;
    G[i + 1][i] = 1;
  }
  G[x - 1][y - 1] = 1;
  G[y - 1][x - 1] = 1;

  warshall_floyd(G);

  vi ans(n, 0);
  rep(i, 0, n) {
    rep(j, i + 1, n) { ++ans[G[i][j]]; }
  }
  rep(i, 1, ans.size()) { cout << ans[i] << endl; }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

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

  queue<int> q1;

  // 1行目は、頂点1を始点とする場合
  // 1,2は、1から2までいくときの最短距離、1.3は、1から3までいくときの最短距離
  vector<vector<int>> len(N + 1, vector<int>(N + 1, -1));

  vector<int> ans(N + 1, 0);

  // i行目について考える（頂点iを始点とする場合について考える）
  for (int i = 1; i <= N - 1; i++) {
    len[i][i] = 0;

    q1.push(i);

    while (!q1.empty()) {
      int temp = q1.front();
      q1.pop();

      if (temp + 1 <= N) {
        if (len[i][temp + 1] == -1) {
          len[i][temp + 1] = len[i][temp] + 1;
          q1.push(temp + 1);
        }
      }

      if (temp - 1 >= 1) {
        if (len[i][temp - 1] == -1) {
          len[i][temp - 1] = len[i][temp] + 1;
          q1.push(temp - 1);
        }
      }

      // 取り出した頂点が、Xかどうか確認
      if (temp == X) {
        if (len[i][Y] == -1) {
          len[i][Y] = len[i][temp] + 1;
          q1.push(Y);
        }
      }
    }
  }

  // ここまでで表はできている
  int temp;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++) {
      temp = len[i][j];
      // cout << i << "--" << j << "--" << temp << "--" << endl;
      if (temp != -1) {
        ans[temp]++;
      }
    }
  }

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

  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

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

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

  queue<int> q1;

  // 1行目は、頂点1を始点とする場合
  // 1,2は、1から2までいくときの最短距離、1.3は、1から3までいくときの最短距離
  vector<vector<int>> len(N + 1, vector<int>(N + 1, -1));

  vector<int> ans(N + 1, 0);

  // i行目について考える（頂点iを始点とする場合について考える）
  for (int i = 1; i <= N - 1; i++) {
    len[i][i] = 0;

    q1.push(i);

    while (!q1.empty()) {
      int temp = q1.front();
      q1.pop();

      if (temp + 1 <= N) {
        if (len[i][temp + 1] == -1) {
          len[i][temp + 1] = len[i][temp] + 1;
          q1.push(temp + 1);
        }
      }

      if (temp - 1 >= 1) {
        if (len[i][temp - 1] == -1) {
          len[i][temp - 1] = len[i][temp] + 1;
          q1.push(temp - 1);
        }
      }

      // 取り出した頂点が、Xかどうか確認
      if (temp == X) {
        if (len[i][Y] == -1) {
          len[i][Y] = len[i][temp] + 1;
          q1.push(Y);
        }
      }
    }
  }

  // ここまでで表はできている
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++) {
      int temp = len[i][j];
      ans[temp]++;
    }
  }

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

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


#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
using namespace std;
int cnt[2005][2005];
int ans[2005];
int vis[2005];
struct node {
  int p, val;
  node() {}
  node(int p, int val) : p(p), val(val) {}
  // bool operator<(const node &b)
  // {
  //     return this->val > b.val;
  // }
  friend bool operator<(node a, node b) { return a.val > b.val; }
};
int s, n, x, y;
void bfs() {
  priority_queue<node> q;
  q.push(node(s, 0));
  memset(vis, 0, sizeof(vis));
  while (!q.empty()) {
    node now = q.top();
    q.pop();
    if (vis[now.p])
      continue;
    vis[now.p] = 1;
    ans[now.val]++;
    if (now.p - 1 >= 1)
      q.push(node(now.p - 1, now.val + 1));
    if (now.p + 1 <= n)
      q.push(node(now.p + 1, now.val + 1));
    if (now.p == x)
      q.push(node(y, now.val + 1));
    if (now.p == y)
      q.push(node(x, now.val + 1));
  }
}
int main() {

  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++) {
    s = i;
    bfs();
  }
  for (int i = 1; i <= n - 1; i++)
    cout << ans[i] / 2 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;
const int maxn = 2e3 + 5;

int ans[maxn] = {0};
int main() {
  int n, x, y;
  cin >> n >> x >> y;

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

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

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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pii pair<int, pi>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 2001

int n, x, y;
int ans[MAXN];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> x >> y;

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

  y--;
  x--;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int neww = abs((min(x, y) - i)) + abs((j - max(x, y))) + 1;

      if (neww < j - i) {
        ans[j - i]--;
        ans[neww]++;
      }
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pii pair<int, pi>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 2001
#define INF 999999

int n, x, y;
int dist[MAXN][MAXN];
int ans[MAXN];

void floyd_warshall() {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}
void initialize() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = INF;
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> x >> y;

  initialize();
  x--;
  y--;
  dist[x][y] = min(dist[x][y], 1);
  dist[y][x] = min(dist[y][x], 1);

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

  floyd_warshall();

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

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

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

#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdint.h>
#include <vector>
using namespace std;

#define int long long
#define INF 1001001001
int ans[2200];
int dis[2200][2200];
vector<int> v[2200];

void bfs(int start) {

  queue<int> q;

  q.push(start);

  dis[start][start] = 1;

  while (!q.empty()) {

    int u = q.front();
    q.pop();
    for (int v : v[u]) {

      if (dis[v][start] == 0) {

        dis[v][start] = dis[u][start] + 1;
        q.push(v);
      }
    }
  }
}

int32_t main() {

  int N, X, Y;

  cin >> N >> X >> Y;

  X--;
  Y--;

  for (int i = 0; i < N - 1; 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 = 0; i < N; i++)
    bfs(i);

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

      ans[dis[j][i] - 1]++;
    }
  }

  for (int i = 1; i < N; i++) {

    cout << ans[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdint.h>
#include <vector>
using namespace std;

#define int long long
#define INF 1001001001
int ans[2200];
int dis[2200][2200];
vector<int> v[2200];

void bfs(int start) {

  queue<int> q;

  q.push(start);

  dis[start][start] = 1;

  while (!q.empty()) {

    int u = q.front();

    for (int v : v[u]) {

      if (dis[v][start] == 0) {

        dis[v][start] = dis[u][start] + 1;
        q.push(v);
      }
    }
  }
}

int32_t main() {

  int N, X, Y;

  cin >> N >> X >> Y;

  X--;
  Y--;

  for (int i = 0; i < N - 1; 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 = 0; i < N; i++)
    bfs(i);

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

      ans[dis[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, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

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

  vector<int> ans(N);

  rep(i, 0, N) {
    int k = 0;
    rep(j, i, N) {
      if (i == j)
        k = 0;
      else
        k = min(j - i, abs(i - X + 1) + abs(j - Y + 1) + 1);
      ans[k]++;
    }
  }
  rep(i, 1, N) cout << ans[i] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

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

  vector<vector<int>> dp(N, vector<int>(N, 9999999));

  rep(i, 0, N) {
    rep(j, i, N) {
      if (i == j)
        dp[i][j] = 0;
      else if (i == X - 1 && j == Y - 1)
        dp[i][j] = 1;
      else
        dp[i][j] = min(j - i, abs(i - X + 1) + abs(j - Y + 1) + 1);
    }
  }

  rep(k, 1, N) {
    int ans = 0;
    rep(i, 0, N) ans += count(all(dp[i]), k);
    cout << ans << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vi> g(n, vi(n, INF));
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      g[i][j] = j - i;
      g[j][i] = j - i;
    }
  }
  g[x - 1][y - 1] = 1;
  g[y - 1][x - 1] = 1;

  vi kv;
  kv.push_back(x - 1);
  kv.push_back(y - 1);
  rep(_k, 2) {
    int k = kv[_k];
    rep(i, n) {
      rep(j, n) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); }
    }
  }
  vi hist(n);
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      hist[g[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << hist[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vi> g(n, vi(n, INF));
  rep(i, n - 1) {
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  g[x - 1][y - 1] = 1;
  g[y - 1][x - 1] = 1;

  rep(k, n) {
    rep(i, n) {
      rep(j, n) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); }
    }
  }
  vi hist(n);
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      hist[g[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << hist[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;

int dist(int i, int j, int X, int Y) {

  int Norm = abs(i - j);
  int a = abs(i - X);
  int b = abs(j - Y);
  int Cust = a + 1 + b;

  return MIN(Norm, Cust);
}

int main() {

  int N;
  cin >> N;
  int X;
  cin >> X;
  int Y;
  cin >> Y;

  int Sum = 0;

  vector<int> A(N - 1, 0);

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

  for (int k = 0; k < N - 1; k++) {
    cout << A[k] << "\\n";
  }
}

Error: TLE

Fixed submission:

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

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;

int dist(int i, int j, int X, int Y) {

  int Norm = abs(i - j);
  int a = abs(i - X);
  int b = abs(j - Y);
  int Cust = a + 1 + b;

  return MIN(Norm, Cust);
}

int main() {

  int N;
  cin >> N;
  int X;
  cin >> X;
  int Y;
  cin >> Y;

  int Sum = 0;

  for (int k = 1; k < N; k++) {
    Sum = 0;
    for (int i = 1; i <= N; i++) {
      for (int j = i + 1; j <= N; j++) {
        if (dist(i, j, X, Y) == k) {
          Sum++;
        }
      }
    }
    cout << Sum << "\\n";
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int N, x, y, ans[2010];

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int N, x, y, ans[2010];

int main() {
  cin >> N >> x >> y;
  for (int i = 1; i <= x; i++)
    for (int j = i + 1; j <= x; j++)
      ans[j - i]++;
  for (int i = y; i <= N; i++)
    for (int j = y + 1; j <= N; j++)
      ans[j - i]++;
  for (int i = x + 1; i < y; i++)
    for (int j = i + 1; j < y; j++)
      ans[min(j - i, i - x + y - j + 1)]++;
  for (int i = 1; i <= x; i++)
    for (int j = x + 1; j < y; j++)
      ans[min(j - i, y - j + 1 + x - i)]++;
  for (int i = y; i <= N; i++)
    for (int j = x + 1; j < y; j++)
      ans[min(i - j, j - x + 1 + i - y)]++;
  for (int i = 1; i <= x; i++)
    for (int j = y; j <= N; j++)
      ans[j - y + x - i + 1]++;
  for (int i = 1; i < N; i++)
    cout << ans[i] << 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;
  x--;
  y--;
  int a[n] = {};
  for (int i = 0; i < n - 1; i++) {
    for (int j = 1; j < n; j++) {
      if (i <= x && j <= x || i >= y && j >= y) {
        a[j - i]++;
      } else if (i <= x && j > x && j < y) {
        int s = min(j - i, x - i + 1 + y - j);
        a[s]++;
      } else if (i <= x && j >= y) {
        a[x - i + 1 + j - y]++;
      } else if (i > x && i < y && j > x && j < y) {
        int s = min(j - i, i - x + 1 + y - j);
        a[s]++;
      } else {
        int s = min(j - i, i - x + 1 + j - y);
        a[s]++;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    cout << a[i] << endl;
  }
}

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> a(n, 0);
  for (int i = 1; i < n; i++) {
    for (int j = 2; j < n + 1; j++) {
      if (i <= x && j <= x || i >= y && j >= y) {
        a[j - i]++;
      } else if (i <= x && j > x && j < y) {
        a[min(j - i, x - i + 1 + y - j)]++;
      } else if (i <= x && j >= y) {
        a[x - i + 1 + j - y]++;
      } else if (i > x && i < y && j > x && j < y) {
        a[min(j - i, i - x + 1 + y - j)]++;
      } else {
        a[min(j - i, i - x + 1 + j - y)]++;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    cout << a[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(obj) (obj).begin(), (obj).end()
const int mod = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<int> ans(n, 0);
  rep(sv, n) {
    vector<int> dist(n, mod);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != mod)
        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; i++)
    cout << ans[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dp[2004][2004];
int n, x, y;
void dfs(int xx, int yy, int kk) {
  if (dp[xx][yy] <= kk)
    return;
  dp[xx][yy] = kk;
  if (xx - 1 >= 0)
    dfs(xx - 1, yy, kk + 1);
  if (yy - 1 != xx)
    dfs(xx, yy - 1, kk + 1);
  if (xx + 1 != yy)
    dfs(xx + 1, yy, kk + 1);
  if (yy + 1 < n)
    dfs(xx, yy + 1, kk + 1);
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x >> y;
  --x;
  --y;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      dp[i][j] = j - i;
  dfs(x, y, 1);
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      a[dp[i][j]]++;
  for (int i = 1; i < n; i++)
    cout << a[i] << endl;
  return 0;
}