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 < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\\n"
#define dbv(vec)                                                               \\
  cerr << #vec << ":";                                                         \\
  for (auto e : vec)                                                           \\
    cerr << e << " ";                                                          \\
  cout << "\\n"
#define dbvv(vv)                                                               \\
  cerr << #vv << ":\\n";                                                        \\
  for (auto vec : vv) {                                                        \\
    for (auto e : vec)                                                         \\
      cerr << e << " ";                                                        \\
    cerr << endl;                                                              \\
  }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int N, X, Y;

int d(int i, int j) {
  /*
  int res = min(j - i, abs(i - X) + 1 + abs(j - Y));
  db(i); db(j); dbl(res);
  return res;
  */
  return min(j - i, abs(i - X) + 1 + abs(j - Y));
}

int main() {
  cin >> N >> X >> Y;
  vi ans(N);
  rep2(k, 1, N) ans[k] = N - k;
  dbv(ans);
  rep2(i, 1, N) {
    rep2(j, i + 1, N + 1) {
      int p = d(i, j);
      if (j - i > p) {
        ans[j - i]--;
        ans[p]++;
      }
    }
  }
  dbv(ans);
  rep2(k, 1, N) { cout << ans[k] << endl; }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\\n"
#define dbv(vec)                                                               \\
  cerr << #vec << ":";                                                         \\
  for (auto e : vec)                                                           \\
    cerr << e << " ";                                                          \\
  cout << "\\n"
#define dbvv(vv)                                                               \\
  cerr << #vv << ":\\n";                                                        \\
  for (auto vec : vv) {                                                        \\
    for (auto e : vec)                                                         \\
      cerr << e << " ";                                                        \\
    cerr << endl;                                                              \\
  }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int N, X, Y;

int d(int i, int j) {
  int res = min(j - i, abs(i - X) + 1 + abs(j - Y));
  db(i);
  db(j);
  dbl(res);
  return res;
}

int main() {
  cin >> N >> X >> Y;
  vi ans(N);
  rep2(i, 1, N) {
    rep2(j, i + 1, N + 1) { ans[d(i, j)]++; }
  }
  dbv(ans);
  rep2(k, 1, N) { cout << ans[k] << endl; }
}