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

#include <iostream>
#include <stdlib.h>
using namespace std;

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

  int count[N];
  for (i = 0; i < N; i++)
    count[i] = 0;
  for (i = 1; i < N; i++) {
    for (j = i + 1; j < (N + 1); j++) {
      r = j - i;
      if (r > (abs(i - X) + abs(j - Y) + 1))
        r = (abs(i - X) + abs(j - Y) + 1);
      count[r]++;
    }
  }

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

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <stdlib.h>
using namespace std;

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

  int count[N];
  for (i = 0; i < N; i++)
    count[i] = 0;
  for (i = 1; i < N; i++) {
    for (j = i + 1; j <= N; j++) {
      r = j - i;
      if (r < (abs(i - X) + abs(j - Y)))
        r = (abs(i - X) + abs(j - Y));
      count[r - 1]++;
    }
  }

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

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  --X;
  --Y;
  vector<int> count(N - 1, 0);
  rep(i, N) {
    for (int j = i + 1; j < N; ++j) {
      int dist = min(j - i, abs(X - i) + abs(Y - j) + 1);
      ++count.at(dist - 1);
    }
  }
  rep(i, N - 1) cout << count.at(i) << endl;
}


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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  --X;
  --Y;
  vector<bool> opt(N - 2, false);
  rep(i, 2) opt.push_back(true);
  vector<int> count(N - 1, 0);
  do {
    rep(i, N) {
      if (opt.at(i)) {
        for (int j = i + 1; j < N; ++j) {
          if (opt.at(j)) {
            int dist = min(j - i, abs(X - i) + abs(Y - j) + 1);
            ++count.at(dist - 1);
            i = N;
            j = N;
          }
        }
      }
    }
  } while (next_permutation(opt.begin(), opt.end()));
  rep(i, N - 1) cout << count.at(i) << endl;
}
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;
  vector<int> ans(N + 1, 0);
  int count = 0;

  for (int i = 1; i <= N - 1; i++) {
    for (int j = i + 1; j <= N; j++) {
      vector<int> kouho = {abs(j - i), abs(X - i) + 1 + abs(Y - j),
                           abs(Y - i) + 1 + abs(X - j)};
      sort(kouho.begin(), kouho.end());
      int min = kouho.at(0);
      ans.at(min)++;
    }
  }
  for (int i = 1; i < N; i++)
    cout << ans.at(i) << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long N, X, Y;
  cin >> N >> X >> Y;
  long k = 1;
  long count = 0;
  while (k < N) {
    for (long i = 1; i <= N - 1; i++) {
      for (long j = i + 1; j <= N; j++) {
        vector<long> kouho = {abs(j - i), abs(X - i) + 1 + abs(Y - j),
                              abs(Y - i) + 1 + abs(X - j)};
        sort(kouho.begin(), kouho.end());
        long min = kouho.at(0);
        if (min == k) {
          count++;
        }
      }
    }
    cout << count << endl;
    count = 0;
    k++;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int calc(int i, int j, int x, int y) {

  int use;
  int dontUse;

  dontUse = j - i;
  use = abs(x - i) + abs(y - j) + 1;

  return min(dontUse, use);
}

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

  res.resize(N);
  for (int i = 1; i < N; i++) {
    res[i] = 0;
  }

  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j < N + 1; j++) {
      res[calc(i, j, X, Y)] += 1;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int calc(int i, int j, int x, int y) {

  int use;
  int dontUse;

  dontUse = j - i;
  use = abs(x - i) + abs(y - j) + 1;

  return min(dontUse, use);
}

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

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

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  int n, x, y, ans[2003] = {}, i, j;
  vector<int> g[2003];

  cin >> n >> x >> y;

  for (i = 0; i < n - 1; i++) {
    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);

  int p;
  for (i = 0; i < n; i++) {
    int d[2003] = {};
    queue<int> q;
    q.push(i);
    d[i] = 1;
    while (!q.empty()) {
      p = q.front();
      q.pop();
      for (j = 0; j < g[p].size(); j++) {
        if (d[g[p][j]] == 0) {
          d[g[p][j]] = d[p] + 1;
          q.push(g[p][j]);
        }
      }
    }
    for (j = 0; j < n; j++) {
      if (i != j)
        ans[d[j]]++;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main(void) {
  int n, x, y, d[2003][2003] = {}, i, j, k, ans[2003] = {};
  const int INF = 1e9;
  bool con;

  cin >> n >> x >> y;

  for (i - 0; i < n; i++)
    for (j = 0; j < n; j++) {
      d[i][j] = INF;
    }

  for (i = 0; i < n; i++) {
    d[i][i + 1] = d[i + 1][i] = 1;
  }

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

  con = true;
  while (con) {
    con = false;
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        for (k = 0; k < n; k++) {
          if (i == j || j == k || k == i)
            continue;
          if (d[i][j] > d[i][k] + d[k][j]) {
            con = true;
            d[i][j] = d[j][i] = d[i][k] + d[k][j];
          }
        }
  }

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

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

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


Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> ans(N, 0);
  for (int k = 1; k < N; k++) {
    for (int i = 1; i < N + 1; i++) {
      for (int j = 1; j < N + 1; j++) {
        if (k == min(abs(j - i), abs(X - i) + 1 + abs(j - Y)) && i < j) {
          ans.at(k)++;
        }
      }
    }
  }
  for (int k = 1; k < N; k++) {
    cout << ans.at(k) << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using Edge = pair<int, long long>;
int d[10000];

int main() {

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

using Edge = pair<int, long long>;

int main() {
  // string S;

  ll N, X, Y;
  cin >> N >> X >> Y;

  ll d[N][N];

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) {
        d[i][j] = 0;
      } else if (abs(j - i) == 1) {
        d[i][j] = 1;
      } else {
        d[i][j] = 100000000000;
      }
    }
  }
  d[X - 1][Y - 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]);
      }
    }
  }

  vector<int> cnt(N - 1);
  for (int i = 0; i < N - 1; i++)
    cnt[i] = 0;

  for (int i = 0; i < (N - 1); i++) {
    for (int j = i; j < N; j++) {
      // cout << d[i][j] << endl;
      if (0 < d[i][j] && d[i][j] < N) {
        cnt[d[i][j] - 1]++;
      }
    }
  }

  for (int i = 0; i < N - 1; i++)
    cout << cnt[i] << endl;

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm = 1e6;
ll d[mm];
ll vis[mm];
ll dd[2000 + 50][2000 + 50];
int main() {
  ll i, j, n, m, k, kk, kkk;
  k = 0;
  kk = maxn;
  scanf("%lld%lld%lld", &n, &m, &kkk);
  for (i = 1; i <= n; i++) {
    d[i] = i;
    dd[i][i] = 1;
  }
  dd[m][kkk] = dd[kkk][m] = 1;
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++) {
      if (dd[i][j] == 0) {
        k = (abs(m - i) + 1 + abs(kkk - j));
        kk = (abs(kkk - i) + 1 + abs(m - j));
        k = min(k, kk);
        dd[i][j] = min(abs(d[i] - d[j]), k);
      }
      if (dd[j][i] == 0) {
        k = (abs(m - j) + 1 + abs(kkk - i));
        kk = (abs(kkk - j) + 1 + abs(m - i));
        k = min(k, kk);
        dd[j][i] = min(abs(d[j] - d[i]), k);
      }
    }
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++) {
      vis[dd[i][j]]++;
    }
  for (i = 1; i <= n - 1; i++)
    printf("%lld\\n", vis[i]);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm = 1e6;
int d[mm];
int vis[mm];
int dd[2000 + 50][2000 + 50];
int main() {
  ll i, j, n, m, k, kk;
  k = 0;
  kk = maxn;
  scanf("%lld%lld%lld", &n, &m, &k);
  for (i = 1; i <= n; i++) {
    d[i] = i;
    dd[i][i] = 1;
  }
  dd[m][k] = dd[k][m] = 1;
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++) {
      if (dd[i][j] == 0)
        dd[i][j] = abs(d[i] - d[j]);
      if (dd[j][i] == 0)
        dd[j][i] = abs(d[i] - d[j]);
    }
  for (k = 1; k <= n; k++)
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) {
        dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j]);
      }
  //	printf("%lld\\n",dd[1][5]);
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++) {
      vis[dd[i][j]]++;
    }
  for (i = 1; i <= n - 1; i++)
    printf("%lld\\n", vis[i]);
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
#define int long long
  int N, X, Y;

  cin >> N >> X >> Y;
  int l;
  vector<int> box(N - 1);
  for (int i = 1; i <= X; i++) {
    for (int j = i + 1; j <= X; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
    for (int j = X + 1; j < Y; j++) {
      l = X - i + min(j - X, Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - i - Y + X + 1;
      box.at(l - 1)++;
    }
  }
  for (int i = X + 1; i < Y; i++) {
    for (int j = i + 1; j < Y; j++) {
      l = min(j - i, i - X + Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - Y + min(Y - i, i - X + 1);
      box.at(l - 1)++;
    }
  }
  for (int i = Y; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
  }
  for (int i = 0; i < (N - 1); i++) {
    cout << box.at(i) << endl;
  }
}


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


Fixed submission:

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

int main() {
#define int long long
  int N, X, Y;

  cin >> N >> X >> Y;
  int l;
  vector<int> box(N - 1);
  for (int i = 1; i <= X; i++) {
    for (int j = i + 1; j <= X; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
    for (int j = X + 1; j < Y; j++) {
      l = X - i + min(j - X, Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - i - Y + X + 1;
      box.at(l - 1)++;
    }
  }
  for (int i = X + 1; i < Y; i++) {
    for (int j = i + 1; j < Y; j++) {
      l = min(j - i, i - X + Y - j + 1);
      box.at(l - 1)++;
    }
    for (int j = Y; j <= N; j++) {
      l = j - Y + min(Y - i, i - X + 1);
      box.at(l - 1)++;
    }
  }
  for (int i = Y; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      l = j - i;
      box.at(l - 1)++;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << box.at(i) << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#define SIZE 2010
int ans[SIZE];

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#define SIZE 2010
#define INF 1000000

int dist[SIZE][SIZE], ans[SIZE];

int main() {
  int n, x, y;
  std::cin >> n >> x >> y;
  --x;
  --y;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      dist[i][j] = INF;
    }
  }

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

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j)
      ++ans[dist[i][j]];
  }
  for (int k = 1; k < n; ++k)
    std::cout << ans[k] << '\\n';

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

#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int MAX = 2000;
int a[MAX][MAX];

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

  int d[MAX] = {0};

  rep(i, n) for (int j = i + 1; j < n; ++j) {
    a[i][j] = std::min(std::abs(j - i),
                       std::abs(x - 1 - i) + 1 + std::abs(y - 1 - j));
    d[a[i][j]]++;
  }

  for (int k = 1; k < n; ++k) {
    std::cout << d[k] << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int MAX = 2000;
int a[MAX][MAX];

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

  rep(i, n) rep(j, n) a[i][j] =
      std::min(std::abs(j - i), std::abs(x - 1 - i) + 1 + std::abs(y - 1 - j));

  for (int k = 1; k < n; ++k) {
    int cnt = 0;
    rep(i, n) for (int j = i + 1; j < n; ++j) {
      if (a[i][j] == k) {
        cnt++;
      }
    }
    std::cout << cnt << '\\n';
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define INF 1000000

/*void solve(vector<vector<int>> &d, int N) {
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d.at(i).at(j) = min(d.at(i).at(j), d.at(i).at(k) +
d.at(k).at(j));
            }
        }
    }
}*/

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  /*vector<vector<int>> d (N, vector<int>(N, INF));
  d.at(X).at(Y) = 1;
  d.at(Y).at(X) = 1;
  d.at(N - 1).at(N - 1) = 0;
  for (int i = 0; i < N - 1; i++) {
      d.at(i).at(i + 1) = 1;
      d.at(i + 1).at(i) = 1;
      d.at(i).at(i) = 0;
  }
  solve(d, N);
  vector<int> ans(N, 0);
  for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
          ans.at(d.at(i).at(j))++;
      }
  }*/
  vector<int> ans(N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (i <= X && j >= Y)
        ans.at((j - i) - (Y - X) + 1)++;
      else if (i <= X && j < Y && Y - j + 1 < j - X)
        ans.at((X - i) + (Y - j) + 1)++;
      else if (i > X && j >= Y && i - X + 1 < Y - i)
        ans.at((i - X) + (j - Y) + 1)++;
      else if (i > X && j < Y && (Y - j) + (i - X) + 1 < j - i)
        ans.at((i - X) + (Y - j) + 1)++;
      else
        ans.at(j - i)++;
    }
  }
  for (int i = 1; i < N; i++)
    cout << ans.at(i) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define INF 1000000

void solve(vector<vector<int>> &d, int N) {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d.at(i).at(j) = min(d.at(i).at(j), d.at(i).at(k) + d.at(k).at(j));
      }
    }
  }
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<vector<int>> d(N, vector<int>(N, INF));
  d.at(X).at(Y) = 1;
  d.at(Y).at(X) = 1;
  d.at(N - 1).at(N - 1) = 0;
  for (int i = 0; i < N - 1; i++) {
    d.at(i).at(i + 1) = 1;
    d.at(i + 1).at(i) = 1;
    d.at(i).at(i) = 0;
  }
  solve(d, N);
  vector<int> ans(N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans.at(d.at(i).at(j))++;
    }
  }
  /*vector<int> ans(N - 1, 0);
  for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
          if (i <= X && j >= Y)
              ans.at(j - i - (Y - X))++;
          else if (i <= X && j < Y && Y - j + 1 < j - X)
              ans.at(j - i - (Y - X) + (Y - j) + 1)++;
          else if (i > X && j >= Y && i - X + 1 < Y - i)
              ans.at(j - i - (Y - X) + (i - X) + 1)++;
          else if (i > X && j < Y && (Y - j) + (i - X) + 1 < j - i)
              ans.at(j - i - (Y - X) + (Y - j) + (i - X) + 1)++;
          else
              ans.at(j - i - 1)++;
      }
  }*/
  for (int i = 1; i < N; i++)
    cout << ans.at(i) << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, f, e) for (int(i) = (f); (i) < (e); (i)++)
#define repr(i, e, f) for (int(i) = (e - 1); (i) >= (f); (i)--)

const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

deque<int> G[2010];
int K[2010];

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

  rep(i, 1, N) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);

  // rep(i,1,N+1){
  //     cout << i << " : ";
  //     for(auto j : G[i]){
  //         cout << j << " ";
  //     }
  //     cout << endl;
  // }

  rep(i, 1, N + 1) {
    vector<int> dist(N + 1, -1);
    queue<int> que;

    dist[i] = 0;
    for (int j = i - 1; j = 0; j--) {
      dist[j] = INF;
    }
    que.push(i);

    while (!que.empty()) {
      int v = que.front(); // キューから先頭頂点を取り出す
      que.pop();

      // v から辿れる頂点をすべて調べる
      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue; // すでに発見済みの頂点は探索しない
        // 新たな白色頂点 nv について距離情報を更新してキューに追加する
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }

    rep(v, i, N + 1) { K[dist[v]] += 1; }
  }

  rep(k, 1, N) { cout << K[k] << endl; }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, f, e) for (int(i) = (f); (i) < (e); (i)++)
#define repr(i, e, f) for (int(i) = (e - 1); (i) >= (f); (i)--)

const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

deque<int> G[2010];
int K[2010];

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

  rep(i, 1, N) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);

  // rep(i,1,N+1){
  //     cout << i << " : ";
  //     for(auto j : G[i]){
  //         cout << j << " ";
  //     }
  //     cout << endl;
  // }

  rep(i, 1, N + 1) {
    vector<int> dist(N + 1, -1);
    queue<int> que;

    dist[i] = 0;
    for (int j = i - 1; j = 0; j--) {
      dist[j] = INF;
    }
    que.push(i);

    while (!que.empty()) {
      int v = que.front(); // キューから先頭頂点を取り出す
      que.pop();

      // v から辿れる頂点をすべて調べる
      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue; // すでに発見済みの頂点は探索しない
        // 新たな白色頂点 nv について距離情報を更新してキューに追加する
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }

    rep(k, 1, N) {
      rep(v, i, N + 1) {
        if (k == dist[v])
          K[k] += 1;
      }
    }
  }

  rep(k, 1, N) { cout << K[k] << endl; }

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

// BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 1005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }

int cnt[2005];

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

  int n, x, y;

  cin >> n >> x >> y;

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

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


Error: 0

Fixed submission:

// BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 1005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }

int cnt[1005];

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

  int n, x, y;

  cin >> n >> x >> y;

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

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