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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, x, y;
  cin >> n >> x >> y;
  int a[n];
  x--;
  y--;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  std::vector<int> v(n, 0);
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int m = min(
          j - i, min(abs(x - i) + 1 + abs(y - j), abs(x - j) + 1 + abs(y - i)));
      v[m]++;
    }
  }
  for (std::vector<int>::iterator i = v.begin() + 1; i != v.end(); ++i) {
    cout << *i << endl;
  }
}

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 i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        mat[i][j] = 0;
      if (i == j + 1 || j == i + 1)
        mat[i][j] = 1;
    }
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      if (i == k)
        continue;
      for (int j = 0; j < n; j++) {
        if (i == j || k == 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: Runtime Error

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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int ara[n + 1];
  memset(ara, 0, sizeof(ara));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ara[min(j - i, abs(x - i) + 1 + abs(j - y))]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ara[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int ara[100000];

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ara[min(j - i, abs(x - i) + 1 + abs(j - y))]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ara[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int node;
vector<int> adj[2005];
int ara[2005];

vector<int> bfs(int st) {
  vector<int> dis(node + 1, -1);
  dis[st] = 0;
  queue<int> q;
  q.push(st);
  int d = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();

    for (int i = 0; i < adj[u].size(); i++) {
      int y = adj[u][i];
      if (dis[y] == -1) {
        dis[y] = 1;
        q.push(y);
        dis[y] = dis[u] + 1;
      }
    }
  }
  return dis;
}
int main() {
  cin >> node;
  int x, y;
  cin >> x >> y;
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 1; i < node; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  for (int i = 1; i < node; i++) {
    vector<int> dis = bfs(i);
    for (int j = i; j <= node; j++) {
      ara[dis[j]]++;
    }
  }
  for (int i = 1; i < node; i++) {
    cout << ara[i] << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
const int maxv = 2 * 1e3 + 100;
int d[maxv][maxv];
int write[maxv];
const int MAX = 0x3f3f3f3f;
void floyd(int v) {
  for (int k = 1; k <= v; k++) {
    for (int i = 1; i <= v; i++) {
      for (int j = 1; 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;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      d[i][j] = MAX;
  }
  for (int i = 1; i <= n - 1; i++)
    d[i][i + 1] = 1, d[i + 1][i] = 1;
  for (int i = 1; i <= n; i++)
    d[i][i] = 0;
  d[x][y] = 1;
  d[y][x] = 1;
  floyd(n);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      write[d[i][j]]++;
  for (int i = 1; i <= n - 1; i++)
    cout << write[i] << " ";
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int dist(int i, int j, int X, int Y, int N) {
  int d1 = j - i;
  int d2 = abs(X - i) + abs(Y - j) + 1;

  if (d1 > d2) {
    return d2;
  }
  if (d1 <= d2) {
    return d1;
  }
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<int> K(N);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      K.at(dist(i, j, X, Y, N))++;
    }
  }

  for (int k = 1; k < N; k++) {
    cout << K.at(k) << endl;
  }
}

Error: TLE

Fixed submission:

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

int dist(int i, int j, int X, int Y, int N) {
  int d1 = j - i;
  int d2 = abs(X - i) + abs(Y - j) + 1;

  if (d1 > d2) {
    return d2;
  }
  if (d1 <= d2) {
    return d1;
  }
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<vector<int>> D(N, vector<int>(N));

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      D.at(i).at(j) = dist(i, j, X, Y, N);
    }
  }

  int ans;
  for (int k = 1; k < N; k++) {
    ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (D.at(i).at(j) == k) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, x, y;
  cin >> n >> x >> y;
  map<ll, ll> m;
  for (ll i = 1; i < n; i++) {
    for (ll j = i + 1; j < n + 1; j++) {
      ll stock = min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x));
      ll len = min(abs(j - i), stock);
      m[len]++;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << m[i] << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x, y;
  cin >> n >> x >> y;
  int a[n][n];
  int b[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = 0;
      b[i][j] = 0;
      if (abs(i - j) == 1) {
        a[i][j] = 1;
        b[i][j] = 1;
      }
      if ((i == x - 1 && j == y - 1) || (i == y - 1 && j == x - 1)) {
        a[i][j] = 1;
        b[i][j] = 1;
      }
    }
  }

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

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

using namespace std;

#define N 2001
#define INFTY (1 << 21)

int d[N];
int ans[N];
int n;
int x, y;

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 1; i <= n; i++)
    d[i] = INFTY;
  d[s] = 0;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    if (u != n && d[u + 1] == INFTY) {
      d[u + 1] = d[u] + 1;
      ans[d[u + 1]]++;
      q.push(u + 1);
    }
    if (u != 1 && d[u - 1] == INFTY) {
      d[u - 1] = d[u] + 1;
      ans[d[u - 1]]++;
      q.push(u - 1);
    }
    if (u == x) {
      if (d[y] == INFTY) {
        d[y] = d[u] + 1;
        ans[d[y]]++;
        q.push(y);
      }
    }
    if (u == y) {
      if (d[x] == INFTY) {
        d[x] = d[u] + 1;
        ans[d[x]]++;
        q.push(x);
      }
    }
  }
}

int main() {
  int i;

  cin >> n >> x >> y;

  for (i = 1; i <= n; i++) {
    bfs(i);
  }

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

  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

#define N 2001
#define INFTY (1 << 21)

int M[N][N];
int d[N];
int ans[N];
int n;

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 1; i <= n; i++)
    d[i] = INFTY;
  d[s] = 0;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int v = 1; v <= n; v++) {
      if (M[u][v] == 0)
        continue;
      if (d[v] != INFTY)
        continue;
      d[v] = d[u] + 1;
      ans[d[v]]++;
      q.push(v);
    }
  }
}

int main() {
  int i;
  int x, y;

  cin >> n >> x >> y;

  for (i = 1; i < n; i++) {
    M[i][i + 1] = 1;
    M[i + 1][i] = 1;
    if (i == x) {
      M[x][y] = 1;
      M[y][x] = 1;
    }
  }

  for (i = 1; i <= n; i++) {
    bfs(i);
  }

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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
const ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define pow(x, y) modpow(x, y)
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N = in(), X = in() - 1, Y = in() - 1;
  vector<int> dist(N - 1);
  REP(i, N - 1) {
    for (int j = i + 1; j < N; j++) {
      dist[min(j - i, abs(i - X) + 1 + abs(j - Y)) - 1]++;
    }
  }
  REP(i, N - 1) cout << dist[i] << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
const ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define pow(x, y) modpow(x, y)
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N = in(), X = in(), Y = in();
  vector<vector<int>> d(N, vector<int>(N));
  REP(i, N) {
    REP(l, N) {
      if (i == l) {
        d[i][l] = 0;
      } else if (i == l + 1) {
        d[i][l] = 1;
      } else if (i + 1 == l) {
        d[i][l] = 1;
      } else if (i == X - 1 && l == Y - 1) {
        d[i][l] = 1;
      } else if (i == Y - 1 && l == X - 1) {
        d[i][l] = 1;
      } else {
        d[i][l] = 10000000;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
  vector<int> dist(N - 1);
  REP(i, N) {
    REP(l, N) {
      if (d[i][l] != 0) {
        dist[d[i][l] - 1]++;
      }
    }
  }
  REP(i, N - 1) cout << dist[i] / 2 << "\\n";
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double db;

const int maxn = 2e3 + 5;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll num[maxn];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dis = j - i;
      dis = min(dis, abs(x - i) + abs(j - y) + 1);
      num[dis]++;
    }
  }
  for (int i = 1; i < n; i++) {
    printf("%lld\\n", num[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double db;

const int maxn = 1e3 + 5;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll num[maxn];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dis = j - i;
      dis = min(dis, abs(x - i) + abs(j - y) + 1);
      num[dis]++;
    }
  }
  for (int i = 1; i < n; i++) {
    printf("%lld\\n", num[i]);
  }
  return 0;
}
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>;

vector<vector<int>> G;
vector<vector<int>> dist;
vector<int> ress;

void bfs(int t) {
  queue<int> que;
  que.push(t);
  dist[t][t] = 0;
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (int node : G[cur]) {
      if (dist[t][node] != -1) {
        continue;
      }
      dist[t][node] = dist[t][cur] + 1;
      ress[dist[t][node] - 1]++;
      que.push(node);
    }
  }
}

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

  // 距離の計算
  dist = vector<vector<int>>(n, vector<int>(n, -1));
  rep(i, n) { bfs(i); }

  // 出力
  rep(i, n - 1) {
    int res = ress[i];
    //    rep(j, n) {
    //      for (int k = j + 1; k < (n); ++k) {
    //        if (dist[j][k] == i + 1) {
    //          res++;
    //        }
    //      }
    //    }
    cout << res / 2 << endl;
  }

  return 0;
}


Error: TLE

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

vector<vector<int>> G;
vector<vector<int>> dist;

void bfs(int t) {
  queue<int> que;
  que.push(t);
  dist[t][t] = 0;
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (int node : G[cur]) {
      if (dist[t][node] != -1) {
        continue;
      }
      dist[t][node] = dist[t][cur] + 1;
      que.push(node);
    }
  }
}

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

  // 距離の計算
  dist = vector<vector<int>>(n, vector<int>(n, -1));
  rep(i, n) { bfs(i); }

  // 出力
  rep(i, n - 1) {
    int res = 0;
    rep(j, n) {
      for (int k = j + 1; k < (n); ++k) {
        if (dist[j][k] == i + 1) {
          res++;
        }
      }
    }
    cout << res << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define All(x) (x).begin(), (x).end()
#define RAll(x) (x).rbegin(), (x).rend()

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<vector<ll>> edge(N, vector<ll>(N, 1000000000));
  for (int i = 0; i < N; i++)
    edge[i][i] = 0;
  for (ll i = 0; i < N - 1; i++) {
    edge[i][i + 1] = 1;
    edge[i + 1][i] = 1;
  }
  edge[X][Y] = 1;
  edge[Y][X] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = i + 2; j < N; j++) {
      edge[i][j] = edge[i][j - 1] + 1;
    }
  }
  for (int i = 0; i <= N; i++) {
    for (int j = i + 1; j < N; j++) {
      edge[j][i] = edge[i][j];
    }
  }

  for (int i = 0; i <= X; i++) {
    for (int j = Y; j < N; j++) {
      edge[i][j] = min(edge[i][j], edge[i][X] + edge[Y][j] + 1);
      edge[j][i] = edge[i][j];
    }
  }
  for (int i = 0; i <= X; i++) {
    for (int j = X + 1; j <= Y; j++) {
      edge[i][j] = min(edge[i][j], edge[i][X] + 1 + edge[Y][j]);
    }
  }
  for (int i = Y; i < N; i++) {
    for (int j = X; j < Y; j++) {
      edge[i][j] = min(edge[i][j], edge[i][Y] + 1 + edge[X][j]);
      edge[j][i] = edge[i][j];
    }
  }
  for (int i = X; i <= Y; i++) {
    for (int j = i + 1; j <= Y; j++) {
      edge[i][j] = min(edge[i][j], edge[i][X] + 1 + edge[Y][j]);
      edge[j][i] = edge[i][j];
    }
  }
  vector<ll> ans(N + 1, 0);
  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j < N; j++) {
      ll now = edge[i][j];
      ans[now]++;
    }
  }
  for (ll i = 1; i < N; i++)
    cout << ans[i] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define All(x) (x).begin(), (x).end()
#define RAll(x) (x).rbegin(), (x).rend()

int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<vector<ll>> edge(N, vector<ll>(N, 1000000000000));
  for (ll i = 0; i < N - 1; i++) {
    edge[i][i + 1] = 1;
    edge[i + 1][i] = 1;
  }
  edge[X][Y] = 1;
  edge[Y][X] = 1;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      for (ll k = 0; k < N; k++) {
        edge[j][k] = min(edge[j][k], edge[j][i] + edge[i][k]);
      }
    }
  }
  vector<ll> ans(N + 1, 0);
  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j < N; j++) {
      ll now = edge[i][j];
      ans[now]++;
    }
  }
  for (ll i = 1; i < N; i++)
    cout << ans[i] << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define per(i, a, b) for (ll i = (a)-1; i >= (b); i--)
const ll maxn = 2e3 + 5;
ll q[maxn], d[maxn], u[maxn], s, e, c, ans[maxn], n, x, y;
vector<ll> ady[maxn];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> x >> y;
  rep(i, 1, n) ady[i].push_back(i + 1), ady[i + 1].push_back(i);
  ady[x].push_back(y), ady[y].push_back(x);
  rep(i, 1, n + 1) {
    s = e = 0;
    q[e++] = i, d[i] = 0, u[i] = ++c;
    while (s < e) {
      ll j = q[s++];
      for (ll to : ady[j])
        if (u[to] != c)
          q[e++] = to, d[to] = d[j] + 1, u[to] = c;
    }
    rep(j, 1, n + 1) ans[d[j]]++;
  }
  rep(i, 1, n) cout << ans[i] / 2 << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define per(i, a, b) for (ll i = (a)-1; i >= (b); i--)
const ll maxn = 2e3;
ll q[maxn], d[maxn], u[maxn], s, e, c, ans[maxn], n, x, y;
vector<ll> ady[maxn];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> x >> y;
  rep(i, 1, n) ady[i].push_back(i + 1), ady[i + 1].push_back(i);
  ady[x].push_back(y), ady[y].push_back(x);
  rep(i, 1, n + 1) {
    s = e = 0;
    q[e++] = i, d[i] = 0, u[i] = ++c;
    while (s < e) {
      ll j = q[s++];
      for (ll to : ady[j])
        if (u[to] != c)
          q[e++] = to, d[to] = d[j] + 1, u[to] = c;
    }
    rep(j, 1, n + 1) ans[d[j]]++;
  }
  rep(i, 1, n) cout << ans[i] / 2 << "\\n";
}
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;

  vector<int> ans(N - 1, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (min(j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j)) > 0) {
        ans.at(min(j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j)) - 1)++;
      }
    }
  }

  for (int i = 0; i < N - 1; i++) {
    cout << ans.at(i) << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 5)


Fixed submission:

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

vector<int> bfs(int ver, vector<vector<int>> &Gragh) {
  vector<int> dist(Gragh.size(), -1);
  queue<int> list;
  dist.at(ver) = 0;
  list.push(ver);

  while (!list.empty()) {
    int v = list.front();
    list.pop();
    for (int i = 0; i < Gragh.at(v).size(); i++) {
      if (dist.at(Gragh.at(v).at(i)) != -1) {
        continue;
      }
      dist.at(Gragh.at(v).at(i)) = dist.at(v) + 1;
      list.push(Gragh.at(v).at(i));
    }
  }

  return dist;
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> gragh(N);
  for (int i = 0; i < N; i++) {
    if (i - 1 >= 0) {
      gragh.at(i).push_back(i - 1);
    }
    if (i + 1 < N) {
      gragh.at(i).push_back(i + 1);
    }
  }
  gragh.at(X - 1).push_back(Y - 1);
  gragh.at(Y - 1).push_back(X - 1);

  vector<int> ans(N - 1, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N - 1; j++) {
      ans.at(j - 1) +=
          lower_bound(bfs(i, gragh).begin(), bfs(i, gragh).end(), j) -
          lower_bound(bfs(i - 1, gragh).begin(), bfs(i - 1, gragh).end(), j);
    }
  }

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

#include <algorithm>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

const int INF = 1001001001;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  --X;
  --Y;
  vector<int> ans(N);
  for (int sv = 0; sv < N; sv++) { // sv:start-vertex
    vector<int> dist(N, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist.at(v) != INF)
        return;
      dist.at(v) = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist.at(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);
    }
    for (int i = 0; i < N; ++i) {
      ans.at(dist.at(i))++;
    }
  }
  for (int i = 0; i < N; ++i) {
    ans.at(i) /= 2;
  }
  for (int i = 1; i <= N - 1; ++i) {
    cout << ans.at(i) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> d(N, vector<int>(N, N));
  for (int i = 0; i < N - 1; ++i) {
    d.at(i).at(i + 1) = 1;
    d.at(i + 1).at(i) = 1;
  }
  d.at(X - 1).at(Y - 1) = 1;
  d.at(Y - 1).at(X - 1) = 1;
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (i == j || j == k || k == i)
          continue;
        d.at(i).at(j) = min(d.at(i).at(j), d.at(i).at(k) + d.at(k).at(j));
        // cout << i << " " << k << " " << j << " " << d.at(i).at(j) <<endl;
      }
    }
  }
  vector<int> cnt(N);
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      cnt.at(d.at(i).at(j) - 1)++;
    }
  }
  for (int i = 0; i < N - 1; ++i) {
    cout << cnt.at(i) << endl;
  }
  return 0;
}