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

// https://atcoder.jp/contests/abc160/tasks/abc160_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

int d[2001][2001];
int N, X, Y;
void warshall_floyd(int n) {
  vector<int> v;
  v.push_back(X);
  v.push_back(Y);
  for (auto k : v) {                // 経由する頂点
    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]);
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> X >> Y;
  REP(i, N) REP(j, N) { d[i][j] = abs(i - j); }
  // 0-indexed
  X--, Y--;
  d[X][Y] = 1;
  d[Y][X] = 1;
  warshall_floyd(N);
  vector<int> ans(N);
  REP(i, N) FOR(j, i + 1, N) {
    int t = d[i][j];
    if (t < N)
      ans[t]++;
  }
  FOR(i, 1, N) { cout << ans[i] << "\\n"; }

  return 0;
}


Error: TLE

Fixed submission:

// https://atcoder.jp/contests/abc160/tasks/abc160_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

int d[2001][2001];
int N, X, Y;
void warshall_floyd(int n) {
  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]);
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> X >> Y;
  REP(i, N) REP(j, N) { d[i][j] = 1e9; }
  REP(i, N - 1) {
    d[i][i + 1] = 1;
    d[i + 1][i] = 1;
  }
  X--, Y--;
  d[X][Y] = 1;
  d[Y][X] = 1;
  warshall_floyd(N);
  vector<int> ans(N);
  REP(i, N) FOR(j, i + 1, N) {
    int t = d[i][j];
    if (t < N)
      ans[t]++;
  }
  FOR(i, 1, N) { cout << ans[i] << "\\n"; }

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

#include <bits/stdc++.h>

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef std::pair<int, int> pii;

using namespace std;

ll n, x, y;

void w(vector<vector<ll>> &g, vector<ll> &c, ll n) {
  for (ll i = 0; i < n; i++) {       // 始点
    for (ll j = i + 1; j < n; j++) { // 終点
      int temp = min(j - i, abs(i - x) + abs(j - y) + 1);
      c[temp]++;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x >> y;
  vector<vector<ll>> g(n, vector<ll>(n, INF));

  REP(i, n - 1) {
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  g[x - 1][y - 1] = 1;
  g[y - 1][x - 1] = 1;
  x--, y--;

  vector<ll> c(n, 0);
  w(g, c, n);

  for (int i = 1; i < n; i++)
    cout << c[i] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef std::pair<int, int> pii;

using namespace std;

void w(vector<vector<ll>> &g, ll n) {
  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]);
      }
    }
  }
}

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

  ll n, x, y;
  cin >> n >> x >> y;
  vector<vector<ll>> g(n, vector<ll>(n, INF));

  REP(i, n - 1) {
    g[i][i + 1] = 1;
    g[i + 1][i] = 1;
  }
  g[x - 1][y - 1] = 1;
  g[y - 1][x - 1] = 1;

  w(g, n);

  vector<ll> ans(n, 0);
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans[g[i][j]]++;
    }
  }
  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;
typedef long long in;
typedef pair<in, in> ii;
#define F first
#define S second
#define sqr(x) (x) * (x)
#define pb(x) push_back(x)
#define sz(x) (in) x.size()
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rep(i, x, y) for (in i = x; i < (y); ++i)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

const in maxn = 2e3 + 9;

in ans[maxn], jafoi[maxn], cur, jaja[maxn][maxn];
vector<in> g[maxn];

void bfs(in x) {
  jafoi[x] = 1;
  queue<in> q;
  q.push(x);
  while (!q.empty()) {
    in agr = q.front();
    q.pop();
    rep(i, 0, sz(g[agr])) {
      in u = g[agr][i];
      if (!jafoi[u]) {
        q.push(u);
        jafoi[u] = jafoi[agr] + 1;
        if (!jaja[u][x]) {
          ans[jafoi[u] - 1]++;
          jaja[u][x] = jaja[x][u] = 1;
        }
      }
    }
  }
}

int main() {
  IOS;
  in n, x, y;
  cin >> n >> x >> y;
  rep(i, 1, n) {
    g[i].pb(i + 1);
    g[i + 1].pb(i);
  }
  g[x].pb(y);
  g[y].pb(x);
  rep(i, 1, n + 1) {
    memset(jafoi, 0, sizeof(jafoi));
    bfs(i);
  }
  rep(i, 1, n) { cout << ans[i] << "\\n"; }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in, in> ii;
#define F first
#define S second
#define sqr(x) (x) * (x)
#define pb(x) push_back(x)
#define sz(x) (in) x.size()
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rep(i, x, y) for (in i = x; i < (y); ++i)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

const in maxn = 2e3 + 9;

in ans[maxn], jafoi[maxn], cur;
vector<in> g[maxn];
set<ii> s;

void bfs(in x) {
  jafoi[x] = 0;
  queue<in> q;
  q.push(x);
  while (!q.empty()) {
    in agr = q.front();
    q.pop();
    rep(i, 0, sz(g[agr])) {
      in u = g[agr][i];
      if (!jafoi[u]) {
        q.push(u);
        jafoi[u] = jafoi[agr] + 1;
        if (!s.count(ii(u, x)) and u != x) {
          ans[jafoi[u]]++;
          s.insert(ii(u, x));
          s.insert(ii(x, u));
        }
      }
    }
  }
}

int main() {
  IOS;
  in n, x, y;
  cin >> n >> x >> y;
  rep(i, 1, n) {
    g[i].pb(i + 1);
    g[i + 1].pb(i);
  }
  g[x].pb(y);
  g[y].pb(x);
  rep(i, 1, n + 1) {
    memset(jafoi, 0, sizeof(jafoi));
    bfs(i);
  }
  rep(i, 1, n) { cout << ans[i] << "\\n"; }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  vector<int> ans(n - 1);
  for (int j = 0; j < n; ++j)
    for (int k = j + 1; k < n; ++k)
      ++ans[min(k - j, abs(k - y) + abs(j - x) + 1) - 1];
  for (auto a : ans)
    cout << a << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)
#define all(ct) ct.begin(), ct.end()
#define endl "\\n"
#define fr(i, a) for (auto i : a)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define in(d, v) d.find(v) != d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e15);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return modexp((x * x) % md, n / 2, md);
  return (x * modexp((x * x) % md, n / 2, md)) % md;
}

int main() {
  fastio;
  // clock_t tm = clock();
  int n, x, y;
  cin >> n >> x >> y;
  vi ans(n, 0);
  --x;
  --y;
  f(i, 0, n) {
    f(j, i + 1, n) {
      int d = abs(x - i) + abs(y - j) + 1;
      ans[min(d, j - i)]++;
    }
  }
  f(i, 1, n) cout << ans[i] << endl;
  // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Error: TLE

Fixed submission:

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)
#define all(ct) ct.begin(), ct.end()
#define endl "\\n"
#define fr(i, a) for (auto i : a)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define in(d, v) d.find(v) != d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e15);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return modexp((x * x) % md, n / 2, md);
  return (x * modexp((x * x) % md, n / 2, md)) % md;
}

int main() {
  fastio;
  // clock_t tm = clock();
  int n, x, y;
  cin >> n >> x >> y;
  vvi d(n, vi(n, 1e9));
  f(i, 0, n) {
    d[i][i] = 0;
    if (i < n - 1) {
      d[i][i + 1] = 1;
      d[i + 1][i] = 1;
    }
  }
  d[x - 1][y - 1] = 1;
  f(k, 0, n) {
    f(i, 0, n) {
      f(j, 0, n) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
    }
  }
  vi ans(n, 0);
  f(i, 0, n) {
    f(j, i + 1, n) { ans[d[i][j]]++; }
  }
  f(i, 1, n) cout << ans[i] << endl;
  // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int g[2010][2010];
int ans[2010];
int n, x, y;
int main() {
  cin >> n >> x >> y;
  if (y < x)
    swap(x, y);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (i <= x && y <= j)
        ans[min(x - i + j - y + 1, j - i)]++; // ac
      else if (x < i && j < y)
        ans[min(j - i, i - x + y - j + 1)]++; // bb
      else if (y <= i && y <= j)
        ans[j - i]++; // cc
      else if (i <= x && j <= x)
        ans[j - i]++;    // aa
      else if (i <= x) { // ab
        int dis = min(j - i, y - j + 1 + x - i);
        ans[dis]++;
      } else if (y <= j) { // bc
        int dis = min(j - i, j - y + 1 + i - x);
        ans[dis]++;
      }
    }
  }
  for (int i = 1; i <= n - 1; i++)
    cout << ans[i] << endl;
  return 0;
}
/*
10 2 9
10
12
13
8
2
0
0
0
0
*/

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int g[2010][2010];
int ans[2010];
int n, x, y;
int main() {
  cin >> n >> x >> y;
  x--, y--;
  memset(g, 0x3f, sizeof(g));
  for (int i = 0; i < n - 1; i++)
    g[i][i] = 0, g[i][i + 1] = g[i + 1][i] = 1;
  g[n - 1][n - 1] = 0;
  g[x][y] = g[y][x] = 1;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (g[i][j] > g[i][k] + g[k][j])
          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] <= 100000)
        ans[g[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] / 2 << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int n, x, y;
int ans[3003], viz[2001];
int modul(int x, int y) {
  if (x > y)
    return x - y;
  else
    return y - x;
}
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int minim = min(modul(j, i), min(modul(x, i) + 1 + modul(j, y),
                                       modul(y, i) + 1 + modul(j, x)));
      ans[minim]++;
    }
  for (int i = 1; i < n; i++)
    cout << ans[i] << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <set>
using namespace std;
int n, x, y;
int ans[1001], viz[1001];
int modul(int x, int y) {
  if (x > y)
    return x - y;
  else
    return y - x;
}
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int minim = min(modul(j, i), min(modul(x, i) + 1 + modul(j, y),
                                       modul(y, i) + 1 + modul(j, x)));
      ans[minim]++;
    }
  for (int i = 1; i < n; i++)
    cout << ans[i] << '\\n';
  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, map<int, int>> dis;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (dis[i][j] == 0)
        dis[i][j] = INT_MAX;
      dis[i][j] = min(abs(j - i), min(abs(x - i) + abs(y - j) + 1,
                                      abs(x - j) + abs(y - i) + 1));
      m[dis[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << m[i] << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif

  int n, x, y;
  cin >> n >> x >> y;

  vector<vector<int>> g(n, vector<int>(n, INT_MAX));

  for (int i = 0; i < n; i++) {
    g[i][i] = 0;
  }
  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 k = 0; k < n; k++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (g[i][k] != INT_MAX and g[k][j] != INT_MAX)
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j)
        ans[g[i][j] - 1]++;
    }
  }
  for (int i = 0; i < n - 1; i++)
    cout << ans[i] / 2 << "\\n";
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

int N, X, Y, a[3004][3004], ans[10005];
vector<int> graph[3004];
queue<int> q;

int main() {
  cin >> N >> X >> Y;
  for (int i = 2; i < N; i++) {
    graph[i].push_back(i - 1);
    graph[i].push_back(i + 1);
  }
  graph[1].push_back(2);
  graph[N].push_back(N - 1);
  graph[X].push_back(Y);
  graph[Y].push_back(X);
  for (int i = 1; i <= N; i++) {
    a[i][i] = 0;
    q.push(i);
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      for (int j = 0; j < graph[f].size(); j++) {
        if (a[i][graph[f][j]] == 0 && graph[f][j] != i) {
          a[i][graph[f][j]] = a[i][f] + 1;
          q.push(graph[f][j]);
        }
      }
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      ans[a[i][j]]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int N, X, Y, a[1004][1004], ans[10005];
vector<int> graph[3004];
queue<int> q;

int main() {
  cin >> N >> X >> Y;
  for (int i = 2; i < N; i++) {
    graph[i].push_back(i - 1);
    graph[i].push_back(i + 1);
  }
  graph[1].push_back(2);
  graph[N].push_back(N - 1);
  graph[X].push_back(Y);
  graph[Y].push_back(X);
  for (int i = 1; i <= N; i++) {
    a[i][i] = 0;
    q.push(i);
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      for (int j = 0; j < graph[f].size(); j++) {
        if (a[i][graph[f][j]] == 0 && graph[f][j] != i) {
          a[i][graph[f][j]] = a[i][f] + 1;
          q.push(graph[f][j]);
        }
      }
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      ans[a[i][j]]++;
    }
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << ans[i] << endl;
  }

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;

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

  ll length[2001] = {0};

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      ll lix = abs(x - i);
      ll ljx = abs(x - j);
      ll liy = abs(y - i);
      ll ljy = abs(y - j);

      ll min = abs(j - i);

      if (lix + ljy + 1 < min) {
        min = lix + ljy + 1;
      }
      if (ljx + liy + 1 < min) {
        min = ljx + liy + 1;
      }

      length[min]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << length[i] / 2 << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;

static const int N = 2000;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N]; // 距離で訪問状態（color）を管理する

int bfs(int s, int k) {
  queue<int> q; // 標準ライブラリの queue を使用
  q.push(s);
  for (int i = 0; i < n; i++)
    d[i] = INFTY;
  d[s] = 0;
  int u;
  int count = 0;

  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int v = 0; v < n; v++) {
      if (M[u][v] == 0)
        continue;
      if (d[v] != INFTY)
        continue;
      d[v] = d[u] + 1;
      if (d[v] == k) {
        count++;
      }
      q.push(v);
    }
    if (d[u] + 1 == k + 1)
      break;
  }

  return count;
}

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

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

  int ans = 0;

  for (int i = 1; i <= n - 1; i++) {
    for (int j = 0; j < n; j++) {
      ans += bfs(j, i);
    }
    cout << ans / 2 << "\\n";
    ans = 0;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define pb push_back
#define ll long long
const int maxn = 2e6 + 10;
const int mod = 1e9 + 7;
const double pi = -acos(-1);

int xx[maxn];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int k = min(j - i, abs(x - i) + abs(y - j) + 1);
      xx[k]++;
    }
  }
  for (int i = 1; i < n; i++)
    printf("%d\\n", xx[i]);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define pb push_back
#define ll long long
const int maxn = 2e6 + 10;
const int mod = 1e9 + 7;
const double pi = -acos(-1);

int xx[maxn];
int x, y;
int f(int i, int j) {
  int m = j - i;
  m = min(m, abs(x - i) + abs(y - j) + 1);
  return m;
}
int main() {
  int n;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    for (int j = 2; j <= n; j++) {
      int k = f(i, j);
      xx[k]++;
    }
  }
  for (int i = 1; i < n; i++)
    printf("%d\\n", xx[i]);
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod = (int)1e9 + 7;
vector<int> adj[2005];
vector<int> vis(2005), dist(2005), ans(2005);

void bfs(int v) {
  queue<int> q;
  q.push(v);
  vis[v] = 1;
  dist[v] = 0;
  while (!q.empty()) {
    auto x = q.front();
    q.pop();
    for (auto u : adj[x]) {
      if (vis[u])
        continue;
      q.push(u);
      dist[u] = dist[x] + 1;
      vis[u] = 1;
    }
  }
}

void test_case() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  for (int i = 0; i < n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      vis[j] = 0, dist[j] = 0;
    bfs(i);
    for (int j = 0; j < n; j++)
      ans[dist[j]]++;
  }
  for (int i = 1; i <= n - 1; i++)
    cout << ans[i] / 2 << "\\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    test_case();
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod = (int)1e9 + 7;
vector<int> adj[1005];
vector<int> vis(1005), dist(1005), ans(1005);

void bfs(int v) {
  queue<int> q;
  q.push(v);
  vis[v] = 1;
  dist[v] = 0;
  while (!q.empty()) {
    auto x = q.front();
    q.pop();
    for (auto u : adj[x]) {
      if (vis[u])
        continue;
      q.push(u);
      dist[u] = dist[x] + 1;
      vis[u] = 1;
    }
  }
}

void test_case() {
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  for (int i = 0; i < n - 1; i++) {
    adj[i].push_back(i + 1);
    adj[i + 1].push_back(i);
  }
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      vis[j] = 0, dist[j] = 0;
    bfs(i);
    for (int j = 0; j < n; j++)
      ans[dist[j]]++;
  }
  for (int i = 1; i <= n - 1; i++)
    cout << ans[i] / 2 << "\\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    test_case();
}