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

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> ans(N + 1);
  for (int i = 1; i <= N; ++i) {
    for (int k = 1; k <= N; ++k) {
      if (i == k)
        continue;
      int tmp = min(k - i, abs(X - i) + 1 + abs(Y - k));
      if (tmp < 0)
        continue;
      ans.at(tmp)++;
    }
  }
  for (int i = 1; i < N; ++i) {
    cout << ans.at(i) << endl;
  }
}

Error: -11

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> ans(N + 1);
  for (int i = 1; i <= N; ++i) {
    for (int k = 1; k <= N; ++k) {
      if (i == k)
        continue;
      int tmp = min(k - i, abs(X - i) + 1 + abs(Y - k));
      ans[tmp]++;
    }
  }
  for (int i = 1; i < N; ++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##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }

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

  // グラフ
  vector<int> d(N);
  for (int i = 1; i <= N; ++i) {
    for (int j = 1 + i; j <= N; ++j) {
      ll tmp = min(j - i, abs(X - i) + abs(Y - j) + 1);
      d[tmp]++;
    }
  }

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

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  const int INF = 1e+6;
  vector<vector<int>> d;
  d.assign(N, vector<int>(N + 1, INF));

  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 k = 0; k < N - 1; k++) {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (d[i][j] == k + 1) {
          cnt++;
        }
      }
    }
    cout << cnt << 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;
  x--;
  y--;
  int ans[n];
  fill(ans, ans + n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int d = min(j - i, abs(x - i) + 1 + abs(y - j));
      ans[d]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  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++) {
        int d = min(j - i, abs(x - i) + 1 + abs(y - j));
        if (d == k)
          ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define abs(x) (0 <= (x) ? (x) : -(x))

int main() {

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

  int count[N] = {0};
  int i, j, dis;

  for (i = 1; i < N; ++i) {
    for (j = i + 1; j <= N; ++j) {
      dis = min(min(j - i, abs(X - i) + 1 + abs(j - Y)),
                abs(Y - i) + 1 + abs(j - X));
      ++count[dis];
    }
  }

  for (i = 1; i < N; ++i)
    cout << count[i] << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

#define abs(x) (0 <= (x) ? (x) : -(x))

int main() {

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

  int count;
  int i, j;

  for (int k = 1; k < N; ++k) {
    if (k == 1) {
      cout << N << endl;
      continue;
    }
    count = 0;
    for (i = 1; i <= N - k; ++i) {
      for (j = i + k; j <= N; ++j) {
        if (k == min(min(j - i, abs(X - i) + 1 + abs(j - Y)),
                     abs(Y - i) + 1 + abs(j - X))) {
          ++count;
        }
      }
    }
    cout << count << endl;
  }

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

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

typedef long long int ll;

#define pb push_back
#define mp make_pair

const ll maxs = 3005;
ll inf = 1e18;

ll cost[maxs][maxs];
ll dp[maxs][maxs];
ll n;

void warshall() {
  for (ll k = 1; k <= n; k++)
    for (ll i = 1; i <= n; i++)
      for (ll j = 1; j <= n; j++)
        if (dp[i][j] > dp[i][k] + dp[k][j])
          dp[i][j] = dp[i][k] + dp[k][j];
}

// Use when new roads to be build
void update(ll s, ll d, ll w) {
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (dp[i][j] > dp[i][s] + w + dp[d][j])
        dp[i][j] = dp[i][s] + w + dp[d][j];

      if (dp[i][j] > dp[i][d] + w + dp[s][j])
        dp[i][j] = dp[i][d] + w + dp[s][j];
    }
  }
}

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

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      cost[i][j] = abs(i - j);
      dp[i][j] = cost[i][j];
    }
  }

  /*  for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    } */

  update(x, y, 1);

  ll res[n + 1];
  memset(res, 0, sizeof res);
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i + 1; j <= n; j++) {
      res[dp[i][j]]++;
    }
  }

  for (ll i = 1; i < n; i++)
    cout << res[i] << endl;

  return 0;
}

Error: 0

Fixed submission:

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

typedef long long int ll;

#define pb push_back
#define mp make_pair

const ll maxs = 305;
ll inf = 1e18;

ll cost[maxs][maxs];
ll dp[maxs][maxs];
ll n;

void warshall() {
  for (ll k = 1; k <= n; k++)
    for (ll i = 1; i <= n; i++)
      for (ll j = 1; j <= n; j++)
        if (dp[i][j] > dp[i][k] + dp[k][j])
          dp[i][j] = dp[i][k] + dp[k][j];
}

// Use when new roads to be build
void update(ll s, ll d, ll w) {
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (dp[i][j] > dp[i][s] + w + dp[d][j])
        dp[i][j] = dp[i][s] + w + dp[d][j];

      if (dp[i][j] > dp[i][d] + w + dp[s][j])
        dp[i][j] = dp[i][d] + w + dp[s][j];
    }
  }
}

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

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      cost[i][j] = abs(i - j);
      dp[i][j] = cost[i][j];
    }
  }

  /*  for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    } */

  update(x, y, 1);

  ll res[n + 1];
  memset(res, 0, sizeof res);
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i + 1; j <= n; j++) {
      res[dp[i][j]]++;
    }
  }

  for (ll i = 1; i < n; i++)
    cout << res[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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/*
O(|E|log|V|)

P.first = shortest path, P.second = vertex index
G[v] = vector of edge (from v)
d[v] = shortest path from s to v
*/

struct edge {
  int to, cost;
};

void dijkstra(vector<vector<edge>> &G, vector<int> &d, int s) {
  int V = G.size();
  const int INF = 10e8;
  priority_queue<P, vector<P>, greater<P>> que;

  rep(i, V) d[i] = 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;
    rep(i, G[v].size()) {
      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));
      }
    }
  }
}

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

  vector<int> ans(N);
  rep(i, N) {
    vector<int> d(N);
    dijkstra(G, d, i);
    rep(j, N) {
      if (1 <= d[j] && d[j] <= N - 1) {
        ++ans[d[j] - 1];
      }
    }
  }

  rep(k, N - 1) { cout << ans[k] / 2 << endl; }
}

Error: -6
double free or corruption (out)


Fixed submission:

#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>;

/*
O(|E|log|V|)

P.first = shortest path, P.second = vertex index
G[v] = vector of edge (from v)
d[v] = shortest path from s to v
*/

struct edge {
  int to, cost;
};

void dijkstra(vector<vector<edge>> &G, vector<int> &d, int s) {
  int V = G.size();
  const int INF = 10e8;
  priority_queue<P, vector<P>, greater<P>> que;

  rep(i, V) d[i] = 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;
    rep(i, G[v].size()) {
      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));
      }
    }
  }
}

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

  vector<int> ans(N);
  rep(i, N) {
    vector<int> d(N);
    dijkstra(G, d, i);
    rep(j, N) {
      if (1 <= d[j] <= N - 1) {
        ++ans[d[j] - 1];
      }
    }
  }

  rep(k, N - 1) { cout << ans[k] / 2 << endl; }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, a, b) for (long long int i = (a); i < (b); i++)

using namespace std;
using ll = long long int;
using ld = long double;

auto p = [](auto s) { cout << s << endl; };

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> d(N, vector<int>(N));
  rep(i, 0, N) {
    rep(j, 0, N) { d[i][j] = abs(i - j); }
  }
  X--;
  Y--;

  d[X][Y] = 1;
  d[Y][X] = 1;
  rep(i, 0, N) {
    rep(j, 0, N) { d[i][j] = min(d[i][j], d[i][X] + d[X][j]); }
  }
  rep(i, 0, N) {
    rep(j, 0, N) { d[i][j] = min(d[i][j], d[i][Y] + d[Y][j]); }
  }
  vector<int> ans(N);
  rep(i, 0, N) {
    rep(j, 0, N) { ans[d[i][j]] += 1; }
  }

  rep(k, 1, N) { p(ans[k] / 2); }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (long long int i = (a); i < (b); i++)

using namespace std;
using ll = long long int;
using ld = long double;

auto p = [](auto s) { cout << s << endl; };

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> d(N, vector<int>(N));
  rep(i, 0, N) {
    rep(j, 0, N) { d[i][j] = abs(i - j); }
  }
  X--;
  Y--;

  d[X][Y] = 1;
  d[Y][X] = 1;
  rep(i, 0, N) {
    rep(j, 0, N) { d[i][j] = min(d[i][j], d[i][X] + d[X][j]); }
  }
  rep(i, 0, N) {
    rep(j, 0, N) { d[i][j] = min(d[i][j], d[i][Y] + d[Y][j]); }
  }
  rep(k, 1, N) {
    int ans = 0;
    rep(i, 0, N) {
      rep(j, 0, N) {
        if (d[i][j] == k) {
          ans += 1;
        }
      }
    }
    p(ans / 2);
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9 : (int)1e18)
#define EPS 0.0000000001
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
  return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
  auto inner = vectors(tail...);
  return vector<decltype(inner)>(x, inner);
}
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
signed main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> d(N + 1, vector<int>(N + 1, INF));
  // rep(i,N + 1)d[i][i] = 0;
  rep(i, N) d[i][i + 1] = d[i + 1][i] = 1;
  d[X - 1][Y - 1] = d[Y - 1][X - 1] = 1;
  rep(k, N) rep(i, N) rep(j, N) cmin(d[i][j], d[i][k] + d[k][j]);
  map<int, int> memo;
  rep(i, N) rep(j, N) if (i < j) memo[d[i][j]]++;
  rep(i, N) if (i) cout << memo[i] << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error


#include <stdio.h>

#define N_MAX 20002
struct sNode {
  int cost;
};
sNode Node[N_MAX];

int CostList[N_MAX];

int main() {
#ifdef _WIN32
  freopen("input.txt", "r", stdin);
#endif

  int N, X, Y;
  scanf("%d %d %d", &N, &X, &Y);

  for (int n = 1; n <= N; n++) {
    // Initialize
    for (int k = 1; k <= N; k++)
      Node[k].cost = (n - k < 0) ? -(n - k) : (n - k);

    if (Node[X].cost < Node[Y].cost) {
      if (Node[Y].cost > Node[X].cost + 1)
        Node[Y].cost = Node[X].cost + 1;

      for (int i = 1; (1 <= Y - i) || (Y + i <= N); i++) {
        if ((Node[Y].cost + i < Node[Y + i].cost) && (Y + i <= N))
          Node[Y + i].cost = Node[Y].cost + i;
        if ((Node[Y].cost + i < Node[Y - i].cost) && (1 <= Y - i))
          Node[Y - i].cost = Node[Y].cost + i;
      }
    } else {
      if (Node[X].cost > Node[Y].cost + 1)
        Node[X].cost = Node[Y].cost + 1;

      for (int i = 1; (1 <= X - i) || (X + i <= N); i++) {
        if ((Node[X].cost + i < Node[X + i].cost) && (X + i <= N))
          Node[X + i].cost = Node[X].cost + i;
        if ((Node[X].cost + i < Node[X - i].cost) && (1 <= X - i))
          Node[X - i].cost = Node[X].cost + i;
      }
    }

#ifdef _WIN32
    for (int k = 1; k <= N; k++)
      printf("%d / %d\\n", k, Node[k].cost);
    printf("\\n");
#endif

    for (int k = 1; k <= N; k++)
      CostList[Node[k].cost]++;
  }

  for (int n = 1; n < N; n++)
    printf("%d\\n", CostList[n] / 2);
  return 0;
}


Error: 0

Fixed submission:


#include <stdio.h>

#define N_MAX 2002
struct sNode {
  int ShortCut;
  int id;
  int cost;
};
sNode Node[N_MAX];

int CostList[N_MAX];

int main() {
#ifdef _WIN32
  freopen("input.txt", "r", stdin);
#endif

  int N, X, Y;
  scanf("%d %d %d", &N, &X, &Y);
  Node[X].ShortCut = Y;
  Node[Y].ShortCut = X;

  for (int n = 1; n <= N; n++) {
    // Initialize
    for (int k = 1; k <= N; k++) {
      Node[k].cost = (n - k < 0) ? -(n - k) : (n - k);
      Node[k].id = n;
    }

    if (Node[X].cost < Node[Y].cost) {
      if (Node[Y].cost > Node[X].cost + 1)
        Node[Y].cost = Node[X].cost + 1;

      for (int i = 1; (1 <= Y - i) || (Y + i <= N); i++) {
        if ((Node[Y].cost + i < Node[Y + i].cost) && (Y + i <= N))
          Node[Y + i].cost = Node[Y].cost + i;
        if ((Node[Y].cost + i < Node[Y - i].cost) && (1 <= Y - i))
          Node[Y - i].cost = Node[Y].cost + i;
      }
    } else {
      if (Node[X].cost > Node[Y].cost + 1)
        Node[X].cost = Node[Y].cost + 1;

      for (int i = 1; (1 <= X - i) || (X + i <= N); i++) {
        if ((Node[X].cost + i < Node[X + i].cost) && (X + i <= N))
          Node[X + i].cost = Node[X].cost + i;
        if ((Node[X].cost + i < Node[X - i].cost) && (1 <= X - i))
          Node[X - i].cost = Node[X].cost + i;
      }
    }

#ifdef _WIN32
    for (int k = 1; k <= N; k++)
      printf("%d / %d\\n", k, Node[k].cost);
    printf("\\n");
#endif

    for (int k = 1; k <= N; k++)
      CostList[Node[k].cost]++;
  }

  for (int n = 1; n < N; n++)
    printf("%d\\n", CostList[n] / 2);
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define int long long

#define REP(i, b) for (int i = 0; i < (b); i++)
#define REPS(i, b) for (int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vvi dp(N, vi(N));
  dp[X][Y] = 1;
  REP(i, N) {
    for (int j = i + 1; j < N; j++) {
      dp[i][j] = j - i;
      chmin(dp[i][j], abs(i - X) + 1 + abs(j - Y));
      chmin(dp[i][j], abs(i - Y) + 1 + abs(j - X));
    }
  }
  vi ans(N);
  REP(i, N) for (int j = i + 1; j < N; j++) ans[dp[i][j]]++;
  REPS(i, N - 1) cout << ans[i] << endl;
  /*
 REP(i, N)
 {
     REP(j, N) cout << dp[i][j] << " ";
     cout << endl;
 }
 */
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define int long long

#define REP(i, b) for (int i = 0; i < (b); i++)
#define REPS(i, b) for (int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int N, X, Y;
vvb G;
vvi d;

void djikstra(int s) {
  priority_queue<pi, vector<pi>, greater<pi>> q;
  d[s][s] = 0;
  q.push(mp(0, s));

  while (!q.empty()) {
    pi p = q.top();
    q.pop();
    int v = p.second;
    if (d[s][v] < p.first)
      continue;

    for (int i = 0; i < N; i++) {
      if (G[v][i] && d[s][i] > d[s][v] + 1) {
        d[s][i] = d[s][v] + 1;
        q.push(mp(d[s][i], i));
      }
    }
  }
}

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> X >> Y;
  X--;
  Y--;
  G.resize(N, vb(N, false));
  d.resize(N, vi(N, INF));
  REP(i, N - 1) {
    G[i][i + 1] = true;
    G[i + 1][i] = true;
  }
  G[X][Y] = true;
  G[Y][X] = true;

  REP(i, N) djikstra(i);
  vi ans(N);
  REP(i, N) for (int j = i + 1; j < N; j++) ans[d[i][j]]++;
  REPS(i, N - 1) cout << ans[i] << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 2e3 + 34;

int s[N];

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  --x;
  --y;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = j - i; // 3
      if (j >= y && i <= x) {
        d -= y - x - 1;
      } else if (i <= x && j <= y && j > x) {
        d = min(d, x - i + y - j + 1); // 3, 1-0+3-3+1
      } else if (i >= x && i < y && j >= y) {
        d = min(d, i - x + j - y + 1); // 2, 2-1+4-3+1
      } else if (i >= x && j <= y) {
        d = min(d, i - x + y - j + 1);
      }
      ++s[d];
      // printf("(%d, %d) -> %d\\n", i+1, j+1, d);
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", s[i]);
  }
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 2e3 + 34;

int s[N];

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  --x;
  --y;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int d = j - i; // 3
      if (j >= y && i <= x) {
        d -= y - x - 1;
      } else if (i <= x && j <= y && j > x) {
        d = min(d, x - i + y - j + 1); // 3, 1-0+3-3+1
      } else if (i >= x && i < y && j >= y) {
        d = min(d, i - x + j - y + 1); // 2, 2-1+4-3+1
      } else {
        d = min(d, i - x + y - j + 1);
      }
      ++s[d];
      // printf("(%d, %d) -> %d\\n", i+1, j+1, d);
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", s[i]);
  }
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}