Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define fr(j, p) for (int i = j; i < p; i++)
#define fastScan                                                               \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define inp(x, n) fr(0, n) cin >> x[i];
#define out(x, n) fr(0, n) cout << x[i] << " ";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define YESF                                                                   \\
  if (flag == 0)                                                               \\
    cout << "YES" << endl;                                                     \\
  else                                                                         \\
    cout << "NO" << endl;
#define yesf                                                                   \\
  if (flag == 0)                                                               \\
    cout << "Yes" << endl;                                                     \\
  else                                                                         \\
    cout << "No" << endl;
const long long md = 1e9 + 7;
using namespace std;
int main() {

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

  int dp[n][n];
  x--, y--;

  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < n; i++) {
    dp[i][i] = 0;
  }

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

  dp[x][y] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {

      int temp1 = x - i;
      int temp2 = j - y;

      if (temp1 >= 0 && temp2 >= 0) {
        dp[i][j] = 1 + temp1 + temp2;
      } else if (temp1 < 0 && temp2 >= 0) {
        dp[i][j] = min(i - x + 1 + temp2, j - i);

      } else if (temp1 >= 0 && temp2 < 0)
        dp[i][j] = min(j - i, 1 + temp1 - temp2);
      else
        dp[i][j] = min(j - i, 1 - temp1 - temp2);
    }
  }

  // for(int i=0; i<n ; i++){
  //   for(int j=0; j<n ; j++)
  //   {
  //     cout<<dp[i][j]<<" ";

  //   }
  //   cout<<endl;
  // }

  vector<int> ans(n, 0);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans[dp[i][j]]++;
    }
  }

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

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define fr(j, p) for (int i = j; i < p; i++)
#define fastScan                                                               \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define inp(x, n) fr(0, n) cin >> x[i];
#define out(x, n) fr(0, n) cout << x[i] << " ";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define YESF                                                                   \\
  if (flag == 0)                                                               \\
    cout << "YES" << endl;                                                     \\
  else                                                                         \\
    cout << "NO" << endl;
#define yesf                                                                   \\
  if (flag == 0)                                                               \\
    cout << "Yes" << endl;                                                     \\
  else                                                                         \\
    cout << "No" << endl;
const long long md = 1e9 + 7;
using namespace std;
int main() {

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

  int dp[n][n];
  x--, y--;

  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < n; i++) {
    dp[i][i] = 0;
  }

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

  dp[x][y] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {

      int temp1 = x - i;
      int temp2 = j - y;

      if (temp1 >= 0 && temp2 >= 0) {
        dp[i][j] = 1 + temp1 + temp2;
      } else if (temp1 < 0 && temp2 >= 0) {
        dp[i][j] = min(i - x + 1 + temp2, j - i);

      } else if (temp1 >= 0 && temp2 < 0)
        dp[i][j] = (j - i, 1 + temp1 - temp2);
      else
        dp[i][j] = min(j - i, 1 - temp1 - temp2);
    }
  }

  // for(int i=0; i<n ; i++){
  //   for(int j=0; j<n ; j++)
  //   {
  //     cout<<dp[i][j]<<" ";

  //   }
  //   cout<<endl;
  // }

  vector<int> ans(n, 0);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans[dp[i][j]]++;
    }
  }

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