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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

const int MAX_N = 2e3 + 5;

int n, x, y, dis[MAX_N], ans[MAX_N];
std::vector<int> adj[MAX_N];
bool vis[MAX_N];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 2; i < n; ++i) {
    adj[i].push_back(i + 1);
    adj[i].push_back(i - 1);
  }
  if (n > 1)
    adj[1].push_back(2);
  if (n > 1)
    adj[n].push_back(n - 1);
  for (int i = 1; i < n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    std::queue<int> q;
    vis[i] = true;
    dis[i] = 0;
    for (q.push(i); !q.empty(); q.pop()) {
      for (int j : adj[q.front()])
        if (!vis[j]) {
          dis[j] = dis[q.front()] + 1;
          vis[j] = true;
          q.push(j);
        }
    }
    for (int j = i + 1; j <= n; ++j)
      ++ans[dis[j]];
  }
  for (int i = 1; i < n; ++i)
    printf("%d\\n", ans[i]);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

const int MAX_N = 1e3 + 5;

int n, x, y, dis[MAX_N], ans[MAX_N];
std::vector<int> adj[MAX_N];
bool vis[MAX_N];

int main() {
  scanf("%d%d%d", &n, &x, &y);
  adj[x].push_back(y);
  adj[y].push_back(x);
  for (int i = 2; i < n; ++i) {
    adj[i].push_back(i + 1);
    adj[i].push_back(i - 1);
  }
  if (n > 1)
    adj[1].push_back(2);
  if (n > 1)
    adj[n].push_back(n - 1);
  for (int i = 1; i < n; ++i) {
    memset(vis, 0x00, sizeof(vis));
    std::queue<int> q;
    vis[i] = true;
    dis[i] = 0;
    for (q.push(i); !q.empty(); q.pop()) {
      for (int j : adj[q.front()])
        if (!vis[j]) {
          dis[j] = dis[q.front()] + 1;
          vis[j] = true;
          q.push(j);
        }
    }
    for (int j = i + 1; j <= n; ++j)
      ++ans[dis[j]];
  }
  for (int i = 1; i < n; ++i)
    printf("%d\\n", ans[i]);
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

const int mxN = 2e3 + 5;
int cnt[mxN];

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

  // |j - i|, |x - i| + 1 + |j - y|, |y - i| + 1 + |j - x|
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      ++cnt[min(min(abs(j - i), abs(x - i) + 1 + abs(j - y)),
                abs(y - i) + 1 + abs(j - x))];
  for (int i = 1; i < n; ++i)
    cout << cnt[i] << '\\n';
}


Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;

const int mxN = 2e3 + 5;
vector<int> adj[mxN];
int dis[mxN][mxN];

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  adj[u].push_back(v);
  adj[v].push_back(u);
  for (int i = 1; i < n; ++i)
    adj[i].push_back(i + 1), adj[i + 1].push_back(i);
  memset(dis, -1, sizeof dis);
  for (int i = 1; i <= n; ++i) {
    queue<pair<int, int>> bfs;
    bfs.push({i, 0});
    while (!bfs.empty()) {
      pair<int, int> cur = bfs.front();
      bfs.pop();
      if (~dis[i][cur.first])
        continue;
      dis[i][cur.first] = cur.second;
      for (int x : adj[cur.first])
        if (dis[i][x] == -1)
          bfs.push({x, cur.second + 1});
    }
  }
  map<int, set<pair<int, int>>> mp;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      mp[dis[i][j]].insert({i, j}), mp[dis[i][j]].insert({j, i});
  for (int i = 1; i < n; ++i)
    cout << mp[i].size() / 2 << '\\n';
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> G(n);
  for (int i = 0; i < n - 1; i++) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[x - 1].push_back(y - 1);
  G[y - 1].push_back(x - 1);
  map<int, int> memo;
  for (int i = 0; i < n; i++) {
    int dist[n];
    for (int j = 0; j < n; j++)
      dist[j] = -1;
    queue<int> que;
    dist[i] = 0;
    que.push(i);
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (auto nv : G[v]) {
        if (dist[nv] != -1)
          continue;
        dist[nv] = dist[v] + 1;
        memo[dist[nv]]++;
        que.push(nv);
      }
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << memo[i] / 2 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int d[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) {
        d[i][j] = 0;
        continue;
      }
      if (abs(i - j) == 1) {
        d[i][j] = 1;
        continue;
      }
      if ((i == x - 1 and j == y - 1) or (i == y - 1 and j == x - 1)) {
        d[i][j] = 1;
        continue;
      }
      d[i][j] = 100000;
    }
  }
  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]);
      }
    }
  }
  map<int, int> memo;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      memo[d[i][j]]++;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    cout << memo[i] / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e3 + 3;

struct edge {
  int to;
  int len;
};

vector<edge> g[N];
vector<int> min_dist(N, INF);

void dijkstra(int source) {
  min_dist[source] = 0;
  set<pii> S; // S is set of active vertices (min_dist, vertex)
  S.insert({0, source});

  while (!S.empty()) {
    int curr = S.begin()->se;
    S.erase(S.begin());

    for (auto e : g[curr]) {
      if (min_dist[e.to] > min_dist[curr] + e.len) {
        S.erase({min_dist[e.to], e.to});
        min_dist[e.to] = min_dist[curr] + e.len;
        S.insert({min_dist[e.to], e.to});
      }
    }
  }
}

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

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

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

  vector<int> cnt(N, 0);
  for (int i = 1; i <= n; i++) {
    fill(all(min_dist), INF);
    dijkstra(i);
    for (int i = 1; i <= n; i++) {
      cnt[min_dist[i]]++;
    }
  }

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

Error: 0

Fixed submission:

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e3 + 3;

struct edge {
  int to;
  int len;
};

vector<edge> g[N];
vector<int> min_dist(N, INF);

void dijkstra(int source) {
  min_dist[source] = 0;
  set<pii> S; // S is set of active vertices (min_dist, vertex)
  S.insert({0, source});

  while (!S.empty()) {
    int curr = S.begin()->se;
    S.erase(S.begin());

    for (auto e : g[curr]) {
      if (min_dist[e.to] > min_dist[curr] + e.len) {
        S.erase({min_dist[e.to], e.to});
        min_dist[e.to] = min_dist[curr] + e.len;
        S.insert({min_dist[e.to], e.to});
      }
    }
  }
}

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

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

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

  vector<int> cnt(N, 0);
  for (int i = 1; i <= n; i++) {
    fill(all(min_dist), INF);
    dijkstra(i);
    for (int i = 1; i <= n; i++) {
      cnt[min_dist[i]]++;
    }
  }

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

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  map<int, long> m;
  for (int i = 1; i < N; i++) {
    m[i] = 0;
  }

  int a[N][N];

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      a[i][j] = abs(j - i);
    }
  }

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      a[i][j] = min(a[i][j], a[i][X] + 1 + a[Y][j]);
      m[a[i][j]]++;
    }
  }

  for (auto x : m) {
    cout << x.second << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  map<int, long> m;
  for (int i = 1; i < N; i++) {
    m[i] = 0;
  }

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

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      a[i][j] = min(a[i][j], a[i][X] + 1 + a[Y][j]);
      m[a[i][j]]++;
    }
  }

  for (auto x : m) {
    cout << x.second << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define MAX 2000

int main() {
  int N, x, y, D[MAX], i, j, d, d1, d2;
  cin >> N >> x >> y;
  for (i = 1; i <= N; i++)
    D[i] = 0;
  for (i = 1; i < N; i++) {
    for (j = i + 1; j <= N; j++) {
      d1 = j - i;
      d2 = abs(y - j) + abs(x - i) + 1;
      d = min(d1, d2);
      D[d]++;
    }
  }
  for (i = 1; i < N; i++)
    cout << D[i] << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 200

int main() {
  int N, x, y, D[MAX], i, j, d, d1, d2;
  cin >> N >> x >> y;
  for (i = 1; i <= N; i++)
    D[i] = 0;
  for (i = 1; i < N; i++) {
    for (j = i + 1; j <= N; j++) {
      d1 = j - i;
      d2 = abs(y - j) + abs(x - i) + 1;
      d = min(d1, d2);
      D[d]++;
    }
  }
  for (i = 1; i < N; i++)
    cout << D[i] << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define DS pair<ll, ll>
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
;
const double PI = 2 * acos(0.0);
// template<typename T> using ordered_set = tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;

int cost[3005], ok[3005][3005];
vector<int> g[N];
unordered_map<int, int> ans, vis;

void bfs(int s) {
  queue<int> q;
  vis.clear();
  vis[s] = 1;
  q.push(s);
  memset(cost, 0, sizeof cost);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (vis[v] == 0) {
        q.push(v);
        vis[v] = 1;
        cost[v] = cost[u] + 1;
      } else if (cost[u] + 1 < cost[v]) {
        cost[v] = cost[u] + 1;
      }
    }
  }
}

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int n, x, y;
  cin >> n >> 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[y].push_back(x);
  for (int i = 1; i <= n; i++) {
    bfs(i);
    for (int j = 1; j < n; j++) {
      if (ok[i][j] || ok[j][i]) {
        continue;
      }
      ans[cost[j]]++;
      ok[i][j] = ok[j][i] = 1;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define DS pair<ll, ll>
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
;
const double PI = 2 * acos(0.0);
// template<typename T> using ordered_set = tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>;

int cost[3005];
vector<int> g[N];
map<DS, bool> ok;
unordered_map<int, int> ans, vis;

void bfs(int s) {
  queue<int> q;
  vis.clear();
  vis[s] = 1;
  q.push(s);
  memset(cost, 0, sizeof cost);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (vis[v] == 0) {
        q.push(v);
        vis[v] = 1;
        cost[v] = cost[u] + 1;
      } else if (cost[u] + 1 < cost[v]) {
        cost[v] = cost[u] + 1;
      }
    }
  }
}

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int n, x, y;
  cin >> n >> 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[y].push_back(x);
  for (int i = 1; i <= n; i++) {
    bfs(i);
    for (int j = 1; j <= n; j++) {
      if (ok[{i, j}] || ok[{j, i}]) {
        continue;
      }
      ans[cost[j]]++;
      ok[{i, j}] = ok[{j, i}] = 1;
    }
  }
  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>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

// pdf見て解答

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

  fill(ans.begin(), ans.end(), 0);

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ans[min(abs(j - i),
              min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)))]++;
      // put(min(abs(j-i),min(abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))));
    }
  }
  for (int j = 1; j < n; j++) {
    put(ans[j] / 2);
  }
}

Error: TLE

Fixed submission:

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

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  vector<vector<ll>> g;
  vector<ll> flag(n);
  vector<set<set<ll>>> ans(n - 1);

  for (int i = 1; i <= n; i++) {
    vector<ll> tmp;
    // tmp.push_back(i);
    if (i > 1)
      tmp.push_back(i - 1);
    if (i < n)
      tmp.push_back(i + 1);
    g.push_back(tmp);
  }
  g[x - 1].push_back(y);
  g[y - 1].push_back(x);

#ifdef DEBUG
  for (auto x : g) {
    cout << "[";
    for (auto y : x) {
      cout << y << " ";
    }
    cout << "]";
  }
  cout << endl;
#endif

  for (int i = 0; i < n; i++) {
    queue<ll> q;
    q.push(i);
    fill(flag.begin(), flag.end(), -1);
    flag[i] = 0;
    // bfs
    while (!q.empty()) {
      ll tmp = q.front();
      q.pop();
      for (auto x : g[tmp]) {
        if (flag[x - 1] < 0) {
          q.push(x - 1);
          flag[x - 1] = flag[tmp] + 1;
          set<ll> s;
          s.insert(i);
          s.insert(x - 1);
          ans[flag[x - 1] - 1].insert(s);
        }
      }
    }
/*
for(int j = 0; j < n; j++){
    if(flag[j] == 0) continue;
    set<ll> tmp;
    tmp.insert(i+1);
    tmp.insert(j+1);
    ans[flag[j]-1].insert(tmp);
}*/
#ifdef DEBUG
    for (auto x : flag)
      cout << x << " ";
    cout << endl;
#endif
  }
#ifdef DEBUG
  for (auto x : ans) {
    for (auto y : x) {
      cout << "(";
      for (auto z : y) {
        cout << z << " ";
      }
      cout << ")";
    }
    cout << endl;
  }
#endif

  for (int i = 0; i < n - 1; i++) {
    put(ans[i].size());
  }
}
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;

  vector<int> count(N + 1);

  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++) {
      int A, B, C, D;
      A = j - i;
      B = 1;
      if (j > Y) {
        C = j - Y;
      } else {
        C = Y - j;
      }
      if (i > X) {
        D = i - X;
      } else {
        D = X - i;
      }
      int distance;
      distance = min(A, B + C + D);
      count.at(distance)++;
    }
  }
  for (int i = 1; i < N; i++) {
    cout << count.at(i) << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  for (int k = 1; k < N; k++) {
    int count = 0;

    for (int i = 1; i <= N - k; i++) {
      for (int j = i + k; j <= N; j++) {
        int A, B, C, D;
        A = j - i;
        B = 1;
        if (j > Y) {
          C = j - Y;
        } else {
          C = Y - j;
        }
        if (i > X) {
          D = i - X;
        } else {
          D = X - i;
        }
        int distance;
        distance = min(A, B + C + D);
        if (distance == k) {
          count++;
        }
      }
    }

    cout << count << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

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

vector<int> s[N];

void add(int x, int y) {
  s[x].push_back(y);
  s[y].push_back(x);
}

int a[N];
vector<int> v;

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; ++i) {
    add(i, i + 1);
  }
  add(x, y);
  for (int i = 1; i <= n; ++i) {
    priority_queue<pair<int, int>> Q;
    Q.push(make_pair(0, i));
    int vis[N] = {0};
    vis[i] = 1;
    while (!Q.empty()) {
      pair<int, int> p = Q.top();
      Q.pop();
      a[-p.first]++;
      for (int j = 0, st = s[p.second].size(); j < st; ++j) {
        int m = s[p.second][j];
        if (!vis[m]) {
          vis[m] = 1;
          Q.push(make_pair(p.first - 1, m));
        }
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", a[i] / 2);
  }
}

int main() { solve(); }


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 100;
#define ll long long

vector<int> s[N];

void add(int x, int y) {
  s[x].push_back(y);
  s[y].push_back(x);
}

int a[N];
vector<int> v;

void solve() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; ++i) {
    add(i, i + 1);
  }
  add(x, y);
  for (int i = 1; i <= n; ++i) {
    priority_queue<pair<int, int>> Q;
    Q.push(make_pair(0, i));
    int vis[N] = {0};
    vis[i] = 1;
    while (!Q.empty()) {
      pair<int, int> p = Q.top();
      Q.pop();
      a[-p.first]++;
      for (int j = 0, st = s[p.second].size(); j < st; ++j) {
        int m = s[p.second][j];
        if (!vis[m]) {
          vis[m] = 1;
          Q.push(make_pair(p.first - 1, m));
        }
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\\n", a[i] / 2);
  }
}

int main() { solve(); }
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> v(N, vector<int>(N));
  vector<int> ans(N - 1);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      v[i][j] = min(j - i, abs(Y - j - 1) + 1 + abs(X - i - 1));
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (v[i][j] > 0) {
        int ind = v[i][j] - 1;
        ans[ind] += 1;
      }
    }
  }

  for (int x : ans) {
    cout << x << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> v(N - 1, vector<int>(N - 1));
  vector<int> ans(N - 1);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      v[i][j] = min(j - i, abs(Y - j - 1) + 1 + abs(X - i - 1));
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (v[i][j] > 0) {
        int ind = v[i][j] - 1;
        ans[ind] += 1;
      }
    }
  }

  for (int x : ans) {
    cout << x << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

/* 大文字を小文字に変換 */
char tolower(char c) { return (c + 0x20); }
/* 小文字を大文字に変換 */
char toupr(char c) { return (c - 0x20); }

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

const int INF = pow(10, 4);

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  int d[N][N];
  int dis[N];
  // 初期化
  rep(i, N) {
    rep(j, N) { d[i][j] = INF; }
  }
  rep(i, N) dis[i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      d[i][j] = min(abs(j - i), abs(X - 1 - i) + 1 + abs(Y - 1 - j));
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      // if(d[i][j] == 5) cout << i << "," << j << endl;
      dis[d[i][j]]++;
    }
  }
  rep(i, N) {
    if (i != 0)
      printf("%d\\n", dis[i]);
  }
}

Error: TLE

Fixed submission:

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

/* 大文字を小文字に変換 */
char tolower(char c) { return (c + 0x20); }
/* 小文字を大文字に変換 */
char toupr(char c) { return (c - 0x20); }

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

const int INF = pow(10, 4);

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  int d[N][N];
  int dis[N];
  // 初期化
  rep(i, N) {
    rep(j, N) { d[i][j] = INF; }
  }
  rep(i, N) dis[i] = 0;
  rep(i, N) {
    // cout << i << endl;
    if (i != N - 1) {
      d[i][i + 1] = 1;
      d[i + 1][i] = 1;
    }
  }
  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][j], d[i][k] + d[k][j]);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      // if(d[i][j] == 5) cout << i << "," << j << endl;
      dis[d[i][j]]++;
    }
  }
  rep(i, N) {
    if (i != 0)
      printf("%d\\n", dis[i]);
  }
}