Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable ":\\t" << (variable) << endl
#define LOGCON(i, container)                                                   \\
  for (int(i) = 0; (i) < (container).size(); ++(i))                            \\
  cout << (i) << ":\\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)       // from n to 0
#define REPRS(i, r, n) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj)                                                       \\
  for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj)                                                      \\
  for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

/***** MAIN *****/
signed main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x;
  --y;
  map<int, int> mp;
  int bridge = y - x;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int tmp = min(j - i, abs(x - i) + 1 + abs(j - y));
      ++mp[tmp];
    }
  }
  REP(i, n - 1) { cout << mp[i + 1] << endl; }
  return 0;
}
/***** MAIN *****/


Error: TLE

Fixed submission:

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable ":\\t" << (variable) << endl
#define LOGCON(i, container)                                                   \\
  for (int(i) = 0; (i) < (container).size(); ++(i))                            \\
  cout << (i) << ":\\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)       // from n to 0
#define REPRS(i, r, n) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj)                                                       \\
  for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj)                                                      \\
  for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
const int MAX = 2005;
int d[MAX][MAX];
int n, x, y;
void WarshallFloyd() {
  REP(i, n) REP(j, n) REP(k, n) { d[j][k] = min(d[j][k], d[j][i] + d[i][k]); }
}
signed main() {
  cin >> n >> x >> y;
  --x;
  --y;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j)
        continue;
      if (abs(i - j) == 1) {
        d[i][j] = 1;
        d[j][i] = 1;
      } else {
        d[i][j] = 5000;
        d[j][i] = 5000;
      }
    }
  }
  d[x][y] = 1;
  d[y][x] = 1;
  WarshallFloyd();
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ++mp[d[i][j]];
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    cout << mp[i + 1] << endl;
  }
  return 0;
}
/***** MAIN *****/