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

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

int ans[2001];

inline void gs(int x) {
  for (int i = 1; i < x; ++i)
    ans[i] += x - i;
}

inline void gp(int a, int b) {
  // cout<<a<<" "<<b<<endl;
  int i;
  if (b <= a) {
    for (i = 1; i <= b; ++i)
      ans[i] += i;
    for (; i <= a; ++i)
      ans[i] += b;
    for (; i < a + b; ++i)
      ans[i] += a + b - i;
  } else {
    for (i = 1; i <= a; ++i)
      ans[i] += i;
    for (; i <= b; ++i)
      ans[i] += a;
    for (; i < a + b; ++i)
      ans[i] += a + b - i;
  }
  for (i = 1; i <= b; ++i)
    --ans[i];
}

inline void ks(int x) {
  --ans[1];
  for (int i = 2; i <= x >> 1; ++i)
    ans[i] -= 2;
}

inline void hs(int x) {
  for (int i = 1; i <= x >> 1; ++i)
    ans[i] += x;
  if (x % 2 == 0)
    ans[x >> 1] -= x >> 1;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  memset(ans, 0, sizeof(ans));

  int i;
  int huan = y - x - 1, mh = x + y >> 1, zh = mh - x, yh = huan - zh;

  gs(n - huan);
  // for(i=1;i<n;++i)cout<<ans[i]<<endl;

  if (huan > 0) {
    gp(x, zh);
    // for(i=1;i<n;++i)cout<<ans[i]<<endl;

    gp(x + 1, yh);
    // for(i=1;i<n;++i)cout<<ans[i]<<endl;

    gp(n - y + 2, yh);
    // for(i=1;i<n;++i)cout<<ans[i]<<endl;

    gp(n - y + 1, zh);
    // for(i=1;i<n;++i)cout<<ans[i]<<endl;

    ks(huan + 2);
    // for(i=1;i<n;++i)cout<<ans[i]<<endl;

    hs(huan + 2);
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[2001][2001], b[2001];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  register int i, j, k;
  memset(a, 0x3f, sizeof(a)), memset(b, 0, sizeof(b));
  for (i = 1; i < n; ++i)
    a[i][i + 1] = a[i + 1][i] = 1;

  a[x][y] = a[y][x] = 1;

  for (k = 1; k <= n; ++k) {
    for (i = 1; i <= n; ++i) {
      for (j = 1; j <= n; ++j)
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
    }
  }

  for (i = 1; i < n; ++i) {
    for (j = i + 1; j <= n; ++j) {
      ++b[a[i][j]];
    }
  }
  for (i = 1; i < n; ++i)
    cout << b[i] << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
const int MAXN = 1e3 + 2;
int d[MAXN << 1][MAXN << 1];
int dis[MAXN << 1];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = abs(i - j);
    }
  }

  d[x - 1][y - 1] = 1;
  d[y - 1][x - 1] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      d[i][j] = min(min(d[i][x - 1] + 1 + d[y - 1][j], d[i][j]),
                    d[i][y - 1] + 1 + d[x - 1][j]);
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j)
        ++dis[d[i][j]];
    }
  }

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

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
const int MAXN = 1e3 + 2;
int d[MAXN << 1][MAXN << 1];
int dis[MAXN << 1];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = abs(i - j);
    }
  }
  d[x - 1][y - 1] = 1;
  d[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++) {
        d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
      }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j)
        ++dis[d[i][j]];
    }
  }

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

#include <iostream>
using namespace std;

#include <cstring>
#include <queue>

int get_minstep(int start, int end, int n, int x, int y) {
  int straight_steps = end - start;
  int xy_steps = 1 + abs(start - x) + abs(end - y);
  return min(straight_steps, xy_steps);
}

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

  int min_steps[2000];
  memset(min_steps, 0, sizeof(min_steps));
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      min_steps[get_minstep(i, j, n, x - 1, y - 1) - 1]++;
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#include <cstring>
#include <queue>

void set_cost(int index, int current_cost, queue<int> &graph, int *costs) {
  if (costs[index] != 0)
    return;

  // cout << index << endl;
  graph.push(index);
  costs[index] = current_cost;
}

int costs[2000];
int get_minstep(int start, int end, int n, int x, int y) {
  memset(costs, 0, sizeof(costs));
  // for (int i = 0; i < n; ++i)
  //     costs[i] = -1;

  costs[start] = 1;
  int current = start;
  queue<int> graph;
  graph.push(start);
  while (true) {
    current = graph.front();
    graph.pop();
    if (current == 0) {
      set_cost(current + 1, costs[current] + 1, graph, costs);
      if (costs[end] != 0)
        break;
    } else if (current == n - 1) {
      set_cost(current - 1, costs[current] + 1, graph, costs);
      if (costs[end] != 0)
        break;
    } else {
      set_cost(current - 1, costs[current] + 1, graph, costs);
      set_cost(current + 1, costs[current] + 1, graph, costs);
      if (costs[end] != 0)
        break;
    }
    if (current == x) {
      set_cost(y, costs[current] + 1, graph, costs);
      if (costs[end] != 0)
        break;
    }
    if (current == y) {
      set_cost(x, costs[current] + 1, graph, costs);
      if (costs[end] != 0)
        break;
    }

    if (costs[end] != 0)
      break;
  }
  // cout << start << " " << end << " " << costs[end] << endl;
  return costs[end] - 1;
}

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

  int min_steps[2000];
  memset(min_steps, 0, sizeof(min_steps));
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      min_steps[get_minstep(i, j, n, x - 1, y - 1) - 1]++;
    }
  }

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

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

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

typedef long long LL;

int main(void) {
  int n, x, y;
  cin >> n >> x >> y;
  int dis1, dis2;
  int ans[2005] = {};
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (i <= x && y <= j) {
        dis1 = j - y + x - i + 1;
        ans[dis1]++;
      } else if (i <= x && j < y) {
        dis1 = j - i;
        dis2 = y - j + x - i + 1;
        ans[min(dis1, dis2)]++;
      } else if (x < i && j >= y) {
        dis1 = j - i;
        dis2 = i - x + j - y + 1;
        ans[min(dis1, dis2)]++;
      } else {
        dis1 = j - i;
        dis2 = i - x + y - j + 1;
        ans[min(dis1, dis2)]++;
      }
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << ans[i] << endl;
  }
}

Error: 0

Fixed submission:

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

typedef long long LL;

int main(void) {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> a(2000, vector<int>(2000));
  int dis1, dis2;
  int ans[2005] = {};
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (i <= x && y <= j) {
        a[i][j] = j - y + x - i + 1;
      } else if (i <= x && j < y) {
        dis1 = j - i;
        dis2 = y - j + x - i + 1;
        if (dis1 > dis2)
          a[i][j] = dis2;
        else
          a[i][j] = dis1;
      } else if (x < i && j >= y) {
        dis1 = j - i;
        dis2 = i - x + j - y + 1;
        if (dis1 > dis2)
          a[i][j] = dis2;
        else
          a[i][j] = dis1;
      } else {
        dis1 = j - i;
        dis2 = i - x + y - j + 1;
        if (dis1 > dis2)
          a[i][j] = dis2;
        else
          a[i][j] = dis1;
      }
    }
  }
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      tmp = a[i][j];
      ans[tmp]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
const int mod = 1000000007;
const int INF = 1001001001;

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) {
        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]]++;
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
// const int mod = 1000000007;
const int INF = 1001001001;
// struct edge{ll to, cost;};
// vector<vector<edge>> d;
// vector<vector<edge>> graph;
vector<int> used;
vector<vector<int>> graph;
vector<vector<int>> d;
int n, x, y;

// void dfs(int vertex, int cur, int dist) {
//   cout << vertex << endl;
//   if(d[vertex][cur] > dist) d[vertex][cur] = dist;
//   if(used[cur]) return;
//   used[cur] = true;
//   for(int i = 0; i < n; ++i) {
//     if(graph[cur][i] == 0) continue;
//     dfs(vertex, i, dist + 1);
//   }
//   return;
// }

int main() {

  cin >> n >> x >> y;
  graph.resize(n, vector<int>(n + 10));
  d.resize(n, vector<int>(n + 10, INF));
  used.resize(n, false);
  for (int i = 0; i < n - 1; ++i) {
    graph[i][i + 1] = 1;
    graph[i + 1][i] = 1;
  }
  x--;
  y--;
  graph[x][y] = 1;
  graph[y][x] = 1;

  rep(i, n) {
    queue<P> que;
    que.push(make_pair(i, 0));
    d[i][i] = 0;
    while (!que.empty()) {
      P v = que.front();
      que.pop();

      rep(j, n) {
        if (graph[v.first][j] == 1) {
          if (d[i][j] > v.second) {
            que.push(make_pair(j, v.second + 1));

            d[i][j] = v.second + 1;
          }
        }
      }
    }
  }
  vector<int> cnt(n + 10);
  rep(i, n) {
    for (int j = i + 1; j < n; ++j) {
      cnt[d[i][j]]++;
    }
  }

  for (int i = 1; i <= n - 1; ++i) {
    printf("%d\\n", cnt[i]);
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int abs(int i, int j) {
  if (i > j) {
    return i - j;
  } else {
    return j - i;
  }
}

int min(int i, int j, int k) {
  if (i < j) {
    if (i < k) {
      return i;
    } else {
      return k;
    }
  } else if (j < k) {
    return j;
  } else {
    return k;
  }
}

int main() {
  int X, Y, N;
  scanf("%d %d %d", &N, &X, &Y);
  int k[N][N];
  int l[N][N];
  int a[N - 1];
  int i, j, m;
  for (i = 0; i < N - 1; i++) {
    a[i] = 0;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      k[i][j] = abs(i, j);
    }
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      l[i][j] = min(k[i][X - 1] + 1 + k[Y - 1][j],
                    k[i][Y - 1] + 1 + k[X - 1][j], k[i][j]);
    }
  }

  for (j = 0; j < N; j++) {
    for (m = j; m < N; m++) {
      a[l[j][m] - 1] = a[l[j][m] - 1] + 1;
    }
  }

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

Error: TLE

Fixed submission:

#include <stdio.h>

int abs(int i, int j) {
  if (i > j) {
    return i - j;
  } else {
    return j - i;
  }
}

int min(int i, int j, int k) {
  if (i < j) {
    if (i < k) {
      return i;
    } else {
      return k;
    }
  } else if (j < k) {
    return j;
  } else {
    return k;
  }
}

int main() {
  int X, Y, N;
  scanf("%d %d %d", &N, &X, &Y);
  int k[N][N];
  int l[N][N];
  int a[N - 1];
  int i, j, m;
  for (i = 0; i < N - 1; i++) {
    a[i] = 0;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      k[i][j] = abs(i, j);
    }
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      l[i][j] = min(k[i][X - 1] + 1 + k[Y - 1][j],
                    k[i][Y - 1] + 1 + k[X - 1][j], k[i][j]);
    }
  }

  for (i = 0; i < N - 1; i++) {
    for (j = 0; j < N; j++) {
      for (m = j; m < N; m++) {
        if (l[j][m] == i + 1) {
          // printf("%d %d %d",j,m,l[j][m]);
          // printf("¥n");
          a[i] = a[i] + 1;
        }
      }
    }
  }
  for (i = 0; i < N - 1; i++) {
    printf("%d\\n", a[i]);
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 0x7fffffff

int main() {
  long long a, b, c, i, j, k, n, m, x, y, ans1, ans = 0;
  string str;

  cin >> n >> x >> y;

  vector<vector<int>> aa(n + 1, vector<int>(n + 1));
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      aa[i][j] = j - i;
      if ((i <= x) && (y <= j))
        aa[i][j] = j - i - (y - x) + 1;
      if ((x <= i) && (y <= j)) {
        k = (i - x + 1 + (j - y));
        if (aa[i][j] > k)
          aa[i][j] = k;
      } else if ((x <= i) && (j <= y)) {
        k = (i - x + 1 + (y - j));
        if (aa[i][j] > k)
          aa[i][j] = k;
      } else if ((i <= x) && (j <= y)) {
        k = (x - i + 1 + (y - j));
        if (aa[i][j] > k)
          aa[i][j] = k;
      }
    }
  }
  /*
          for(i=1;i<=n;i++) {
                  for(j=1;j<=n;j++) {
                          cout << aa[i][j] << " ";
                  }
                  cout << endl;
          }
  */
  vector<int> an(n + 1);
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      an[aa[i][j]]++;
    }
  }
  for (i = 1; i < n; i++) {
    cout << an[i] << endl;
  }
}


Error: TLE

Fixed submission:

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

#define INF 0x7fffffff

int main() {
  long long a, b, c, i, j, k, n, m, x, y, ans1, ans = 0;
  string str;

  cin >> n >> x >> y;

  vector<vector<int>> aa(n + 1, vector<int>(n + 1));
  for (i = 1; i <= n - 1; i++) {
    for (j = i + 1; j <= n; j++) {
      aa[i][j] = j - i;
      if ((i <= x) && (y <= j))
        aa[i][j] = j - i - (y - x) + 1;
      if ((x <= i) && (y <= j))
        if (aa[i][j] > (i - x + 1 + (j - y)))
          aa[i][j] = (i - x + 1 + (j - y));
      if ((x <= i) && (j <= y))
        if (aa[i][j] > (i - x + 1 + (y - j)))
          aa[i][j] = (i - x + 1 + (y - j));
      if ((i <= x) && (j <= y))
        if (aa[i][j] > (x - i + 1 + (y - j)))
          aa[i][j] = (x - i + 1 + (y - j));
    }
  }
  /*
          for(i=1;i<=n;i++) {
                  for(j=1;j<=n;j++) {
                          cout << aa[i][j] << " ";
                  }
                  cout << endl;
          }
  */
  for (a = 1; a < n; a++) {
    ans = 0;
    for (i = 1; i <= n - 1; i++) {
      for (j = i + 1; j <= n; j++) {
        if (aa[i][j] == a)
          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)
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))

using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> adjList;
int arr[21000]{};
ll N, X, Y;

vector<int> bfs(int node) {

  queue<int> qu;
  vector<int> d(N + 1, -1);
  d[node] = 0;
  qu.push(node);
  bool ok = true;

  while (!qu.empty()) {
    node = qu.front();
    qu.pop();
    for (auto x : adjList[node]) {

      if (d[x] == -1) {
        d[x] = d[node] + 1;
        qu.push(x);
      }
    }
  }
  return d;
}

int main() {

  cin >> N >> X >> Y;
  adjList = vector<vector<int>>(N);

  for (int i = 0; i < N - 1; i++) {

    adjList[i].push_back(i + 1);
    adjList[i + 1].push_back(i);
  }
  adjList[X - 1].push_back(Y - 1);
  adjList[Y - 1].push_back(X - 1);

  for (int from = 0; from < N; from++) {
    vector<int> DEP = bfs(from);
    for (int k = 0; k < N; k++) {
      arr[DEP[k]]++;
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))

using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> adjList;
int arr[21000]{};
ll N, X, Y;

void bfs(int depth, int node) {

  queue<int> qu;
  vector<int> d(N + 1, -1);
  d[node] = 0;
  qu.push(node);
  bool ok = true;

  while (!qu.empty() && ok) {
    node = qu.front();
    qu.pop();
    for (auto x : adjList[node]) {

      if (d[x] == -1) {
        d[x] = d[node] + 1;
        qu.push(x);
        if (d[x] == depth) {
          arr[depth]++;
        }
      } else if (d[x] > depth)
        ok = false;
    }
  }
}
int main() {

  cin >> N >> X >> Y;
  adjList = vector<vector<int>>(N);

  for (int i = 0; i < N - 1; i++) {

    adjList[i].push_back(i + 1);
    adjList[i + 1].push_back(i);
  }
  adjList[X - 1].push_back(Y - 1);
  adjList[Y - 1].push_back(X - 1);

  for (int i = 0; i < N; i++) {
    for (int k = 1; k <= N; k++) {
      bfs(k, i);
    }
  }

  for (int i = 1; i < N; i++)
    cout << arr[i] / 2 << endl;
  return 0;
}
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;

  // 解説見たやり方（この問題の特性上，XY間を通るか否かで場合分けして最小か比較するのが簡単だった．あとgraphはそもそも不要でループ内で都度カウントしてあげるようにした）
  vector<int> result(N - 1);
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ++result[min({j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j),
                    abs(Y - 1 - i) + 1 + abs(X - 1 - j)}) -
               1];
    }
  }
  for (auto r : result) {
    cout << r << 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;

  vector<vector<int>> graph(N, vector<int>(N));
  for (int i = 0; i < N - 1; ++i) {
    // graph[i][i] = 0;
    graph[i][i + 1] = 1;
    // graph[i + 1][i] = 1;
  }
  // graph[N - 1][N - 1] = 0;
  graph[X - 1][Y - 1] = 1;
  // graph[Y - 1][X - 1] = 1;

  // ワーシャルフロイド法（WA）
  // for (int k = 0; k < N; ++k) {
  //     for (int i = 0; i < N; ++i) {
  //         for (int j = 0; j < N; ++j) {
  //             graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
  //         }
  //     }
  // }
  // 解説見たやり方（この問題の特性上，XY間を通るか否かで場合分けして最小か比較するのが簡単だった．あとgraphの上三角だけ使うことにした）
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      graph[i][j] = min({j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j),
                         abs(Y - 1 - i) + 1 + abs(X - 1 - j)});
    }
  }

  int cnt = 0;
  for (int k = 1; k < N; ++k) {
    cnt = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = i + 1; j < N; ++j) {
        if (graph[i][j] == k) {
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[2010][2010], ans[2010];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = abs(i - j);
    }
  }
  a[x][y] = 1;
  a[y][x] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = min(a[i][j], a[i][x] + 1 + a[y][j]);
      a[i][j] = min(a[i][j], a[i][y] + 1 + a[x][j]);
    }
  }
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans[a[i][j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    printf("%d\\n", ans[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[1010][1010], ans[2010];
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = abs(i - j);
    }
  }
  a[x][y] = 1;
  a[y][x] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = min(a[i][j], a[i][x] + 1 + a[y][j]);
      a[i][j] = min(a[i][j], a[i][y] + 1 + a[x][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = min(a[i][j], a[i][x] + 1 + a[y][j]);
      a[i][j] = min(a[i][j], a[i][y] + 1 + a[x][j]);
    }
  }
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans[a[i][j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    printf("%d\\n", ans[i]);
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define quicker                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef long long ll;

vector<vector<int>> adj;

int main() {
  quicker
#ifdef HALO
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, x, y;

  cin >> n >> x >> y;
  adj = vector<vector<int>>(n + 1);
  for (int i = 1; i < n; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  if (x != y + 1 && (x != y - 1)) {
    adj[x].pb(y);
    adj[y].pb(x);
  }
  int A[2001][2001] = {0};
  for (int i = 1; i <= n; i++) {
    A[i][i] = 0;
    bool visited[3000] = {false};
    queue<int> Q;
    Q.push(i);
    int v, cnt = 0;
    visited[i] = true;
    while (!Q.empty()) {
      v = Q.front();
      Q.pop();
      for (auto u : adj[v]) {
        if (!visited[u]) {
          visited[u] = true;
          A[i][u] = A[i][v] + 1;
          Q.push(u);
        }
      }
    }
  }
  int B[20000] = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++)
      ++B[A[i][j]];
  }
  for (int i = 1; i < n; i++)
    cout << B[i] << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define quicker                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef long long ll;

vector<vector<int>> adj;

int main() {
  quicker
#ifdef HALO
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, x, y;

  cin >> n >> x >> y;
  adj = vector<vector<int>>(n + 1);
  for (int i = 1; i < n; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  if (x != y + 1 && (x != y - 1)) {
    adj[x].pb(y);
    adj[y].pb(x);
  }
  int A[2000][2000] = {0};
  for (int i = 1; i <= n; i++) {
    A[i][i] = 0;
    bool visited[2000] = {false};
    queue<int> Q;
    Q.push(i);
    int v, cnt = 0;
    visited[i] = true;
    while (!Q.empty()) {
      v = Q.front();
      Q.pop();
      for (auto u : adj[v]) {
        if (!visited[u]) {
          visited[u] = true;
          A[i][u] = A[i][v] + 1;
          Q.push(u);
        }
      }
    }
  }
  int B[200000] = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++)
      ++B[A[i][j]];
  }
  for (int i = 1; i < n; i++)
    cout << B[i] << endl;
}