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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define endl "\\n"
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

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

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

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define endl "\\n"
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int INF = 100000;
int xy[2020][2020];

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

  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  rep(i, n) {
    rep(j, n) { xy[i][j] = INF; }
  }

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

  ll ans[2200] = {0};
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      // cout << xy[i][j] << endl;
      ans[xy[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>

typedef long long ll;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++) // no semicoron
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i > 0; i--)
#define FORD(i, a, b) for (ll i = (a); i > (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく

using namespace std;

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

  // 最短距離を求める

  ll count = 1;

  vector<int> ans(N);
  FOR(i, 0, N) ans[i] = 0;

  FOR(i, 1, N) {
    FOR(j, i + 1, N + 1) {

      if (j <= X || Y <= i) {
        // cout << j-i << endl;
        ans[j - i]++;
      } else {
        ll mindis = min(abs(j - i), (abs(X - i) + 1 + abs(j - Y)));
        // cout << mindis << endl;
        ans[mindis]++;
      }
    }
  }

  FOR(i, 1, N) cout << ans[i] << endl;

  // count = 0;

  /*FOR(i, 1, N+1){
      FOR(j, i+1, N+1){
          ll mindis = min(abs(j - i), (abs(X - i) + 1 + abs(j - Y)));
          if(mindis == k) count++;
      }
  }*/

  // cout << count << endl;

  // FOR(k, k, N) cout << '0' << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

typedef long long ll;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++) // no semicoron
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i > 0; i--)
#define FORD(i, a, b) for (ll i = (a); i > (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく

using namespace std;

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

  // 最短距離を求める

  ll count;

  FOR(k, 1, N) {

    count = 0;

    FOR(i, 1, N + 1) {
      FOR(j, i + 1, N + 1) {
        ll mindis = min(abs(j - i), (abs(X - i) + 1 + abs(j - Y)));
        if (mindis == k)
          count++;
      }
    }

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

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

ll memo[20001][20001]; // 各点の最短距離を記録したもの

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

  rep(i, n) {
    rep(j, n) { memo[i][j] = -1; }
  }
  rep(i, n - 1) {

    memo[i][i] = 0;
    memo[i][i + 1] = 1;
    memo[i + 1][i] = 1;
  }
  memo[n - 1][n - 1] = 0;
  memo[x][y] = 1;
  memo[y][x] = 1;

  for (ll k = 2; k < n; k++) {
    for (ll i = 0; i < n - 2; i++) {
      if (memo[i][i + k] != -1) {
        continue;
      }

      ll p = min(memo[i][i + k - 1], memo[i + 1][i + k]);
      ll j = labs(i - x) + labs(i + k - y);
      ll h = labs(i - y) + labs(i + k - x);
      ll g = min(p + 1, j + 1);

      memo[i][i + k] = min(g, h + 1);
      memo[i + k][i] = min(g, h + 1);
    }
  }
  map<ll, ll> score;
  rep(i, n) {
    rep(j, n) { score[memo[i][j]] += 1; }
  }

  rep(i, n - 1) { cout << score[i + 1] / 2 << endl; }
}

Error: 0

Fixed submission:

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

ll memo[2001][2001]; // 各点の最短距離を記録したもの

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

  rep(i, n) {
    rep(j, n) { memo[i][j] = -1; }
  }
  rep(i, n - 1) {

    memo[i][i] = 0;
    memo[i][i + 1] = 1;
    memo[i + 1][i] = 1;
  }
  memo[n - 1][n - 1] = 0;
  memo[x][y] = 1;
  memo[y][x] = 1;

  for (ll k = 2; k < n; k++) {
    for (ll i = 0; i < n - 2; i++) {
      if (memo[i][i + k] != -1) {
        continue;
      }

      ll p = min(memo[i][i + k - 1], memo[i + 1][i + k]);
      ll j = labs(i - x) + labs(i + k - y);
      ll h = labs(i - y) + labs(i + k - x);
      ll g = min(p + 1, j + 1);

      memo[i][i + k] = min(g, h + 1);
      memo[i + k][i] = min(g, h + 1);
    }
  }
  map<ll, ll> score;
  rep(i, n) {
    rep(j, n) { score[memo[i][j]] += 1; }
  }

  rep(i, n - 1) { cout << score[i + 1] / 2 << endl; }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(), s.end(), s.begin(), ::tolower);
#define transup transform(s.begin(), s.end(), s.begin(), ::toupper);
#define endl "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;
ll n;
vector<ll> adj[100000];

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

          cin >>
      n;
  vector<ll> ans;
  ans.resize(n + 1, 0);
  vector<ll> adj[n + 1];
  for (ll i = 1; i < n; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  ll x, y;
  cin >> x >> y;
  adj[x].pb(y);
  adj[y].pb(x);

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

    queue<ll> q;
    ll source = i;
    q.push(source);
    vector<ll> dist(n + 1, -1);
    dist[source] = 0;
    while (!q.empty()) {
      ll cn = q.front();
      q.pop();
      for (auto it : adj[cn]) {
        if (dist[it] == -1) {
          dist[it] = dist[cn] + 1;
          q.push(it);
        }
      }
    }

    for (ll i = 1; i <= n; i++) {
      ans[dist[i]] += 1;
    }
  }
  for (ll i = 1; i < n; i++)
    cout << ans[i] / 2 << " ";

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(), s.end(), s.begin(), ::tolower);
#define transup transform(s.begin(), s.end(), s.begin(), ::toupper);
#define endl "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;
ll n;
vector<ll> adj[10000];

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

  cin >> n;
  vector<ll> ans;
  ans.resize(n + 1, 0);
  vector<ll> adj[n + 1];
  for (ll i = 1; i < n; i++) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  ll x, y;
  cin >> x >> y;
  adj[x].pb(y);
  adj[y].pb(x);

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

    queue<ll> q;
    ll source = i;
    q.push(source);
    vector<ll> dist(n + 1, -1);
    dist[source] = 0;
    while (!q.empty()) {
      ll cn = q.front();
      q.pop();
      for (auto it : adj[cn]) {
        if (dist[it] == -1) {
          dist[it] = dist[cn] + 1;
          q.push(it);
        }
      }
    }

    for (ll i = 1; i <= n; i++) {
      ans[dist[i]] += 1;
    }
  }
  for (ll i = 1; i < n; i++)
    cout << ans[i] / 2 << " ";

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

#include <bits/stdc++.h>

using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  const int max_n = 2 * 1e3;

  // vector<vector<int>> dis(max_n+1, vector<int>(max_n));
  // for(int i = 0; i < n; i++){
  //   for(int j = i + 1; j < n; j++){
  //     dis[i][j] = min(j - i, abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 +
  //     abs(j - x));
  //   }
  // }
  // for(int i = 0; i < n; i++){
  //   for(int j = i + 1; j < n; j++){
  //     if(min(j - 1, abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
  //     == i){

  //     }
  //   }

  // }

  vector<vector<int>> map(max_n + 1);
  for (int i = 0; i < n - 1; i++) {
    map[i].push_back(i + 1);
    map[i + 1].push_back(i);
  }
  map[x - 1].push_back(y - 1);
  map[y - 1].push_back(x - 1);

  // calculate distance to all node from node i
  vector<vector<int>> seen(max_n + 1, vector<int>(max_n + 1, -1));
  for (int i = 0; i < n; i++) {
    queue<int> todo;
    todo.push(i);
    seen[i][i] = 0;
    int now;
    while (!todo.empty()) {
      now = todo.front();
      todo.pop();

      for (auto next : map[now]) {
        if (seen[i][next] == -1) {
          seen[i][next] = seen[i][now] + 1;
          todo.push(next);
        }
      }
    }
  }

  int count[max_n + 1] = {};

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      count[seen[i][j]]++;
    }
  }
  // cout << count / 2 << endl;
  for (int k = 1; k < n; k++) {
    cout << count[k] / 2 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  const int max_n = 2 * 1e3;

  vector<vector<int>> map(max_n + 1);
  for (int i = 0; i < n - 1; i++) {
    map[i].push_back(i + 1);
    map[i + 1].push_back(i);
  }
  map[x - 1].push_back(y - 1);
  map[y - 1].push_back(x - 1);

  // calculate distance to all node from node i
  vector<vector<int>> seen(max_n + 1, vector<int>(max_n + 1, -1));
  for (int i = 0; i < n; i++) {
    queue<int> todo;
    todo.push(i);
    seen[i][i] = 0;
    int now;
    while (!todo.empty()) {
      now = todo.front();
      todo.pop();

      for (auto next : map[now]) {
        if (seen[i][next] == -1) {
          seen[i][next] = seen[i][now] + 1;
          todo.push(next);
        }
      }
    }
  }

  int count = 0;
  for (int k = 1; k < n; k++) {
    count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (seen[i][j] == k)
          count++;
      }
    }
    cout << count / 2 << 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() {

  int n, x, y;
  cin >> n >> x >> y;
  if (x > y) {
    swap(x, y);
  }
  x--;
  y--;
  vector<int> ans(n, 0);

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int dis = min(j - i, abs(j - y) + 1 + abs(i - x));

      ans[dis]++;
    }
  }

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

  int l;
  cin >> l;
}

Error: TLE

Fixed submission:

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

vector<vector<int>> g;
int curr;
unordered_set<int> check;

void dfs1(int i, int k) {
  if (k == 1) {
    return;
  }
  for (auto it : g[i]) {
    check.insert(it);
    dfs1(it, k - 1);
  }
}

int dfs(int i, int k) {
  int sum = 0;
  if (k == 1) {
    for (int z = 0; z < g[i].size(); z++) {
      int p = check.size();
      check.insert(g[i][z]);
      if (check.size() > p && (g[i][z] > curr)) {
        sum++;
      }
    }
    return sum;
  }

  else {
    for (auto it : g[i]) {
      sum += dfs(it, k - 1);
    }
    return (sum);
  }
}

int main() {

  int n, x, y;
  cin >> n >> x >> y;
  g = vector<vector<int>>(n);

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

  if (y > x) {
    g[x - 1].push_back(y - 1);
    g[y - 1].push_back(x - 1);
  } else {
    g[y - 1].push_back(x - 1);
    g[x - 1].push_back(y - 1);
  }

  for (int j = 1; j < n; j++) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      curr = i;
      dfs1(i, j);
      sum += dfs(i, j);
      check.clear();
    }
    cout << sum << endl;
  }

  int l;
  cin >> l;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n + 1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n + 1); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define repr3(i, n) for (ll i = (n); i > 0; i--)
#define repr4(i, s, n) for (ll i = (n); i >= (s); i--)
#define stlen(s) ll s.size() - 1
#define all(v) v.begin(), v.end()
#define cout(n) cout << std::fixed << std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll, ll>>>;
#define INF1 INT_MAX;
#define INF2 LLONG_MAX;
#define PI 3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/

int main() {
  int N, X, Y;
  map<int, int> dist_map;
  cin >> N >> X >> Y;
  rep3(i, N - 1) {
    rep4(j, i + 1, N) {
      int dist;
      dist = min(j - i, abs(j - Y) + abs(i - X) + 1);
      dist_map[dist]++;
    }
  }
  rep3(i, N - 1) { cout << dist_map[i] << endl; }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n + 1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n + 1); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define repr3(i, n) for (ll i = (n); i > 0; i--)
#define stlen(s) ll s.size() - 1
#define all(v) v.begin(), v.end()
#define cout(n) cout << std::fixed << std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1 INT_MAX;
#define INF2 LLONG_MAX;
#define PI 3.14159265358979323846;

int main() {
  ll N, X, Y, count = 0;
  cin >> N >> X >> Y;
  int count_[N];
  rep(i, N) { count_[i] = 0; }
  rep3(k, N - 1) {
    rep3(i, N - k) {
      rep4(j, i + k, N) {
        int mindist = min(j - i, abs(j - Y) + abs(i - X) + 1);
        if (mindist == k)
          count_[k]++;
      }
    }
  }
  rep3(i, N - 1) { cout << count_[i] << endl; }

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

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<vector<int>> a(n);
  vector<int> b(n, 0);
  for (int i = 0; i < n; ++i) {
    a[i] = b;
  }
  b.clear();
  vector<int> cnt(n - 1, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (i < x) {
        if (j <= x) {
          a[i][j] = j - i;
        } else if (j >= y) {
          a[i][j] = x - i + 1 + j - y;
        } else {
          a[i][j] = min(j - i, x - i + 1 + y - j);
        }
      } else if (i == x) {
        if (j == y) {
          a[i][j] = 1;
        } else if (j > y) {
          a[i][j] = 1 + j - y;
        } else {
          a[i][j] = min(y - j + 1, j - i);
        }
      } else if (i == y) {
        a[i][j] = j - i;
      } else if (i > y) {
        a[i][j] = j - i;
      } else {
        if (j >= y) {
          a[i][j] = min(j - i, i - x + 1 + j - y);
        } else {
          a[i][j] = min(j - i, i - x + 1 + y - j);
        }
      }
      ++cnt[a[i][j] - 1];
    }
  }
  for (int i : cnt) {
    cout << i << "\\n";
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  vector<vector<int>> a(n);
  vector<int> b(n, 0);
  for (int i = 0; i < n; ++i) {
    a[i] = b;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (i < x) {
        if (j <= x) {
          a[i][j] = j - i;
        } else if (j >= y) {
          a[i][j] = x - i + 1 + j - y;
        } else {
          a[i][j] = min(j - i, x - i + 1 + y - j);
        }
      } else if (i == x) {
        if (j == y) {
          a[i][j] = 1;
        } else if (j > y) {
          a[i][j] = 1 + j - y;
        } else {
          a[i][j] = min(y - j + 1, j - i);
        }
      } else if (i == y) {
        a[i][j] = j - i;
      } else if (i > y) {
        a[i][j] = j - i;
      } else {
        if (j >= y) {
          a[i][j] = min(j - i, i - x + 1 + j - y);
        } else {
          a[i][j] = min(j - i, i - x + 1 + y - j);
        }
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    int cnt = 0;
    for (int j = 0; j < n; ++j) {
      cnt += count(a[j].begin(), a[j].end(), i);
    }
    cout << cnt << "\\n";
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

int n, x, y;
int all[20005];

int main() {

  cin >> n >> x >> y;

  for (int i = 1; i <= n; i++)
    all[i] = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist1 = abs(j - i);
      int dist2 = abs(x - i) + 1 + abs(j - y);
      int min_dist = min(dist1, dist2);
      all[min_dist]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << all[i] << '\\n';
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

int n, x, y;
int all[1005];

int main() {

  cin >> n >> x >> y;

  for (int i = 1; i <= n; i++)
    all[i] = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int dist1 = abs(j - i);
      int dist2 = abs(x - i) + 1 + abs(j - y);
      int min_dist = min(dist1, dist2);
      all[min_dist]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << all[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 < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  vector<int> freq(n);
  rep(i, n) rep(j, n) {
    if (i < j) {
      int dist = min(
          j - i, min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)));
      freq[dist]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << freq[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>;

const ll INF = 1e11;
const int MAX_N = 2e3 + 1;
ll dp[MAX_N][MAX_N];

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--, y--;
  rep(i, n) rep(j, n) if (i != j) dp[i][j] = INF;
  rep(i, n - 1) {
    dp[i][i + 1] = 1;
    dp[i + 1][i] = 1;
  }
  dp[x][y] = 1;
  rep(i, n) rep(j, n) rep(k, n) {
    if (dp[j][i] != INF && dp[i][k] != INF)
      dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
  }

  vector<int> freq(n);
  rep(i, n) rep(j, n) if (i < j) freq[dp[i][j]]++;
  for (int i = 1; i < n; i++)
    cout << freq[i] << endl;

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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

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

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

void warshall_floyd(vector<vector<int>> &G) {
  int n = G.size();
  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() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int>> G(N, vector<int>(N));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      G[i][j] = INF;
      if (i == j)
        G[i][j] = 0;
      if (j == i + 1)
        G[i][j] = 1;
      if (i == j + 1)
        G[i][j] = 1;
      if (i == (X - 1) && j == (Y - 1))
        G[i][j] = 1;
      if (j == (X - 1) && i == (Y - 1))
        G[i][j] = 1;
    }
  }

  warshall_floyd(G);

  vector<int> counts(N, 0);
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ++counts[G[i][j]];
    }
  }
  for (int k = 1; k < N; ++k) {
    cout << counts[k] << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<vector<int>> G;
vector<int> dist, ans;

void bfs(int now) {
  rep(i, dist.size()) dist.at(i) = INF;
  queue<int> que;
  que.push(now);
  dist[now] = 0;
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : G[v]) {
      if (dist[nv] > dist[v] + 1)
        dist[nv] = dist[v] + 1;
      else
        continue;
      que.push(nv);
    }
  }
  rep(i, dist.size()) {
    if (dist[i] == INF)
      continue;
    ans[dist[i]]++;
  }
}

signed main(void) {
  int n, x, y;

  cin >> n >> x >> y;
  --x;
  --y;
  G.resize(n);
  dist.resize(n);
  ans.resize(n);
  rep(i, n) ans.at(i) = 0;
  rep(i, n - 1) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[x].push_back(y);
  G[y].push_back(x);
  rep(i, n) bfs(i);
  for (int i = 1; i < n; i++)
    cout << ans.at(i) / 2 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

signed main(void) {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  int v[n][n];
  int ans[n];
  rep(i, n) rep(j, n) v[i][j] = INF;
  rep(i, n - 1) {
    v[i][i + 1] = 1;
    v[i + 1][i] = 1;
  }
  v[x][y] = 1;
  v[y][x] = 1;
  rep(i, n) v[i][i] = 0;
  rep(i, n) ans[i] = 0;
  rep(k, n)     // via
      rep(i, n) // from
      rep(j, n) // to
      v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
  rep(i, n) for (int j = i + 1; j < n; j++) ans[v[i][j]]++;
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}