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

#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 2e3 + 5;

int n;
int dist[N], d[N];
vector<int> E[N];

void solve(int s) {
  // memset(dist, 0x3f3f3f3f, sizeof dist);
  vector<int> dist(n + 1, 0x3f3f3f3f);

  dist[s] = 0;
  queue<int> Q;
  Q.push(s);

  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();

    for (int y : E[x]) {
      if (dist[y] > dist[x] + 1) {
        dist[y] = dist[x] + 1;
        if (y > s)
          d[dist[y]]++;
        Q.push(y);
      }
    }
  }

  // for (int i = s + 1; s <= n; s++) cout << dist[i] << endl;
}

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

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

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

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

  for (int i = 1; i < n; i++)
    cout << d[i] << "\\n";
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 2e3 + 5;

int dist[N][N];
int d[N];

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

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

  memset(dist, 0x3f3f3f3f, sizeof dist);

  for (int i = 1; i <= n; i++)
    dist[i][i] = 0;
  for (int i = 1; i < n; i++)
    dist[i][i + 1] = dist[i + 1][i] = 1;
  dist[x][y] = dist[y][x] = 1;

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

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

  for (int i = 1; i < n; i++)
    cout << d[i] << "\\n";
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3", "Ofast", "unroll-loops", "fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
#define endl '\\n'

using namespace std;

const int maxn = 2228;
int d[maxn][maxn];
signed main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);
  int i, j, n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      d[i][j] = min(j - i, abs(x - i) + 1 + abs(y - j));
      d[i][j] = min(d[i][j], abs(y - i) + 1 + abs(x - j));
    }
  }
  vector<int> c(n + 1);
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      c[d[i][j]]++;
    }
  }
  for (i = 1; i < n; i++) {
    cout << c[i] << endl;
  }
  cout << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3", "Ofast", "unroll-loops", "fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
#define endl '\\n'

using namespace std;

const int maxn = 1228;
int d[maxn][maxn];
signed main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);
  int i, j, n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (i <= x && j >= y) {
        d[i][j] = (x - i) + 1 + (j - y);
      } else if (i <= x && j <= y && j >= x) {
        d[i][j] = min(j - i, x - i + 1 + y - j);
      } else if (i >= x && i <= y && j >= y) {
        d[i][j] = min(j - i, i - x + 1 + j - y);
      } else {
        d[i][j] = j - i;
      }
    }
  }
  vector<int> c(n + 1);
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      c[d[i][j]]++;
    }
  }
  for (i = 1; i < n; i++) {
    cout << c[i] << endl;
  }
  cout << endl;

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

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int n, x, y;
static const int INF = 1e9 + 7;
vector<vector<int>> edge;
vector<int> ans;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x >> y;
  edge.resize(n);
  ans.resize(n);
  for (int i = 0; i < n - 1; i++) {
    edge[i].push_back(i + 1);
    edge[i + 1].push_back(i);
  }
  edge[x - 1].push_back(y - 1);
  edge[y - 1].push_back(x - 1);

  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  set<int> s;
  for (int i = 0; i < n; i++) {
    s.clear();
    for (auto &&j : edge[i]) {
      pq.push(make_pair(1, j));
    }
    s.insert(i);
    while (pq.size()) {
      auto info = pq.top();
      pq.pop();
      if (s.count(info.second)) {
        continue;
      }
      ans[info.first]++;
      s.insert(info.second);
      for (auto &&j : edge[info.second]) {
        if (s.count(j)) {
          continue;
        }
        pq.push(make_pair(info.first + 1, j));
      }
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] / 2 << "\\n";
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  static const int INF = 1e9 + 7;
  vector<vector<int>> edge(n, vector<int>(n, INF));
  for (int i = 0; i < n; i++) {
    edge[i][i] = 0;
    if (i + 1 < n) {
      edge[i][i + 1] = edge[i + 1][i] = 1;
    }
  }
  edge[x - 1][y - 1] = edge[y - 1][x - 1] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        edge[j][k] = min(edge[j][k], edge[j][i] + edge[i][k]);
      }
    }
  }
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans[edge[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << "\\n";
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 2001;

struct edge {
  int to, cost;
};
typedef pair<int, int> P; // firstは最短距離, secondは頂点の番号

int V;
vector<edge> G[MAX_V];
int d[MAX_V][MAX_V];

// 負辺のない単一始点全点間最短路を求めるアルゴリズム。
// 蟻本参照
//
// 計算量: O(ElogV)
void dijkstra(int s, int idx) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d[idx], d[idx] + V, INF);
  d[idx][s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[idx][v] < p.first) {
      continue;
    }

    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[idx][e.to] > d[idx][v] + e.cost) {
        d[idx][e.to] = d[idx][v] + e.cost;
        que.push(P(d[idx][e.to], e.to));
      }
    }
  }
}

int X, Y;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> X >> Y;
  X--;
  Y--;
  for (int i = 0; i < V - 1; i++) {
    G[i].push_back(edge{i + 1, 1});
    G[i + 1].push_back(edge{i, 1});
  }
  G[X].push_back(edge{Y, 1});
  G[Y].push_back(edge{X, 1});

  for (int i = 0; i < V; i++) {
    dijkstra(i, i);
  }

  vector<int> ans(V, 0);
  for (int i = 0; i < V; i++) {
    for (int j = i + 1; j < V; j++) {
      ans[d[i][j]]++;
    }
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 2001;

int d[MAX_V][MAX_V];
int V;

void warshall_floyd() {
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        if (d[i][k] == INF || d[k][j] == INF) {
          continue;
        }
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int X, Y;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> X >> Y;
  X--;
  Y--;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (i == j) {
        d[i][j] = 0;
      } else if (i + 1 == j) {
        d[i][j] = 1;
      } else if (i == j + 1) {
        d[i][j] = 1;
      } else {
        d[i][j] = INF;
      }
    }
  }
  d[X][Y] = 1;
  d[Y][X] = 1;

  warshall_floyd();
  vector<int> ans(V, 0);
  for (int i = 0; i < V; i++) {
    for (int j = i + 1; j < V; j++) {
      ans[d[i][j]]++;
    }
  }

  for (int i = 1; i < V; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

const int N = 2e3 + 10;
int a[N];

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> PLL;
#define x first
#define y second
const LL N = 2e3 + 10;
const LL INF = 0x3f3f3f3f;
LL n, x, y;
LL h[N], e[N], ne[N], w[N], idx;
LL dist[N], st[N];
LL res[N], maxdist[N][N];

void add(LL a, LL b, LL c) {
  e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}

LL dijkstra(LL s) {
  memset(dist, INF, sizeof dist);
  memset(st, false, sizeof st);
  dist[s] = 0;
  priority_queue<PLL, vector<PLL>, greater<PLL>> q;
  q.push(make_pair(0, s));

  while (!q.empty()) {
    PLL t = q.top();
    q.pop();

    LL ver = t.y, distance = t.x;

    if (st[ver])
      continue;
    st[ver] = true;

    for (LL i = h[ver]; i != -1; i = ne[i]) {
      LL j = e[i];
      if (dist[j] > distance + w[i]) {
        dist[j] = distance + w[i];
        q.push(make_pair(dist[j], j));
      }
    }
  }

  if (dist[n] == INF)
    return -1;
  return dist[n];
}

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

  memset(h, -1, sizeof h);
  for (LL i = 0; i < n - 1; i++) {
    add(i, i + 1, 1), add(i + 1, i, 1);
  }
  add(x, y, 1), add(y, x, 1);

  for (LL k = 0; k < n; k++) {
    dijkstra(k);
    for (LL j = 0; j < n; j++) {
      maxdist[k][j] = dist[j];
    }
  }

  for (LL i = 0; i < n; i++)
    for (LL j = i + 1; j < n; j++)
      res[maxdist[i][j]]++;

  for (LL i = 1; i < n; i++)
    cout << res[i] << endl;

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

#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;

bool visited[N];
vector<int> adjList[N];
bool compared[N][N];

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    adjList[i].push_back(i + 1);
    adjList[i + 1].push_back(i);
  }

  adjList[x].push_back(y);
  adjList[y].push_back(x);
  /*for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
          if (i == j+1 || j == i+1 || ((i == x && j == y) || (j == x && i ==
  y))) cout << 1 << " "; else cout << 0 << " ";
      }
      cout << endl;
  }*/

  int discount[N] = {};
  int dist[N];
  for (int c = 1; c <= n; c++) {
    memset(visited, 0, sizeof visited);
    queue<int> q;
    q.push(c);
    dist[c] = 0;
    int node;
    while (!q.empty()) {
      node = q.front();
      q.pop();
      if (!compared[c][node]) {
        discount[dist[node]]++;
        compared[c][node] = true;
        compared[node][c] = true;
      }
      for (auto i : adjList[node]) {
        if (visited[i])
          continue;
        dist[i] = dist[node] + 1;
        visited[i] = true;
        q.push(i);
      }
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;

bool visited[N];
vector<int> adjList[N];

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    adjList[i].push_back(i + 1);
    adjList[i + 1].push_back(i);
  }

  adjList[x].push_back(y);
  adjList[y].push_back(x);
  /*for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
          if (i == j+1 || j == i+1 || ((i == x && j == y) || (j == x && i ==
  y))) cout << 1 << " "; else cout << 0 << " ";
      }
      cout << endl;
  }*/

  int discount[N] = {};
  int dist[N];
  map<pair<int, int>, bool> compared;

  for (int c = 1; c <= n; c++) {
    memset(visited, 0, sizeof visited);
    queue<int> q;
    q.push(c);
    dist[c] = 0;
    int node;
    while (!q.empty()) {
      node = q.front();
      q.pop();
      if (!compared[{c, node}]) {
        discount[dist[node]]++;
        compared[{c, node}] = true;
        compared[{node, c}] = true;
      }
      for (auto i : adjList[node]) {
        if (visited[i])
          continue;
        dist[i] = dist[node] + 1;
        visited[i] = true;
        q.push(i);
      }
    }
  }

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

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

#include <bits/stdc++.h>
using namespace std;
vector<int> G[1 << 11];
int d[1 << 11], N, X, Y;
void bfs(int s) {
  fill(d, d + (1 << 11), 1 << 30);
  d[s] = 0;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (auto e : G[v]) {
      if (d[e] > d[v] + 1) {
        d[e] = d[v] + 1;
        q.push(e);
      }
    }
  }
}
int main(void) {
  cin >> N >> X >> Y;
  X--;
  Y--;
  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);
  map<int, int> cnt;
  for (int i = 0; i < N; i++) {
    bfs(i);
    for (int j = i + 1; j < N; j++)
      cnt[d[j]]++;
  }
  for (int k = 1; k < N; k++)
    cout << cnt[k] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int G[1 << 11][1 << 11], d[1 << 11], N, X, Y;
void bfs(int s) {
  fill(d, d + (1 << 11), 1 << 30);
  d[s] = 0;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < N; i++) {
      if (v == i)
        continue;
      if (G[v][i] != 1 << 30 && d[i] > d[v] + 1) {
        d[i] = d[v] + 1;
        q.push(i);
      }
    }
  }
}
int main(void) {
  cin >> N >> X >> Y;
  X--;
  Y--;
  fill((int *)G, (int *)(G + (1 << 11)), 1 << 30);
  for (int i = 0; i < N - 1; i++)
    G[i][i + 1] = G[i + 1][i] = 1;
  G[X][Y] = G[Y][X] = 1;
  map<int, int> cnt;
  for (int i = 0; i < N; i++) {
    bfs(i);
    for (int j = i + 1; j < N; j++)
      cnt[d[j]]++;
  }
  for (int k = 1; k < N; k++)
    cout << cnt[k] << 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 = 1000000000;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

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

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

  vector<int> count(n);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      count[dist[i][j]]++;
    }
  }

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


Error: TLE

Fixed submission:

#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>;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

const int INF = 1000000000;
int main() {
  int n, x, y;
  cin >> n >> x >> y;

  int mp[n][n];
  rep(i, n) rep(j, n) {
    if (i == j) {
      mp[i][j] = 0;
    } else if (abs(i - j) == 1) {
      mp[i][j] = 1;
    } else {
      mp[i][j] = INF;
    }
  }
  mp[x - 1][y - 1] = 1;
  mp[y - 1][x - 1] = 1;

  rep(k, n) rep(i, n) rep(j, n) {
    mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
  }

  vector<int> count(n, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      count[mp[i][j]]++;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using G = vector<vector<int>>;
class Pos {
public:
  int node, rank;
  Pos(int node, int rank) : node(node), rank(rank){};
};

void solve() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int N, X, Y;
  cin >> N >> X >> Y;
  G g(N);
  g[X - 1].push_back(Y - 1);
  g[Y - 1].push_back(X - 1);
  for (int i = 0; i < N - 1; ++i) {
    g[i].push_back(i + 1);
    g[i + 1].push_back(i);
  }
  vector<int> ans(N, 0);
  for (int i = 0; i < N; ++i) {
    queue<int> q;
    q.push(i);
    vector<bool> memo(N, false);
    memo[i] = true;
    vector<int> dis(N);
    dis[i] = 0;
    while (!q.empty()) {
      int node = q.front();
      q.pop();
      for (int e : g[node]) {
        if (memo[e])
          continue;
        memo[e] = true;
        dis[e] = dis[node] + 1;
        q.push(e);
      }
    }
    for (int j = 0; j < N; ++j) {
      ans[dis[j]]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    cout << ans[i] / 2 << endl;
  }
  return;
}

int main() {
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using G = vector<vector<bool>>;
class Pos {
public:
  int node, rank;
  Pos(int node, int rank) : node(node), rank(rank){};
};

void solve() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int N, X, Y;
  cin >> N >> X >> Y;
  G g(N, vector<bool>(N, false));
  g[X - 1][Y - 1] = true;
  g[Y - 1][X - 1] = true;
  for (int i = 0; i < N - 1; ++i) {
    g[i][i + 1] = true;
    g[i + 1][i] = true;
  }
  vector<int> ans(N, 0);
  for (int i = 0; i < N; ++i) {
    queue<int> q;
    q.push(i);
    vector<bool> memo(N, false);
    memo[i] = true;
    vector<int> dis(N);
    dis[i] = 0;
    while (!q.empty()) {
      int node = q.front();
      q.pop();
      vector<bool> edges = g[node];
      for (int x = 0; x < N; ++x) {
        if (!edges[x])
          continue;
        if (memo[x])
          continue;
        memo[x] = true;
        dis[x] = dis[node] + 1;
        q.push(x);
      }
    }
    for (int j = 0; j < N; ++j) {
      ans[dis[j]]++;
    }
  }
  for (int i = 1; i < N; ++i) {
    cout << ans[i] / 2 << endl;
  }
  return;
}

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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)

using namespace std;

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)

using namespace std;

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

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

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

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

  auto res = map<tuple<ll, ll>, int>{};
  auto cost_map = map<int, int>{};

  auto k = 1;
  for (auto i = 1; i < n; i++) {
    for (auto j = i + 1; j <= n; j++) {
      auto min_route = j - i;
      int cost = abs(x - i) + 1 + abs(j - y);
      min_route = min(min_route, cost);
      auto t = make_tuple(i, j);

      res[t] = min_route;
      if (cost_map.count(min_route)) {
        cost_map[min_route] = cost_map[min_route] + 1;
      } else {
        cost_map[min_route] = 1;
      }
    }
  }

  for (auto k = 1; k < n; k++) {
    if (cost_map.count(k)) {
      cout << cost_map[k] << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

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

  auto res = map<tuple<ll, ll>, int>{};
  auto k = 1;
  for (auto i = 1; i < n; i++) {
    for (auto j = i + 1; j <= n; j++) {
      auto min_route = j - i;
      int cost = abs(x - i) + 1 + abs(j - y);
      min_route = min(min_route, cost);
      auto t = make_tuple(i, j);
      res[t] = min_route;
    }
  }

  for (auto k = 1; k < n; k++) {
    ll cnt = 0;
    for (auto it = res.begin(); it != res.end(); it++) {
      if (k == it->second) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}