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

//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// #define __DBG__

void solve(void) {

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

  vector<int> M(N, 0);

  REP2(i, 1, N) {
    REP2(j, i + 1, N + 1) {
      int tmp = j - i;
      chmin(tmp, abs(X - i) + 1 + abs(j - Y));
      chmin(tmp, abs(Y - i) + 1 + abs(j - X));
      M[tmp]++;
    }
  }

  REP2(k, 1, N) { cout << M[k] << endl; }
  return;
}

#define TESTCASES 1

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  REP(i, TESTCASES) { solve(); }

  return 0;
}


Error: TLE

Fixed submission:

//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// #define __DBG__

void solve(void) {

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

  int M[N + 1][N + 1];

  REP2(i, 1, N) {
    REP2(j, i + 1, N + 1) {
      int tmp = j - i;
      chmin(tmp, abs(X - i) + 1 + abs(j - Y));
      chmin(tmp, abs(Y - i) + 1 + abs(j - X));
      M[i][j] = tmp;
    }
  }

  REP2(k, 1, N) {
    int ans = 0;
    REP2(i, 1, N) {
      REP2(j, i + 1, N + 1) {
        if (M[i][j] == k) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return;
}

#define TESTCASES 1

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  REP(i, TESTCASES) { solve(); }

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

#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, x) for (int i = 0; i < (x); i++)
#define all(x) (x).begin(), (x).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n, x, y;
  cin >> n >> x >> y;

  vi answers(n);

  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      answers.at(min(j - i, abs(j - y) + 1 + abs(i - x)))++;
    }
  }
  for (int k = 1; k < n; k++) {
    cout << answers.at(k) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, x) for (int i = 0; i < (x); i++)
#define all(x) (x).begin(), (x).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n, x, y;
  cin >> n >> x >> y;

  for (int k = 1; k < n; k++) {
    int ans = 0;
    for (int i = 1; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (k == min(j - i, abs(j - y) + 1 + abs(i - x))) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

/* --- END OF TEMPLATE --- */

map<int, int> m;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        // cout << i << " " << j << endl;
        int a = abs(i - j);                  // cout << a << endl;
        int b = abs(i - x) + 1 + abs(j - y); // cout << b << endl;
        int c = abs(i - y) + 1 + abs(j - x); // cout << c << endl;
        int r = min({a, b, c});
        m[r]++;
      }
    }
  }
  for (int k = 1; k <= n - 1; k++) {
    cout << m[k] / 2 << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int k = 1; k <= n - 1; k++) {
    int cc = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i != j) {
          // cout << i << " " << j << endl;
          int a = abs(i - j);                  // cout << a << endl;
          int b = abs(i - x) + 1 + abs(j - y); // cout << b << endl;
          int c = abs(i - y) + 1 + abs(j - x); // cout << c << endl;
          int r = min({a, b, c});
          if (r == k)
            cc++;
        }
      }
    }
    cout << cc / 2 << "\\n";
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <deque>
#include <iostream>
#include <vector>

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

using namespace std;

void init_graph(int nx, int ny, vector<vector<int>> &graph) {
  auto n = graph.size();

  for (auto f = 0; f < nx; ++f) {
    for (auto t = f + 1; t <= nx; ++t) {
      auto diff = t - f;
      graph[f][t] = diff;
    }
  }

  auto ring_len = ny - nx + 1;
  auto xymax = ring_len / 2;
  for (auto f = nx; f < ny; ++f) {
    for (auto t = f + 1; t <= ny; ++t) {
      auto diff = t - f;
      graph[f][t] = (diff <= xymax) ? diff : (ring_len - diff);
    }
  }

  for (auto f = ny; f < n - 1; ++f) {
    for (auto t = f + 1; t <= n - 1; ++t) {
      auto diff = t - f;
      graph[f][t] = diff;
    }
  }
}

int min_path(int i, int j, int nx, int ny, vector<vector<int>> &graph) {
  if (i <= nx && nx <= j && j <= ny) {
    return graph[i][nx] + graph[nx][j];
  } else if (nx <= i && i <= ny && ny <= j) {
    return graph[i][ny] + graph[ny][j];
  } else if (i <= nx && ny <= j) {
    return graph[i][nx] + graph[nx][ny] + graph[ny][j];
  } else {
    return graph[i][j];
  }
}

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

  auto graph = vector<vector<int>>(n, vector<int>(n, 0));
  auto nx = x - 1;
  auto ny = y - 1;
  init_graph(nx, ny, graph);

  auto vec = vector<int>(graph.size() - 1);
  rep(i, n - 1) {
    for (auto j = i + 1; j < n; ++j) {
      auto len = min_path(i, j, nx, ny, graph);
      vec[len - 1]++;
    }
  }

  for (auto t : vec) {
    cout << t << endl;
  }
}


Error: TLE

Fixed submission:

#include <deque>
#include <iostream>
#include <vector>

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

using namespace std;

void set_edge(int x, int y, vector<vector<int>> &graph) {
  graph[x][y] = 1;
  graph[y][x] = 1;
}

int min_path(int i, int j, const vector<vector<int>> &graph) {
  // i < j
  auto n = graph.size();

  auto searched = vector<bool>(n, false);
  auto queue = deque<int>();
  searched[i] = true;
  queue.push_back(i);

  auto count = 0;
  while (true) {
    auto queue_size = queue.size();
    rep(_, queue_size) {
      auto x = queue.front();
      queue.pop_front();
      searched[x] = true;
      if (x == j) {
        return count;
      } else {
        rep(next, n) {
          auto y = graph[x][next];
          if (y > 0 && !searched[next]) {
            queue.push_back(next);
            searched[next] = true;
          }
        }
      }
    }

    if (queue_size > 0) {
      count++;
    }
  }
}

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

  auto graph = vector<vector<int>>(n, vector<int>(n, 0));
  rep(i, n - 1) { set_edge(i, i + 1, graph); }
  set_edge(x - 1, y - 1, graph);

  auto vec = vector<int>(n - 1, 0);
  rep(i, n - 1) {
    for (auto j = i + 1; j < n; ++j) {
      auto ijmin = min_path(i, j, graph);
      vec[ijmin - 1] += 1;
    }
  }

  for (auto t : vec) {
    cout << t << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using LL = long long;
const int N = 2005;

int d[N];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  --x;
  --y;

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

  for (int r = 1; r < n; ++r)
    cout << d[r] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using LL = long long;
const int N = 2005;
int e[N][N];
int cnt[N];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);

  memset(e, 0x3f, sizeof e);
  for (int i = 1; i <= n - 1; ++i) {
    e[i][i + 1] = e[i + 1][i] = 1;
  }
  e[x][y] = e[y][x] = 1;

  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        if (e[i][j] > e[i][k] + e[k][j])
          e[i][j] = e[i][k] + e[k][j];

  for (int i = 2; i <= n; ++i)
    for (int j = 1; j < i; ++j) {
      int d = e[j][i];
      ++cnt[d];
    }

  for (int i = 1; i <= n - 1; ++i) {
    printf("%d\\n", cnt[i]);
  }

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

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

V<int> ans;
int n, x, y, cnt;
int main() {
  cin >> n >> x >> y;

  ans.resize(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j)
        continue;
      int a = abs(x - i) + abs(j - y) + 1;
      int b = abs(y - i) + abs(j - x) + 1;
      int d = min({abs(j - i), a, b});
      ans[d]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] / 2 << endl;
  }
}


Error: -11

Fixed submission:

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

V<int> ans;
int n, x, y, cnt;
int main() {
  cin >> n >> x >> y;

  ans.resize(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j)
        continue;
      int a = abs(x - i) + abs(j - y) + 1;
      int b = abs(y - i) + abs(j - x) + 1;
      int d = min({j - i, a, b});
      ans[d]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

const int MAXN = 2e3 + 5;

int n, x, y;
int dist[MAXN][MAXN], ans[MAXN];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      dist[j][i] = dist[i][j] = j - i;
    }
  }
  dist[x][y] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      dist[i][j] =
          std::min(dist[i][j], std::min(dist[i][x] + dist[x][y] + dist[y][j],
                                        dist[i][y] + dist[y][x] + dist[x][j]));
      ++ans[dist[i][j]];
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", ans[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

const int MAXN = 1e3 + 5;

int n, x, y;
int dist[MAXN][MAXN], ans[MAXN];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      dist[j][i] = dist[i][j] = j - i;
    }
  }
  dist[x][y] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      dist[i][j] =
          std::min(dist[i][j], std::min(dist[i][x] + dist[x][y] + dist[y][j],
                                        dist[i][y] + dist[y][x] + dist[x][j]));
      ++ans[dist[i][j]];
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", ans[i]);
  }
  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 n, x, y;
  cin >> n >> x >> y;

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

  for (int k = 1; k < n; k++)
    cout << p[k] << endl;
}


Error: TLE

Fixed submission:

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

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

  for (int k = 1; k < n; k++) {
    ll ans = 0;
    for (int i = 1; i < n; i++) {
      for (int j = i; j < n + 1; j++) {
        if (min(j - i, abs(i - x) + 1 + abs(j - y)) == k) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define alpha_size 26
const int maxn = 1e3 + 10;
const int INF = 1 << 29;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, x, y;
  cin >> n >> x >> y;
  int g[n + 1][n + 1];
  --x, --y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        g[i][j] = 0;
      else
        g[i][j] = INF;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      g[i][j] = abs(i - j);
  g[x][y] = 1;
  g[y][x] = 1;
  map<int, int> m;
  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[y][j]);
      g[i][j] = min(g[i][j], g[i][y] + 1 + g[x][j]);
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      m[g[i][j]]++;
  for (int i = 1; i <= n - 1; i++)
    cout << m[i] / 2 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define alpha_size 26
const int maxn = 1e3 + 10;
const int INF = 1 << 29;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, x, y;
  cin >> n >> x >> y;
  int g[n + 1][n + 1];
  --x, --y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        g[i][j] = 0;
      else
        g[i][j] = INF;
    }
  }
  for (int i = 0; i + 1 < n; i++) {
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  g[x][y] = 1;
  g[y][x] = 1;
  map<int, int> m;
  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]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (g[i][j] >= 1 && g[i][j] <= n - 1)
        m[g[i][j]]++;
    }
  }

  for (int i = 1; i <= n - 1; i++)
    cout << m[i] / 2 << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[2020][2020], n, x, y, cnt[2020];
int main() {
  memset(arr, 1, sizeof(arr));
  cin >> n >> x >> y;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j)
      arr[i][j] = arr[j][i] = j - i;
  }
  arr[x][y] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (arr[i][x] + arr[x][j] < arr[i][j])
        arr[i][j] = arr[j][i] = arr[i][x] + arr[x][j];
      if (arr[i][y] + arr[y][j] < arr[i][j])
        arr[i][j] = arr[j][i] = arr[i][y] + arr[y][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j)
      cnt[arr[i][j]]++;
  }
  for (int i = 1; i <= n - 1; ++i)
    printf("%lld\\n", cnt[i]);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[2020][2020], n, x, y, cnt[2020];
int main() {
  memset(arr, 1, sizeof(arr));
  cin >> n >> x >> y;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j)
      arr[i][j] = arr[j][i] = j - i;
  }
  arr[x][y] = 1;
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j)
        if (arr[i][k] + arr[k][j] < arr[i][j])
          arr[i][j] = arr[i][k] + arr[k][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j)
      cnt[arr[i][j]]++;
  }
  for (int i = 1; i <= n - 1; ++i)
    printf("%lld\\n", cnt[i]);
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(), x.end()
#define debug(x) cout << x;

struct Edge {
  int v;
  int w;
  int next;
} edge[1000005];

priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    q;
int head[200005];
int cnt;
bool vis[200005];
unsigned F[200005];
int cot[200005];

void add(int u, int v, int w) {
  cnt++;
  edge[cnt].v = v;
  edge[cnt].w = w;
  edge[cnt].next = head[u];
  head[u] = cnt;
}

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

  for (int i = 1; i < n; i++) {
    add(i, i + 1, 1);
    add(i + 1, i, 1);
  }

  add(x, y, 1);
  add(y, x, 1);

  for (int i = 1; i < n; i++) {
    for (int i = 1; i <= n; i++)
      F[i] = INT_MAX; // 初始化
    memset(vis, 0, sizeof(vis));
    F[i] = 0;
    q.push(make_pair(0, i));
    while (!q.empty()) {
      int x = q.top().second;
      q.pop(); // 在判断之前先pop
      if (vis[x])
        continue;
      vis[x] = 1;

      for (int j = head[x]; j; j = edge[j].next) {
        if (F[edge[j].v] > F[x] + edge[j].w) {
          F[edge[j].v] = F[x] + edge[j].w;
          q.push(make_pair(F[edge[j].v], edge[j].v));
        }
      }
    }

    for (int j = i + 1; j <= n; j++)
      if (F[j] != INT_MAX)
        cot[F[j]]++;
  }

  for (int i = 1; i < n; i++)
    cout << cot[i] << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#pragma optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(), x.end()
#define debug(x) cout << x;

unsigned f[2005][2005];
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 = 1; j <= n; j++) {
      if (i == j)
        f[i][j] = 0;
      else
        f[i][j] = INT_MAX;
    }

  for (int i = 1; i < n; i++) {
    f[i][i + 1] = 1;
    f[i + 1][i] = 1;
  }

  f[x][y] = 1;
  f[y][x] = 1;

  for (int k = 1; k <= n; k++) //  注意顺序小心翻车
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        f[i][j] = min(f[i][j], f[i][k] + f[k][j]);

  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      if (f[i][j] != 0 && f[i][j] != INT_MAX)
        cnt[f[i][j]]++;
    }

  for (int i = 1; i < n; i++)
    cout << cnt[i] << '\\n';

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define forr(i, st, en) for (int i = st; i < en; i++)
#define all(v) (v).begin(), (v).end()
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define int long long

int x, y, n;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define forr(i, st, en) for (int i = st; i < en; i++)
#define all(v) (v).begin(), (v).end()
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define int long long

int x, y, n;

int line(int i, int j) {
  return min(abs(j - i),
             min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)));
}
int32_t main() {
  fast;
  cin >> n >> x >> y;
  for (int k = 1; k <= n - 1; k++) {
    int answer = 0;
    for (int i = 1; i < n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (line(i, j) == k) {
          answer++;
        }
      }
    }
    cout << answer << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int count[n + 1];
  memset(count, 0, sizeof(count));
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      count[max({abs(j - i), abs(abs(i - x) + 1 + abs(j - y))})]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << count[i] << " ";
  }
  return 0;
}