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

#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
const int INF = 1001001001;

int n, x, y;

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

  vector<vector<int>> d(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = i > j ? i - j : j - i;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = x + 1; j < n; j++) {
      if (i >= j)
        continue;

      int mid;
      if (j - x > y - j) {
        mid = d[j][y];
      } else {
        mid = d[x][j];
      }

      d[i][j] = min(d[i][j], d[i][x] + 1 + mid);
    }
  }

  // for (int i=0; i<n; i++) {
  //     for (int j=0; j<n; j++) {
  //         cout << d[i][j] << ' ';
  //     }
  //     cout << endl;
  // }

  vector<int> cnt(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      cnt[d[i][j]]++;
    }
  }

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


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
const int INF = 1001001001;

int n, x, y;

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

  int d[n][n];
  fill((int *)d, (int *)(d + n), INF);

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

    if (i == n - 1)
      continue;
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }

  d[x][y] = 1;
  d[y][x] = 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, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cnt[d[i][j]]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << cnt[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;

int main() {
  int INF = 1e8;
  int N;
  int X, Y;
  cin >> N;
  cin >> X >> Y;
  vector<vector<int>> G(N, vector<int>(N, INF));

  for (int i = 0; i < N; i++) {
    G[i][i] = 0;
  }

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

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

  map<int, int> m{};
  for (int i = 1; i < N; ++i) {
    m[i] = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      m[G[i][j]]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    cout << m[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int INF = 1e8;
  int N;
  int X, Y;
  cin >> N;
  cin >> X >> Y;
  vector<vector<int>> G(N, vector<int>(N, INF));

  for (int i = 0; i < N; i++) {
    G[i][i] = 0;
  }

  for (int i = 0; i < N - 1; i++) {
    G[i][i + 1] = min(G[i][i + 1], 1);
    G[i + 1][i] = min(G[i + 1][i], 1);
  }
  G[X - 1][Y - 1] = min(G[X - 1][Y - 1], 1);
  G[Y - 1][X - 1] = min(G[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++) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  map<int, int> m{};
  for (int i = 1; i < N; ++i) {
    m[i] = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      m[G[i][j]]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    cout << m[i] << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
  return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
  return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
  return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
  return (sum_3(j) - sum_3(i - 1) + M) % M;
}

struct MyHash {
  size_t operator()(const pair<int, int> &x) const {
    return x.first + x.second;
  }
};

void solve() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(2 * n + 5, 0);

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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifdef D_LOCAL
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif

  solve();

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
  return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
  return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
  return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
  return (sum_3(j) - sum_3(i - 1) + M) % M;
}

struct MyHash {
  size_t operator()(const pair<int, int> &x) const {
    return x.first + x.second;
  }
};

void solve() {
  int n, x, y;
  cin >> n >> x >> y;
  unordered_map<pair<int, int>, int, MyHash> m;

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

  vector<int> ans(n + 1, 0);
  for (auto &i : m) {
    ans[i.second]++;
  }

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifdef D_LOCAL
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif

  solve();

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

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

#define int long long
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;
}
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

vector<vector<int>> g;
vector<int> dist;
int n, x, y;

signed main() {
  cin >> n >> x >> y;
  vector<int> a(n, 0);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist;
      dist = min(j - i, abs(x - i) + 1 + abs(y - j));
      a[dist]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << a[i] << endl;
  }
}

Error: TLE

Fixed submission:

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

#define int long long
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;
}
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

vector<vector<int>> g;
vector<int> dist;
int n, x, y;

void bfs(int s, int limit) {
  queue<int> que;
  rep(i, n) dist[i] = -1;
  dist[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : g[v]) {
      if (dist[nv] == -1) {
        if (dist[nv] > limit)
          continue;
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }
  }
}

signed main() {
  cin >> n >> x >> y;
  g.resize(n);
  dist.resize(n);
  rep(i, n - 1) {
    g[i].PB(i + 1);
    g[i + 1].PB(i);
  }
  g[x - 1].PB(y - 1);
  g[y - 1].PB(x - 1);

  for (int i = 1; i < n; i++) { // 距離
    int res = 0;
    rep(j, n) { // 始点
      bfs(j, i);
      rep(k, n) {
        if (dist[k] == i)
          res++;
      }
    }
    cout << res / 2 << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(int argc, char *argv[]) {
  int N, X, Y, i, j, k;
  cin >> N >> X >> Y;
  vector<vector<int>> D(N, vector<int>(N));
  int INF = 100000;
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (i == j) {
        D[i][j] = 0;
      } else {
        D[i][j] = INF;
      }
    }
  }
  for (i = 0; i < N - 1; i++) {
    D[i][i + 1] = 1;
    D[i + 1][i] = 1;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (i == j) {
        D[i][j] = 0;
      } else {
        if (j > i) {
          D[i][j] = j - i;
        } else {
          D[i][j] = i - j;
        }
      }
    }
  }
  D[X - 1][Y - 1] = 1;
  D[Y - 1][X - 1] = 1;
  for (j = 0; j < N; j++) {   // 開始頂点
    for (k = 0; k < N; k++) { // 終端
      D[j][k] = min(D[j][k], D[j][X - 1] + D[X - 1][k]);
    }
  }
  for (j = 0; j < N; j++) {   // 開始頂点
    for (k = 0; k < N; k++) { // 終端
      D[j][k] = min(D[j][k], D[j][Y - 1] + D[Y - 1][k]);
    }
  }
  /*
  for (i = 0; i < N; i++){      // 経由する頂点
          for (j = 0; j < N; j++){    // 開始頂点
                  for (k = 0; k < N; k++){  // 終端
                          D[j][k] = min(D[j][k], D[j][i] + D[i][k]);
                  }
          }
  }*/
  vector<int> Num(N + 1, 0);
  for (i = 0; i < N; i++) {   // 経由する頂点
    for (j = 0; j < N; j++) { // 開始頂点
      Num[D[i][j]]++;
    }
  }
  for (k = 1; k < N; k++) {
    cout << Num[k] / 2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(int argc, char *argv[]) {
  int N, X, Y, i, j, k;
  cin >> N >> X >> Y;
  vector<vector<int>> D(N, vector<int>(N));
  int INF = 100000;
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (i == j) {
        D[i][j] = 0;
      } else {
        D[i][j] = INF;
      }
    }
  }
  D[X - 1][Y - 1] = 1;
  D[Y - 1][X - 1] = 1;
  for (i = 0; i < N - 1; i++) {
    D[i][i + 1] = 1;
    D[i + 1][i] = 1;
  }
  for (i = 0; i < N; i++) {     // 経由する頂点
    for (j = 0; j < N; j++) {   // 開始頂点
      for (k = 0; k < N; k++) { // 終端
        D[j][k] = min(D[j][k], D[j][i] + D[i][k]);
      }
    }
  }
  vector<int> Num(N + 1, 0);
  for (i = 0; i < N; i++) {   // 経由する頂点
    for (j = 0; j < N; j++) { // 開始頂点
      Num[D[i][j]]++;
    }
  }
  for (k = 1; k < N; k++) {
    cout << Num[k] / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <string>
typedef long long ll;

#define all(x) (x).begin(), (x).end()
#define puts(x) cout << x << endl;
#define rep(i, m, n) for (ll i = m; i < n; i++)
#define fore(i, a) for (auto i : a)

using namespace std;
ll n, a, b;
ll d[20005]; // leftからrightまでの距離
int main() {
  cin >> n >> a >> b;
  rep(i, 0, 2005) { d[i] = 0; }
  rep(i, 1, n + 1) {
    rep(j, 1, n + 1) {
      ll k = abs(i - j);
      k = min(k, abs(a - i) + abs(b - j) + 1);
      k = min(k, abs(b - i) + abs(a - j) + 1);
      d[k] += 1;
    }
  }
  for (ll i = 1; i < n; i++) {
    puts(d[i] / 2);
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <string>

#define all(x) (x).begin(), (x).end()
#define puts(x) cout << x << endl;
#define rep(i, m, n) for (ll i = m; i < n; i++)
#define fore(i, a) for (auto i : a)
#define ll long long
using namespace std;
ll n, a, b;
int d[2005]; // leftからrightまでの距離
int main() {
  cin >> n >> a >> b;
  rep(i, 0, 2005) { d[i] = 0; }
  rep(i, 1, n + 1) {
    rep(j, 1, n + 1) {
      ll k = i - j;
      k = min(k, abs(a - i) + abs(b - j) + 1);
      k = min(k, abs(b - i) + abs(a - j) + 1);
      d[k]++;
    }
  }
  rep(i, 1, n) { puts(d[i]); }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
vector<int> v[2005];
int cnt[2005] = {0};
void Addedge(int from, int to) {
  v[from].push_back(to);
  v[to].push_back(from);
}
bool vis[2005];

void bfs(int now, int dis) {
  queue<int> q;
  int k = 0;

  q.push(now);
  vis[now] = true;

  while (k < dis) {
    vector<int> vv;
    k++;
    while (!q.empty()) {
      int x = q.front();
      q.pop();

      for (int i = 0; i < v[x].size(); i++) {
        int t = v[x][i];

        if (vis[t])
          continue;
        vis[t] = true;
        // cout<<time<<' '<<x<<' '<<t<<endl;
        vv.push_back(t);
      }
    }
    for (int i = 0; i < vv.size(); i++)
      q.push(vv[i]);
    cnt[k] += q.size();
  }
}

int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);

  int n, x, y;

  cin >> n >> x >> y;
  Addedge(x, y);
  for (int i = 1; i <= n - 1; i++)
    Addedge(i, i + 1);

  for (int j = 1; j <= n; j++) {
    for (int k = 1; k <= 2005; k++)
      vis[k] = false;

    bfs(j, n);
  }
  for (int i = 1; i <= n - 1; i++)
    cout << cnt[i] / 2 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> v[2005];
void Addedge(int from, int to) {
  v[from].push_back(to);
  v[to].push_back(from);
}
bool vis[2005];

int bfs(int now, int dis) {
  queue<int> q;
  int ans = 0, k = 0;

  q.push(now);
  vis[now] = true;

  while (k < dis) {
    vector<int> vv;
    k++;
    while (!q.empty()) {
      int x = q.front();
      q.pop();

      for (int i = 0; i < v[x].size(); i++) {
        int t = v[x][i];

        if (vis[t])
          continue;
        vis[t] = true;
        // cout<<time<<' '<<x<<' '<<t<<endl;

        if (k == dis)
          ans++;
        else
          vv.push_back(t);
      }
    }
    for (int i = 0; i < vv.size(); i++)
      q.push(vv[i]);
  }

  return ans;
}

int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);

  int n, x, y;

  cin >> n >> x >> y;
  Addedge(x, y);
  for (int i = 1; i <= n - 1; i++)
    Addedge(i, i + 1);
  for (int i = 1; i <= n - 1; i++) {
    int sum = 0;
    for (int j = 0; j < i; j++)
      vis[j] = true;
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= 2005; k++)
        vis[k] = false;
      sum += bfs(j, i);
    }
    cout << sum / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\\n";
  else
    cout << a << "\\n";
}
// end of template

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<int> ans(N);
  rep(i, N) rep(j, i + 1, N) {
    int a = j - i;
    int b = abs(i - X) + 1 + abs(Y - j);
    ans[min(a, b)]++;
  }
  rep(i, 1, N) { output(ans[i]); }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\\n";
  else
    cout << a << "\\n";
}
// end of template

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> A(N, vector<int>(N, 100000));
  rep(i, N - 1) {
    A[i][i] = 0;
    A[i][i + 1] = 1;
    A[i + 1][i] = 1;
  }
  A[X - 1][Y - 1] = 1;
  A[Y - 1][X - 1] = 1;
  rep(k, N) rep(i, N) rep(j, N) { A[i][j] = min(A[i][j], A[i][k] + A[k][j]); }
  vector<int> ans(N + 1);
  rep(i, N) rep(j, i + 1, N) { ans[A[i][j]]++; }
  rep(i, 1, N) { output(ans[i]); }

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using namespace std;

int main() {
  int n, x, y;
  long long dist;

  cin >> n >> x >> y;

  long long a[2000] = {0};

  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (i <= x && j >= y) {
        dist = x - i + j - y + 1;
      } else if (i > x && j >= y) {
        dist = min(j - i, i - x + 1 + j - y);
      } else if (i <= x && j < y) {
        dist = min(j - i, y - j + x - i + 1);
      } else {
        dist = min(j - i, i - x + y - j + 1);
      }
      a[dist]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << a[i] << endl;
  }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>

using namespace std;

const int NUMBER = 2100;

int n, x, y;

int abs(int p, int q) {
  if (p < q) {
    return q - p;
  } else {
    return p - q;
  }
}

int reach(vector<vector<bool>> &check, int k, int p) {
  int c = 0;

  if (check.at(p).at(p + k) == false && p + k <= n) {
    check.at(p).at(p + k) = true;
    c++;
  }
  if (p - k > 0) {
    if (check.at(p - k).at(p) == false) {
      check.at(p - k).at(p) = true;
      c++;
    }
  }
  if (abs(x, p) >= k && abs(y, p) >= k) {
    return c;
  } else {
    if (check.at(p).at(y - x + k + p - 1) == false && y - x + k + p - 1 <= n) {
      check.at(p).at(y - x + k + p - 1) = true;
      c++;
    }
    if (y + x - p - k + 1 > p && y + x - p - k + 1 <= n) {
      if (check.at(p).at(y + x - p - k - 1) == false) {
        check.at(p).at(y + x - p - k - 1) = true;
        c++;
      }
    }
    return c;
  }
}

int main() {
  vector<vector<bool>> check(NUMBER, vector<bool>(NUMBER, false));
  cin >> n >> x >> y;
  for (int k = 1; k <= n - 1; k++) {
    int c = 0;
    for (int p = 1; p <= n - 1; p++) {
      c += reach(check, k, p);
    }
    cout << c << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define D(x) cout << "D: " << #x << '=' << x << endl;
#define R(x, l)                                                                \\
  cout << "R: Array " << #x << endl;                                           \\
  for (int i = 0; i < l; i++)                                                  \\
    cout << ' ' << i << ':' << *(x + i) << endl;
#define pb push_back
using namespace std;

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

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


Error: TLE

Fixed submission:

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

int n, x, y, sum;
int ans[2005];
bool vis[2005];
vector<int> v[2005];

int dfs(int a, int b, int M) {
  if (vis[a])
    return 0;
  vis[a] = true;
  for (int i = 0; i < v[a].size(); i++) {
    if (v[a][i] == b) {
      sum = min(sum, M);
      vis[a] = false;
      return 0;
    } else
      dfs(v[a][i], b, M + 1);
  }
  vis[a] = false;
  return 0;
}

int main() {
  cin >> n >> x >> y;
  for (int i = 0; i < n - 1; i++) {
    v[i].push_back(i + 1);
    v[i + 1].push_back(i);
  }
  v[x - 1].push_back(y - 1);
  v[y - 1].push_back(x - 1);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      memset(vis, 0, sizeof(vis));
      sum = 2005;
      dfs(i, j, 1);
      ans[sum]++;
    }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  map<int, int> m;
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j) {
      ++m[min(
          {j - i, abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)})];
    }
  for (int i = 1; i < n; ++i)
    cout << m[i] << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y;
  const int inf = 1e5;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<vector<int>> G(n, vector<int>(n, inf));
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j)
      G[i][j] = G[j][i] = j - i;
  G[y][x] = G[x][y] = 1;
  bool ref = true;
  while (ref) {
    ref = false;
    for (int i = 0; i < n - 1; ++i)
      for (int j = i + 1; j < n; ++j)
        for (int k = 0; k < n; ++k)
          if (G[i][j] > G[i][k] + G[k][j])
            ref = true, G[i][j] = G[j][i] = G[i][k] + G[k][j];
  }
  map<int, int> m;
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j)
      ++m[G[i][j]];
  for (int k = 1; k < n; ++k)
    cout << m[k] << "\\n";
}