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

#include <bits/stdc++.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pdouble;

const int INF = 2000000000;
const int MOD = 1000000007;

const int MAX_N = 2010;
const int MAX_M = 2010;
ll d[MAX_N][MAX_M + 1];

void warshall_floyd(int n) {
  for (int k = 1; k <= n; k++) {     // 経由する頂点
    for (int i = 1; i <= n; i++) {   // 始点
      for (int j = 1; j <= n; j++) { // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

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

  ll s = y - x;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      d[i][j] = 0;
    }
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      ll pi = abs(i - x);
      ll pj = abs(j - y);
      ll m, n;
      m = pi + pj + 1;
      n = j - i;
      d[i][j] = min(m, n);
    }
  }

  vector<ll> kyori(n, 0);
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      kyori.at(d[i][j])++;
    }
  }

  /*for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      cout << d[i][j] << " ";
    }
    cout << endl;
  }*/

  for (int i = 1; i <= n - 1; i++) {
    cout << kyori.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pdouble;

const int INF = 2000000000;
const int MOD = 1000000007;

const int MAX_N = 2010;
const int MAX_M = 2010;
ll d[MAX_N][MAX_M + 1];

void warshall_floyd(int n) {
  for (int k = 1; k <= n; k++) {     // 経由する頂点
    for (int i = 1; i <= n; i++) {   // 始点
      for (int j = 1; j <= n; j++) { // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

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

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) {
        d[i][j] = 0;
      } else if (abs(i - j) == 1) {
        d[i][j] = 1;
      } else if ((i == x && j == y) || (i == y && j == x)) {
        d[i][j] = 1;
      } else {
        d[i][j] = INF;
      }
    }
  }

  warshall_floyd(n);
  vector<ll> kyori(n, 0);
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      kyori.at(d[i][j])++;
    }
  }

  for (int i = 1; i <= n - 1; i++) {
    cout << kyori.at(i) << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = s; i < n; i++)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
const ll inf = pow(2, 31) - 1;
int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vll ans(n, 0);
  vvll d(n, vll(n, inf));
  rep(i, n - 1) {
    d[i][i] = 0;
    d[i][i + 1] = d[i + 1][i] = 1;
  }
  d[n - 1][n - 1] = 0;
  d[x][y] = d[y][x] = 1;

  rep(i, n) REP(j, i, n) {
    d[i][j] = min((ll)abs(i - j), abs(i - x) + 1 + abs(j - y));
  }
  rep(i, n) REP(j, i, n) ans[d[i][j]]++;
  rep(i, n - 1) cout << ans[i + 1] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = s; i < n; i++)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
const ll inf = pow(2, 31) - 1;
int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  vll ans(n, 0);
  vvll d(n, vll(n, inf));
  rep(i, n - 1) {
    d[i][i] = 0;
    d[i][i + 1] = d[i + 1][i] = 1;
  }
  d[n - 1][n - 1] = 0;
  d[x - 1][y - 1] = d[y - 1][x - 1] = 1;

  rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  rep(i, n) {
    REP(j, i, n) {
      if (d[i][j] < n)
        ans[d[i][j]]++;
      // cout << d[i][j] << " ";
    }
    // cout << endl;
  }
  rep(i, n - 1) cout << ans[i + 1] << endl;
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int abs(int n) {
  if (n < 0)
    return -n;
  return n;
}

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> d(n, vector<int>(n, n));
  for (int i = 0; i < n - 1; i++) {
    d[i][i] = 0;
    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]);
      }
    }
  }
  vector<int> ans(n - 1);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int a = d[i][j];
      if (0 < a && a < n) {
        ans[a - 1]++;
      }
    }
  }
  for (int i = 0; i < n - 1; i++)
    cout << ans[i] << endl;

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


/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define setbits(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 2e3 + 5;
const int mod = 1e9 + 7;

int n, x, y;
int dist[N][N];
vector<int> v[N];
void bfs(int x) {
  queue<int> q;
  q.push(x);
  vector<int> d(n + 5, 1e9);
  d[x] = 0;
  int src = x;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    for (int i : v[x]) {
      if (d[i] > d[x] + 1) {
        d[i] = d[x] + 1;
        q.push(i);
      }
    }
  }
  rep(i, 1, n) dist[src][i] = d[i];
}
signed main() {
  FastIO;
  cin >> n >> x >> y;
  rep(i, 1, n - 1) {
    v[i].pb(i + 1);
    v[i + 1].pb(i);
  }
  v[x].pb(y);
  v[y].pb(x);
  rep(i, 1, n) bfs(i);
  map<int, int> m;
  rep(i, 1, n) rep(j, 1, n) m[dist[i][j]]++;
  rep(i, 1, n - 1) cout << m[i] / 2 << '\\n';
  return 0;
}


Error: TLE

Fixed submission:


/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define setbits(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 2e3 + 5;
const int mod = 1e9 + 7;

int n, x, y;
int dist[N][N];
signed main() {
  FastIO;
  cin >> n >> x >> y;
  rep(i, 1, n) rep(j, 1, n) if (i != j) dist[i][j] = 1e9;
  rep(i, 1, n - 1) {
    dist[i][i + 1] = 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++) {
        if (dist[i][k] + dist[k][j] < dist[i][j])
          dist[i][j] = dist[i][k] + dist[k][j];
      }
    }
  }
  map<int, int> m;
  rep(i, 1, n) rep(j, 1, n) m[dist[i][j]]++;
  rep(i, 1, n - 1) cout << m[i] / 2 << '\\n';
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 2 * 1e3 + 10;
#define inf 99999999
int dis[maxn][maxn];
int a[maxn];
int k, n;
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)
      dis[i][j] = inf;
  for (int i = 1; i < n; ++i) {
    dis[i][i] = 0;
    dis[i][i + 1] = 1;
    dis[i + 1][i] = 1;
  }
  dis[n][n] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      dis[j][i] = dis[i][j] = j - i;
  dis[x][y] = 1;
  if (x > y)
    swap(x, y);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      dis[i][j] = min(dis[i][j], dis[i][x] + 1 + dis[y][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j) {
      a[dis[i][j]]++;
    }
  // cout<<dis[1][7]<<dis[1][6];
  for (int i = 1; i < n; ++i)
    printf("%d\\n", a[i]);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 2 * 1e3 + 10;
#define inf 99999999
int dis[maxn][maxn];
int a[maxn];
int k, n;
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)
      dis[i][j] = inf; // fd[0][0]=0;
  for (int i = 1; i < n; ++i) {
    dis[i][i] = 0;
    dis[i][i + 1] = 1;
    dis[i + 1][i] = 1;
  }
  dis[n][n] = 0;
  dis[x][y] = 1;
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j) {
      // cout<<dis[i][j];
      a[dis[i][j]]++;
    }
  for (int i = 1; i < n; ++i)
    printf("%d\\n", a[i]);
  // printf("\\n");
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

// #define int long long

using namespace std;

void Main() {
  int n, x, y;
  cin >> n >> x >> y;

  // 1 <= i < i2 <= n
  // i -> i2
  // i -> x -> y ->i2
  // i -> y -> x ->i2
  vector<int> ans(n, 0);
  for (int i = 1; i <= n - 1; i++) {
    for (int i2 = i + 1; i2 <= n; i2++) {
      int dist1 = i2 - i;
      int dist2 = abs(x - i) + 1 + abs(y - i2);
      int dist3 = abs(y - i) + 1 + abs(x - i2);
      int dist = min(min(dist1, dist2), dist3);
      ans[dist]++;
    }
  }

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

int32_t main() {
  Main();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

// #define int long long

using namespace std;

void Main() {
  int n, x, y;
  cin >> n >> x >> y;

  // 1 <= i < i2 <= n
  // i -> i2
  // i -> x -> y ->i2
  // i -> y -> x ->i2
  vector<int> dist_list;
  int dist_max = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int i2 = i + 1; i2 <= n; i2++) {
      int dist1 = i2 - i;
      int dist2 = abs(x - i) + 1 + abs(y - i2);
      int dist3 = abs(y - i) + 1 + abs(x - i2);
      int dist = min(min(dist1, dist2), dist3);
      dist_list.push_back(dist);
      dist_max = max(dist_max, dist);
    }
  }

  for (int i = 1; i <= n - 1; i++) {
    cout << count(dist_list.begin(), dist_list.end(), i) << endl;
  }
}

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

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

void printq(queue<int> que) {
  while (!que.empty()) {
    cout << que.front() << " ";
    que.pop();
  }
  cout << endl;
}

int main(void) {
  int n, x, y;
  cin >> n >> x >> y;
  queue<int> que;
  vector<vector<int>> g(n + 1);
  g[x].push_back(y);
  g[y].push_back(x);
  g[1].push_back(2);
  g[n].push_back(n - 1);
  for (int i = 2; i <= n - 1; i++) {
    g[i].push_back(i - 1);
    g[i].push_back(i + 1);
  }
  vector<int> ans(n, 0);
  for (int i = 1; i <= n; i++) {
    vector<bool> visit(n + 1, false);
    visit[i] = true;
    que.push(i);
    vector<int> dist(n + 1, 0);
    int count = 1;
    while (count < n) {
      // printq(que);
      int v = que.front();
      // printf("v %d\\n", v);
      que.pop();
      for (int j : g[v]) {
        if ((v == j + 1 || v == j - 1 || (v == x && j == y) ||
             (v == y && j == x)) &&
            !visit[j]) {
          // printf("visit %d from %d\\n", j, v);
          que.push(j);
          visit[j] = true;
          count++;
          dist[j] = dist[v] + 1;
        }
      }
    }
    while (!que.empty())
      que.pop();
    for (int j = i + 1; j <= n; j++) {
      ans[dist[j]]++;
      // printf("%d -> %d : %d\\n", i, j, dist[j]);
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int n, x, y;
  cin >> n >> x >> y;
  queue<int> que;
  vector<bool> visit(n + 1, false);
  vector<int> ans(n, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++)
      visit[j] = false;
    visit[i] = true;
    que.push(i);
    vector<int> dist(n + 1, 0);
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (int j = 1; j <= n; j++) {
        if ((v == j + 1 || v == j - 1 || (v == x && j == y) ||
             (v == y && j == x)) &&
            !visit[j]) {
          que.push(j);
          visit[j] = true;
          dist[j] = dist[v] + 1;
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      ans[dist[j]]++;
    }
  }
  for (int i = 1; i < n; i++) {
    cout << ans[i] / 2 << endl;
  }
  return 0;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

template <typename T> struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T> void warshall_floyd(Matrix<T> &g, T INF) {
  for (int k = 0; k < g.size(); k++) {
    for (int i = 0; i < g.size(); i++) {
      for (int j = 0; j < g.size(); j++) {
        if (g[i][k] == INF || g[k][j] == INF)
          continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

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

  Matrix<int> mat(n, vector<int>(n, INT_MAX));
  for (int i = 0; i < n; i++)
    mat[i][i] = 0;
  for (int i = 0; i < n - 1; i++) {
    mat[i][i + 1] = 1;
    mat[i + 1][i] = 1;
  }
  mat[x][y] = 1;
  mat[y][x] = 1;
  warshall_floyd(mat, INT_MAX);
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (mat[i][j] < n) {
        ans[(mat[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>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int n;
ll d[2003][2003];
int x, y;

void floyd() {
  rep(i, n) {
    if (d[i][x - 1] == INF)
      continue;
    rep(j, n) {
      if (d[x - 1][j] == INF)
        continue;
      chmin(d[i][j], d[i][x - 1] + d[x - 1][j]);
    }
  }

  rep(i, n) {
    if (d[i][y - 1] == INF)
      continue;
    rep(j, n) {
      if (d[y - 1][j] == INF)
        continue;
      chmin(d[i][j], d[i][y - 1] + d[y - 1][j]);
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x >> y;
  rep(i, n) rep(j, n) { d[i][j] = abs(i - j); }
  d[x - 1][y - 1] = 1;
  floyd();
  map<int, int> mp;
  rep(i, n) for (int j = i + 1; j < n; j++) { mp[d[i][j]]++; }
  rep(i, n - 1) { cout << mp[i + 1] << endl; }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int n;
ll d[2003][2003];

void floyd() {
  rep(k, n) rep(i, n) {
    if (d[i][k] == INF)
      continue;
    rep(j, n) {
      if (d[k][j] == INF)
        continue;
      chmin(d[i][j], d[i][k] + d[k][j]);
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, y;
  cin >> n >> x >> y;
  rep(i, n) rep(j, n) d[i][j] = (i == j) ? 0 : INF;
  rep(i, n) {
    if (i != n - 1) {
      d[i][i + 1] = 1;
      d[i + 1][i] = 1;
    }
  }
  d[x - 1][y - 1] = 1;
  floyd();
  map<int, int> mp;
  rep(i, n) for (int j = i + 1; j < n; j++) { mp[d[i][j]]++; }
  rep(i, n - 1) { cout << mp[i + 1] << endl; }

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  int count = 0;
  int kyori;
  for (int k = 1; k <= N - 1; k++) {
    count = 0;
    for (int i = 1; i <= N - k; i++) {
      for (int j = i + 1; j <= N; j++) {
        int A = abs(X - i);
        int B = abs(j - Y);
        kyori = min(j - i, A + B + 1);
        if (kyori == k) {
          count++;
        }
      }
    }
    cout << count << endl;
  }
}
Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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)
        return;
      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]]++;
  }
  rep(i, n) ans[i] /= 2;
  for (int i = 1; i <= n - 1; i++) {
    cout << ans[i] << endl;
  }
}

Error: -11

Fixed submission:

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  int xy = x + y;
  vector<int> p(a);
  vector<int> q(b);
  vector<int> r(c);
  for (int i = 0; i < a; i++) {
    cin >> p.at(i);
  }
  for (int i = 0; i < b; i++) {
    cin >> q.at(i);
  }
  for (int i = 0; i < c; i++) {
    cin >> r.at(i);
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  p.erase(p.begin() + x + 1, p.end());
  q.erase(q.begin() + y + 1, q.end());
  p.insert(p.end(), q.begin(), q.end());
  p.insert(p.end(), r.begin(), r.end());
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  int count = 0;
  for (int i = 0; i < xy; i++) {
    count += p.at(i);
  }
  cout << count << endl;
}
Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> cnt(N);
  for (int i = 1; i < N; i++) {
    for (int j = i + 1; j <= N; j++) {
      int k = min(abs(i - j), min(abs(i - X) + abs(j - Y) + 1,
                                  abs(i - Y) + abs(j - X) + 1));
      cnt[k]++;
    }
  }
  for (int k = 1; k < N; k++)
    cout << cnt[k] << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> cnt(N);
  for (int i = 1; i <= N; i++) {
    vector<int> dist(N + 1, -1);
    dist[i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      if (v > 1 && dist[v - 1] == -1) {
        dist[v - 1] = dist[v] + 1;
        q.push(v - 1);
      }
      if (v < N && dist[v + 1] == -1) {
        dist[v + 1] = dist[v] + 1;
        q.push(v + 1);
      }
      if (v == X && dist[Y] == -1) {
        dist[Y] = dist[v] + 1;
        q.push(Y);
      }
      if (v == Y && dist[X] == -1) {
        dist[X] = dist[v] + 1;
        q.push(X);
      }
    }
    for (int k = 1; k < N; k++)
      cnt[k] += count(ALL(dist), k);
  }
  for (int k = 1; k < N; k++)
    cout << cnt[k] / 2 << '\\n';
}