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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> distances(n);
  rep(i, n) distances[i] = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      int d = min(j - i, abs(x - i) + 1 + abs(y - j));
      distances[d]++;
    }
  }

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

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> distances(n);
  rep(i, n) distances[i] = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 1; j <= n; j++) {
      int d = min(j - i, abs(x - i) + 1 + abs(y - j));
      distances[d]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << distances[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int n, x, y;
int d[2005] = {};
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      // cout <<i<<' '<<j<<endl;
      if (i <= x && j >= y)
        d[x - i + j - y + 1]++;
      else if (j <= x || i >= y)
        d[j - i]++;
      else if (i <= x && j >= x && j <= y)
        d[min(j - x, y - j + 1) + x - i]++;
      else if (i >= x && i <= y && j >= y)
        d[min(i - x + 1, y - i) + j - y]++;
      else if (i >= x && j <= y)
        d[min(j - i, i - x + y - j + 1)]++;
    }
  for (int i = 1; i <= n - 1; i++)
    cout << d[i] << '\\n';
  // cout <<endl;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int n, x, y;
int d[2001] = {};
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      if (i <= x && j >= y)
        d[x - i + j - y + 1]++;
      else if ((i <= x && j <= x) || (i >= y && j >= y))
        d[j - i]++;
      else if (i <= x && j >= x && j <= y)
        d[min(j - x, y - j + 1) + x - i]++;
      else if (i >= x && i <= y && j >= y)
        d[min(x - i + 1, y - x) + j - y]++;
    }
  for (int i = 1; i <= n - 1; i++)
    cout << d[i] << '\\n';
  cout << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  // your code goes here
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> g(n, vector<int>(n, 1e4));
  // 	for(int i=0;i<n-1;i++)
  // 	{
  // 	    g[i][i+1]=1;
  // 	    g[i+1][i]=1;
  // 	}

  for (int i = 0; i < n; i++) {
    g[i][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      g[i][j] = g[i][j - 1] + 1;
      g[j][i] = g[i][j];
    }
  }
  g[x - 1][y - 1] = 1;
  g[y - 1][x - 1] = 1;
  x--;
  y--;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      g[i][j] = min(g[i][j], g[i][x] + g[x][y] + g[y][j]);
      g[j][i] = g[i][j];
    }
  }
  // 	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]);
  // 	        }
  // 	    }
  // 	}
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++)
      mp[g[i][j]]++;
  }
  for (int i = 1; i < n; i++)
    cout << mp[i] << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  // your code goes here
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> g(n, vector<int>(n, 1e4));
  for (int i = 0; i < n - 1; i++) {
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  g[x - 1][y - 1] = 1;
  g[y - 1][x - 1] = 1;
  for (int i = 0; i < n; i++) {
    g[i][i] = 0;
  }
  // 	for(int i=0;i<n;i++)
  // 	{
  // 	    for(int j=0;j<n;j++)
  // 	    cout<<g[i][j]<<" ";
  // 	}
  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]);
      }
    }
  }
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++)
      mp[g[i][j]]++;
  }
  for (int i = 1; i < n; i++)
    cout << mp[i] << "\\n";
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int ara[2100], path[2004], vis[2003], ck[2001][2001];
vector<int> adj[2009];

void bfs(int src, int dst) {
  queue<int> q;
  int fr, sc, tr = 0, sz;
  path[src] = 0;
  vis[src] = 1;

  q.push(src);

  while (!q.empty()) {
    fr = q.front();
    q.pop();
    sz = adj[fr].size();
    for (int i = 0; i < sz; i++) {
      sc = adj[fr][i];
      if (vis[sc] == 0) {

        path[sc] = path[fr] +
                   1; // cout<<sc<<"   "<<src<<"   "<<dst<<" "<<path[sc]<<endl;

        if (ck[src][sc] == 0 && sc > src) {
          ara[path[sc]]++;
          ck[src][sc] == 77;
        }

        q.push(sc);
        vis[sc] = 1;
      }
    }

    if (tr == 1) {
      break;
    }
  }

  while (!q.empty()) {
    q.pop();
  }
}

int main() {

  int n, x, y, i, j, k;

  scanf("%d %d %d", &n, &x, &y);
  for (i = 1; i < n; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }

  adj[x].push_back(y);
  adj[y].push_back(x);

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

    bfs(i, n);
    memset(vis, 0, sizeof vis);
  }

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

  return 0;
}


Error: TLE

Fixed submission:

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

int ara[2100], path[2004], vis[2003];
vector<int> adj[2009];

void bfs(int src, int dst) {
  queue<int> q;
  int fr, sc, tr = 0, sz;
  path[src] = 0;
  vis[src] = 1;

  q.push(src);

  while (!q.empty()) {
    fr = q.front();
    q.pop();
    sz = adj[fr].size();
    for (int i = 0; i < sz; i++) {
      sc = adj[fr][i];
      if (vis[sc] == 0) {

        path[sc] = path[fr] +
                   1; // cout<<sc<<"   "<<src<<"   "<<dst<<" "<<path[sc]<<endl;

        if (sc == dst) {
          ara[path[sc]]++;
          tr = 1;
          break;
        }

        q.push(sc);
        vis[sc] = 1;
      }
    }

    if (tr == 1) {
      break;
    }
  }

  while (!q.empty()) {
    q.pop();
  }
}

int main() {

  int n, x, y, i, j, k;
  scanf("%d %d %d", &n, &x, &y);
  ara[1] = n - 1;
  for (i = 1; i < n; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }

  adj[x].push_back(y);
  adj[y].push_back(x);

  for (i = 1; i <= n; i++) {
    for (j = i + 2; j <= n; j++) {

      bfs(i, j);
      memset(vis, 0, sizeof vis);
    }
  }

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

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

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

int main() {
  int N, X, Y, i, j, ans, dist, list[2001] = {0};

  // stdinから入力受付
  cin >> N >> X >> Y;
  X--;
  Y--; // 0からの値に変換

  // メイン処理
  for (i = 0; i < N - 1; i++) {   // 始点
    for (j = i + 1; j < N; j++) { // 目的地
      // 道を必ず通る場合
      if (abs(i - X) < abs(i - Y))
        dist = abs(i - X) + 1 + abs(j - Y);
      else
        dist = abs(i - Y) + 1 + abs(j - X);
      // 直接行く場合と比較、短いほうをdistに入れる
      if (j - i < dist)
        dist = j - i;
      // list配列のdist番目を1増やす
      list[dist]++;
    }
  }

  // 答えをstdoutに出力
  for (i = 1; i < N; i++)
    cout << list[i] << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y, i, j, ans, dist, list[2001] = {0};

  // stdinから入力受付
  cin >> N >> X >> Y;
  X--;
  Y--; // 0からの値に変換

  // メイン処理
  for (i = 0; i < N - 1; i++) {   // 始点
    for (j = i + 1; j < N; j++) { // 目的地
      // 道を必ず通る場合
      if (abs(i - X) < abs(i - Y))
        dist = abs(i - X) + 1 + abs(j - Y);
      else
        dist = abs(i - Y) + 1 + abs(j - X);
      // 直接行く場合と比較、短いほうをdistに入れる
      if (j - i < dist)
        dist = j - i;
      // list配列のdist番目を1増やす
      list[dist]++;
      cerr << i << ' ' << j << ' ' << dist << endl; // デバッグ出力(stderr)
    }
  }

  // 答えをstdoutに出力
  for (i = 1; i < N; i++)
    cout << list[i] << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// 深さ優先探索
vector<bool> seen;
vector<vector<int>> G;
int a[2001][2001];
vector<int> ans(3000, 0);

void bfs(int top) {
  queue<int> q;
  q.push(top);
  seen[top] = true;

  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto next_v : G[v]) {
      if (seen[next_v])
        continue;
      q.push(next_v);
      seen[next_v] = true;
      a[top][next_v] = a[top][v] + 1;
      if (top < next_v)
        ans[a[top][next_v]]++;
    }
  }
}

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

  G.resize(N);

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

  for (int i = 0; i < N; i++) {
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    bfs(i);
  }

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


Error: TLE

Fixed submission:

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

// 深さ優先探索
vector<bool> seen;
vector<vector<int>> G;
int a[2001][2001];

void bfs(int top) {
  queue<int> q;
  q.push(top);
  seen[top] = true;

  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto next_v : G[v]) {
      if (seen[next_v])
        continue;
      q.push(next_v);
      seen[next_v] = true;
      a[top][next_v] = a[top][v] + 1;
    }
  }
}

int main() {
  int N, X, Y, ans = 0;
  cin >> N >> X >> Y;
  X--;
  Y--;

  G.resize(N);

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

  for (int i = 0; i < N; i++) {
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    bfs(i);
  }

  for (int i = 1; i < N; i++) {
    ans = 0;
    for (int j = 0; j < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (a[j][k] == i)
          ans++;
      }
    }
    cout << ans << endl;
  }
}
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>;
const int INF = 100000000;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int big = 1e5;

int main() {
  long long int n, x, y;
  cin >> n >> x >> y;
  x--, y--;
  vector<vector<long long int>> dist(n, vector<long long int>(n, big));
  for (int i = 0; i < n; i++) {
    dist[i][i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    dist[i][i + 1] = 1;
    dist[i + 1][i] = 1;
  }
  dist[x][y] = 1;
  dist[y][x] = 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] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  vector<long long int> count(n + 5, 0);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      count[dist[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << count[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int n, x, y, dist[N], ans[N];
vector<int> gg[N];
bool used[N];
queue<int> q;
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> x >> y;
  for (int i = 1; i <= n - 1; i++) {
    gg[i].push_back(i + 1);
    gg[i + 1].push_back(i);
  }
  gg[x].push_back(y);
  gg[y].push_back(x);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      used[j] = false;
      dist[j] = 0;
    }
    q.push(i);
    used[i] = true;
    dist[i] = 0;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int j = 0; j < gg[cur].size(); j++) {
        int child = gg[cur][j];
        if (used[child] == false) {
          q.push(child);
          used[child] = true;
          dist[child] = dist[cur] + 1;
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      ans[dist[j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    ans[i] = ans[i] / 2;
    cout << ans[i] << '\\n';
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, x, y, dist[N], ans[N];
vector<int> gg[N];
bool used[N];
queue<int> q;
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> x >> y;
  for (int i = 1; i <= n - 1; i++) {
    gg[i].push_back(i + 1);
    gg[i + 1].push_back(i);
  }
  gg[x].push_back(y);
  gg[y].push_back(x);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      used[j] = false;
      dist[j] = 0;
    }
    q.push(i);
    used[i] = true;
    dist[i] = 0;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int j = 0; j < gg[cur].size(); j++) {
        int child = gg[cur][j];
        if (used[child] == false) {
          q.push(child);
          used[child] = true;
          dist[child] = dist[cur] + 1;
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      ans[dist[j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    ans[i] = ans[i] / 2;
    cout << ans[i] << '\\n';
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int N = 2020;
vector<int> g[N];
int d[N][N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  memset(d, 255, sizeof(d));
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

  for (int i = 1; i < n; i++) {
    g[i].push_back(i - 1);
    g[i - 1].push_back(i);
  }
  g[x].push_back(y);
  g[x].push_back(x);

  for (int i = 0; i < n; i++) {
    vector<int> q;
    q.push_back(i);
    d[i][i] = 0;
    int qj = 0;
    while (qj < q.size()) {
      int curr = q[qj];
      qj++;
      int cd = d[i][curr];
      for (int nxt : g[curr]) {
        if (d[i][nxt] == -1) {
          d[i][nxt] = cd + 1;
          q.push_back(nxt);
        }
      }
    }
  }

  map<int, int> res;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      res[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << res[i] << "\\n";
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 2020;
vector<int> g[N];
int d[1024][1024];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  memset(d, 255, sizeof(d));
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

  for (int i = 1; i < n; i++) {
    g[i].push_back(i - 1);
    g[i - 1].push_back(i);
  }
  g[x].push_back(y);
  g[x].push_back(x);

  for (int i = 0; i < n; i++) {
    vector<int> q;
    q.push_back(i);
    d[i][i] = 0;
    int qj = 0;
    while (qj < q.size()) {
      int curr = q[qj];
      qj++;
      int cd = d[i][curr];
      for (int nxt : g[curr]) {
        if (d[i][nxt] == -1) {
          d[i][nxt] = cd + 1;
          q.push_back(nxt);
        }
      }
    }
  }

  map<int, int> res;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      res[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << res[i] << "\\n";
  }

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

/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int arr[2020][2020];
int chaeng[2020];
int main() {
  int n, i, j, k, x, y, ans, temp, curr, m;
  int tc;
  cin >> n >> x >> y;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      arr[i][j] = 1e9;
  for (i = 1; i <= n; i++)
    arr[i][i] = 0;
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++) {
      arr[i][j] = arr[j][i] = j - i;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      arr[i][j] = min(arr[i][j], arr[i][x] + arr[y][j] + 1);
      arr[i][j] = min(arr[i][j], arr[i][y] + arr[x][j] + 1);
      arr[j][i] = arr[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++) {
      chaeng[arr[i][j]]++;
    }
  }
  for (i = 1; i < n; i++)
    cout << chaeng[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int arr[2020][2020];
int chaeng[2020];
int main() {
  int n, i, j, k, x, y, ans, temp, curr, m;
  int tc;
  cin >> n >> x >> y;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      arr[i][j] = 1e9;
  arr[x][y] = arr[y][x] = 1;
  for (i = 1; i < n; i++) {
    arr[i][i + 1] = arr[i + 1][i] = 1;
  }
  for (k = 1; k <= n; k++) {
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        if (arr[i][j] > arr[i][k] + arr[k][j]) {
          arr[i][j] = arr[i][k] + arr[k][j];
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++) {
      chaeng[arr[i][j]]++;
    }
  }
  for (i = 1; i < n; i++)
    cout << chaeng[i] << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define make_pair mkp;

const int maxn = 1e4 + 10;

// 分成两种情况讨论，一种不经过x,y，一种是经过x,y。。。
// int a[maxn];

int main() {
  int n, x, y, a, b, d;
  cin >> n >> x >> y;
  vector<ll> res(maxn, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      a = j - i;
      b = (x > i ? x - i : i - x) + (y > j ? y - j : j - y) +
          1;         // 加一表示的是x,y之间的距离
      d = min(a, b); // 距离一定是选择最小的。。。
      res[d]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << res[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define make_pair mkp;

const int maxn = 1e3 + 10;

// 分成两种情况讨论，一种不经过x,y，一种是经过x,y。。。
// int a[maxn];

int main() {
  int n, x, y, a, b, d;
  cin >> n >> x >> y;
  vector<int> res(maxn, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      a = j - i;
      b = (x > i ? x - i : i - x) + (y > j ? y - j : j - y) +
          1;         // 加一表示的是x,y之间的距离
      d = min(a, b); // 距离一定是选择最小的。。。
      res[d]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << res[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\\n'
#define fastio                                                                 \\
  cin.sync_with_stdio(false);                                                  \\
  cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<int> adj[2000];

int main() {
  fastio;
  int N, x, y;
  cin >> N >> x >> y;
  --x, --y;

  for (int i = 1; i < N; ++i) {
    adj[i - 1].push_back(i);
    adj[i].push_back(i - 1);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);

  int ans[2000]{};
  for (int i = 0; i < N; ++i) {
    queue<int> Q;
    Q.push(i);

    bool vis[2000]{};
    vis[i] = 1;

    int d = 1;
    while (!Q.empty()) {
      int szQ = sz(Q);
      while (szQ--) {
        int now = Q.front();
        Q.pop();
        for (int nxt : adj[now]) {
          if (vis[nxt])
            continue;
          vis[nxt] = 1;
          Q.push(nxt);
          ans[d]++;
        }
      }
      ++d;
    }
  }

  for (int i = 1; i < N; ++i)
    cout << ans[i] / 2 << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\\n'
#define fastio                                                                 \\
  cin.sync_with_stdio(false);                                                  \\
  cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int adj[2000][2000];

int main() {
  fastio;
  int N, x, y;
  cin >> N >> x >> y;
  --x, --y;

  ini(adj, 0x3f);
  for (int i = 1; i < N; ++i) {
    adj[i - 1][i] = 1;
    adj[i][i - 1] = 1;
  }
  adj[x][y] = adj[y][x] = 1;

  for (int k = 0; k < N; ++k)
    for (int i = 0; i < N; ++i)
      if (adj[i][k] != 0x3f3f3f3f)
        for (int j = 0; j < N; ++j)
          adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);

  int ans[2000]{};
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j)
      if (i != j) {
        ans[adj[i][j]]++;
      }
  }

  for (int i = 1; i < N; ++i)
    cout << ans[i] / 2 << endl;

  return 0;
}