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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
inline int in() {
  int x;
  cin >> x;
  return x;
}
const int MX = 2005;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) FOR(i, 0, (n))
inline int in() {
  int x;
  cin >> x;
  return x;
}

int n;
int dp[2005][2005];
int ans[2005];
void dfs(int x, int y, int dist) {
  if (dp[x][y] <= dist)
    return;
  ans[dp[x][y]]--;
  dp[x][y] = dist;
  ans[dist]++;
  dist++;
  if (x - 1 >= 0)
    dfs(x - 1, y, dist);
  dfs(x + 1, y, dist);
  dfs(x, y - 1, dist);
  if (y + 1 < n)
    dfs(x, y + 1, dist);
}

/*-------------------------------------------------*/
int main() {
  n = in();
  int x = in() - 1, y = in() - 1;
  rep(i, n - 1) FOR(j, i + 1, n) dp[i][j] = j - i;
  FOR(i, 1, n) ans[i] = n - i;
  dfs(x, y, 1);
  FOR(i, 1, n) cout << ans[i] << 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;
  int dist[2001] = {0};
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      dist[min(j - i, min(abs(X - i) + 1 + abs(j - Y),
                          abs(Y - i) + 1 + abs(j - X)))]++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << dist[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int white = 0, gray = 1, black = 2, N = 2001, INF = -1;
bool G[N][N];
int n, color[N], d[N];

void init() {
  for (int i = 1; i <= n; i++) {
    color[i] = white;
    d[i] = INF;
  }
}

void bfs(int v) {
  queue<int> q;
  q.push(v);
  d[v] = 0;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 1; i <= n; i++) {
      if (G[u][i] && color[i] == white) {
        d[i] = d[u] + 1;
        q.push(i);
        color[i] = gray;
      }
    }
    color[u] = black;
  }
}
int main() {
  int X, Y;
  cin >> n >> X >> Y;
  int dist[2001];
  for (int i = 1; i < n; i++) {
    G[i][i + 1] = 1;
    G[i + 1][i] = 1;
  }
  G[X][Y] = 1;
  G[Y][X] = 1;
  for (int i = 1; i <= n; i++) {
    init();
    bfs(i);
    for (int j = i + 1; j <= n; j++) {
      dist[d[j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << dist[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define vv vector
#define ff first
#define ss second
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
typedef pair<ll, ll> pll;
typedef vv<ll> vll;
// #define dbg

ll inf = 1e14;

void bfs(ll s, vll &dis, vv<vll> &gr) {
  queue<pll> q;
  q.emplace(0, s);
  while (!q.empty()) {
    pll t = q.front();
    q.pop();
    if (dis[t.ss] != inf)
      continue;
    dis[t.ss] = t.ff;
    for (auto &i : gr[t.ss]) {
      if (dis[i] == inf) {
        q.emplace(t.ff + 1, i);
      }
    }
  }
}

int main() {
  fastio;
  ll n, x, y;
  cin >> n >> x >> y;
  vv<vll> gr(n + 1);
  for (ll i = 1; i <= n - 1; i++) {
    gr[i].push_back(i + 1);
    gr[i + 1].push_back(i);
  }
  gr[x].push_back(y);
  gr[y].push_back(x);

  vv<vll> d(n + 1, vll(n + 1, inf));
  for (ll i = 0; i < n; i++) {
    bfs(i + 1, d[i + 1], gr);
  }
  vll as(n, 0);
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      as[d[i][j]]++;
    }
  }

#ifdef dbg
  cerr << ":\\n";
  for (auto &i : d) {
    for (auto &j : i)
      if (j < 1e9)
        cerr << j << "  ";
      else
        cerr << -1 << " ";
    cerr << endl;
  }
#endif
  for (ll i = 1; i <= n - 1; i++) {
    cout << as[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define vv vector
#define ff first
#define ss second
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
typedef pair<ll, ll> pll;
typedef vv<ll> vll;
// #define dbg

int main() {
  fastio;
  ll n;
  cin >> n;
  ll d[n][n];
  for (auto &i : d)
    for (auto &j : i)
      j = 1e14;
  for (ll i = 0; i < n - 1; i++) {
    d[i][i] = 0;
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }
  d[n - 1][n - 1] = 0;
  ll x, y;
  cin >> x >> y;
  d[x - 1][y - 1] = 1;
  for (ll k = 0; k < n; k++) {
    for (ll j = 0; j < n; j++) {
      for (ll i = 0; i < n; i++) {
        d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
      }
    }
#ifdef dbg
    cerr << ":\\n";
    for (auto &i : d) {
      for (auto &j : i)
        if (j < 1e9)
          cerr << j << "  ";
        else
          cerr << -1 << " ";
      cerr << endl;
    }
#endif
  }
  // cerr<<1;

  ll as[n];
  fill(as, as + n, 0);
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      if (d[i][j] < 1e9)
        as[d[i][j]]++;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << as[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main() {
  ll n, X, Y;
  cin >> n >> X >> Y;

  X--;
  Y--;

  //    vector<vector<ll>> d(n, vector<ll>(n));
  vector<ll> cnt(n);
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll d = min(abs(i - j), abs(X - i) + 1 + abs(Y - j));
      cnt[d]++;
    }
  }

  repi(k, n) { put(cnt[k]); }
}
signed main() {
  Main();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main() {
  ll n, X, Y;
  cin >> n >> X >> Y;

  // Warshall–Floyd
  ll INF = 1e18;
  vector<vector<ll>> d(n, vector<ll>(n, INF));
  rep(i, n - 1) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }
  d[X - 1][Y - 1] = 1;
  d[Y - 1][X - 1] = 1;
  rep(k, n) {
    rep(i, n) {
      rep(j, n) {
        if (i != j && d[i][k] < INF && d[k][j] < INF) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
  }

  vector<ll> res(n);
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      if (d[i][j] < n) {
        res[d[i][j]]++;
      }
    }
  }

  repi(k, n) { put(res[k]); }
}
signed main() {
  Main();
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  int n, x, y;
  cin >> n >> x >> y;

  vector<int> res(n - 1);
  for (int i = 0; i <= n - 2; i++)
    res[i] = 0;
  for (int i = 0; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      int kyori = 0;
      kyori = min({abs(j - i), 1 + abs(x - 1 - i) + abs(j - y + 1),
                   1 + abs(y - 1 - i) + abs(j - x + 1)});
      res[kyori - 1]++;
      // cout << "i" << i << " j" << j << " " << kyori << endl;
    }
  }
  for (int i = 0; i <= n - 2; i++) {
    cout << res[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> res(n - 1);
  for (int i = 0; i <= n - 1; i++)
    res[i] = 0;
  for (int i = 0; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      int kyori = 0;
      kyori = min({abs(j - i), 1 + abs(x - 1 - i) + abs(j - y + 1),
                   1 + abs(y - 1 - i) + abs(j - x + 1)});
      res[kyori - 1]++;
      // cout << "i" << i << " j" << j << " " << kyori << endl;
    }
  }
  for (int i = 0; i <= n - 2; i++)
    cout << res[i] << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

/*input
10 4 8
*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6;

int n, x, y;
int dmap[N];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int L = 1; L < n; ++L) {
    for (int R = L + 1; R <= n; ++R) {
      int d1 = R - L;
      int d2 = abs(L - x) + 1 + abs(R - y);
      dmap[min(d1, d2)]++;
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", dmap[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

/*input
10 4 8
*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6;

vector<int> adj[2048];
char vs[2048];

int dfs(int u, int v, int d) {
  if (u == v)
    return d;
  if (vs[u])
    return INT_MAX / 2;
  vs[u] = true;
  int ans = INT_MAX;
  for (auto c : adj[u]) {
    ans = min(ans, dfs(c, v, d + 1));
  }
  vs[u] = false;
  return ans;
}

void add(int u, int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}

map<int, int> dmap;

int n, x, y;
int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; ++i) {
    add(i - 1, i);
  }
  add(x - 1, y - 1);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int dist = dfs(i, j, 0);
      // printf("%d %d %d\\n", i, j, dist);
      dmap[dist]++;
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", dmap[i]);
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

// minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
template <class T> inline bool cmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T> inline bool cmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
const int N = 2e5 + 5;
char s[N];
int a[N], n, x, m, res, y, d;
inline int calc(R int i, R int j) {
  if (i <= x && j >= y)
    return j - i - (y - x) + 1;
  if (i <= x && j <= x)
    return j - i;
  if (i >= y && j >= y)
    return j - i;
  if (i <= x)
    return min(j - i, y - j + 1 + x - i);
  if (j >= y)
    return min(j - i, j - y + 1 + i - x);
  return min(j - i, i - x + y - j + 1);
}
int main() {
  //	freopen("testdata.in","r",stdin);
  scanf("%d%d%d", &n, &x, &y);
  fp(i, 1, n) fp(j, i + 1, n)++ a[calc(i, j)];
  fp(i, 1, n - 1) printf("%d\\n", a[i]);
  return 0;
}

Error: 0

Fixed submission:

// minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
template <class T> inline bool cmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T> inline bool cmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
const int N = 2e5 + 5;
char s[N];
int a[N], n, x, m, res, y, d;
inline int calc(R int i, R int j) {
  if (i <= x && j >= y)
    return j - i - (y - x) + 1;
  if (i <= x && j <= x)
    return j - i;
  if (i >= y && j >= y)
    return j - i;
  if (i <= x)
    return min(j - i, y - j + 1 + x - i);
  return min(j - i, j - y + 1 + i - x);
}
int main() {
  //	freopen("testdata.in","r",stdin);
  scanf("%d%d%d", &n, &x, &y);
  fp(i, 1, n) fp(j, i + 1, n)++ a[calc(i, j)];
  fp(i, 1, n - 1) printf("%d\\n", a[i]);
  return 0;
}
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 < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<vector<int>> graph(n);
  rep(i, n) {
    if (i != n - 1) {
      graph[i].push_back(i + 1);
      graph[i + 1].push_back(i);
    }
    if (i == x) {
      graph[x].push_back(y);
      graph[y].push_back(x);
    }
  }

  vector<int> ans(n - 1);
  rep(i, n) {
    vector<int> dis(n, -1);
    queue<int> q;
    q.push(i);
    dis[i] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      rep(i, graph[v].size()) {
        int u = graph[v][i];
        if (dis[u] == -1) {
          dis[u] = dis[v] + 1;
          q.push(u);
          ans[dis[u] - 1]++;
        }
      }
    }
  }
  rep(i, n - 1) { cout << ans[i] / 2 << endl; }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<vector<int>> graph(n);
  rep(i, n) {
    if (i != n - 1) {
      graph[i].push_back(i + 1);
      graph[i + 1].push_back(i);
    }
    if (i == x) {
      graph[x].push_back(y);
      graph[y].push_back(x);
    }
  }

  rep(k, n - 1) {
    int ans = 0;
    rep(i, n) {
      vector<int> dis(n, -1);
      queue<int> q;
      q.push(i);
      dis[i] = 0;
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        if (dis[v] > k + 1) {
          break;
        }
        rep(i, graph[v].size()) {
          int u = graph[v][i];
          if (dis[u] == -1) {
            dis[u] = dis[v] + 1;
            q.push(u);
            if (dis[u] == k + 1) {
              ans++;
            }
          }
        }
      }
    }
    cout << ans / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  int N, X, Y;
  int ans[2001];
  cin >> N >> X >> Y;
  for (int i = 1; i <= N - 1; i++) {
    ans[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1 + i; j <= N; j++) {
      int min = j - i;
      if (min > abs(i - X) + 1 + abs(j - Y)) {
        min = abs(i - X) + 1 + abs(j - Y);
      }
      if (min > abs(i - Y) + 1 + abs(j - X)) {
        min = abs(i - Y) + 1 + abs(j - X);
      }
      ans[min]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  int N, X, Y;
  int ans[201];
  cin >> N >> X >> Y;
  for (int i = 1; i <= N - 1; i++) {
    ans[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1 + i; j <= N; j++) {
      int min = j - i;
      if (min > abs(i - X) + 1 + abs(j - Y)) {
        min = abs(i - X) + 1 + abs(j - Y);
      }
      if (min > abs(i - Y) + 1 + abs(j - X)) {
        min = abs(i - Y) + 1 + abs(j - X);
      }
      ans[min]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int a[2010][2010] = {};
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      a[i][j] = j - i;
    }

  a[x][y] = 1;
  for (int i = 1; i < n; i++) {
    int change = 0;
    for (int j = -i; j <= i; j++) {
      int k = i - abs(j);
      if ((x + j) > 0 && (x + j) <= n && (y + k) <= n) {
        if (a[x + j][y + k] > (a[x][y] + i)) {
          a[x + j][y + k] = (a[x][y] + i);
          change = 1;
        }
      }
      if ((x + j) > 0 && (x + j) <= n && (y - k) > 0) {
        if (a[x + j][y - k] > (a[x][y] + i)) {
          a[x + j][y - k] = (a[x][y] + i);
          change = 1;
        }
      }
    }
    if (change == 0)
      break;
  }

  int ans[2010] = {};
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      ans[a[i][j]]++;
    }
  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;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int a[2000][2000] = {};
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      a[i][j] = j - i;
    }

  a[x][y] = 1;
  for (int i = 1; i < n; i++) {
    int change = 0;
    for (int j = -i; j <= i; j++) {
      int k = i - abs(j);
      if ((x + j) > 0 && (x + j) <= n && (y + k) <= n) {
        if (a[x + j][y + k] > (a[x][y] + i)) {
          a[x + j][y + k] = (a[x][y] + i);
          change = 1;
        }
      }
      if ((x + j) > 0 && (x + j) <= n && (y - k) > 0) {
        if (a[x + j][y - k] > (a[x][y] + i)) {
          a[x + j][y - k] = (a[x][y] + i);
          change = 1;
        }
      }
    }
    if (change == 0)
      break;
  }

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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e3 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL d[MAXN][MAXN];
LL min(LL a, LL b) { return a > b ? b : a; }

int main() {
  fio();
  LL n, x, y;
  cin >> n >> x >> y;
  vector<LL> an(n + 1);
  for1(i, n) {
    for (int j = i + 1; j <= n; j++) {
      an[min(abs(i - x) + 1LL + abs(j - y), (j - i))]++;
    }
  }
  for1(i, n - 1) cout << an[i] << endl;

  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e3 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL d[MAXN][MAXN];
LL min(LL a, LL b) { return a > b ? b : a; }

int main() {
  fio();
  LL n, x, y;
  cin >> n >> x >> y;
  vector<LL> an(n + 1);
  for1(i, n) {
    for (int j = i + 1; j <= n; j++) {
      an[min((i - x) + 1LL + (j - y), (j - i))]++;
    }
  }
  for1(i, n - 1) cout << an[i] << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e3 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL d[MAXN][MAXN];
LL min(LL a, LL b) { return a > b ? b : a; }

int main() {
  fio();
  LL n, x, y;
  cin >> n >> x >> y;
  vector<LL> an(n + 1);
  for1(i, n) {
    for (int j = i + 1; j <= n; j++) {
      if (i <= x && j >= y) {
        an[j - i - (y - x) + 1]++;
      } else if (i >= x && j >= y) {
        LL pp = min((i - x) + 1LL + (j - y), (j - i));
        an[pp]++;
      } else if (i >= x && j <= y) {
        LL pp = min((i - x) + 1LL + (y - j), (j - i));
        an[pp]++;
      } else if (i <= x && y >= j && j >= x) {
        LL pp = min(x - i + 1LL + (y - j), (j - i));
        an[pp]++;
      } else
        an[j - i]++;
      // if(an[5]) cout<<i<<" "<<j<<endl;
    }
  }
  for1(i, n - 1) cout << an[i] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e3 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL d[MAXN][MAXN];

int main() {
  fio();
  LL n, x, y;
  cin >> n >> x >> y;
  //  cout<<n<<endl;
  for1(i, n) {
    for1(j, n) { d[i][j] = i == j ? 0 : 1e9; }
  }
  for1(i, n - 1) d[i][i + 1] = d[i + 1][i] = 1;
  d[x][y] = 1;
  d[y][x] = 1;

  for1(k, n) for1(i, n) for1(j, n) if (d[i][k] + d[k][j] < d[i][j]) d[i][j] =
      d[i][k] + d[k][j];
  vector<LL> an(n + 1);
  for1(i, n) {
    for (int j = i + 1; j <= n; j++) {
      if (d[i][j] <= n)
        an[d[i][j]]++;
    }
  }
  for1(i, n - 1) cout << an[i] << endl;
  return 0;
}