Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i))
#define repr(i, a, n) for (int(i) = (int)(a); (i) > (int)(n); --(i))
#define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a) % MOD) + ((b) % MOD)) % MOD)
#define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;

string s;
int x, y;
int tx, ty;
int cx[8010], cy[8010];
bool dpx[8010][2][8010];
bool dpy[8010][2][8010];

int sign(int x) { return x >= 0 ? 0 : 1; }

void makeDP() {
  int n = SIZE(s);
  int t = 0;
  rep(i, 0, n) {
    int d = 0;
    while (s[i] != 'T' && i < n)
      i++, d++;
    if (t % 2 == 0)
      cx[tx] = d, tx++;
    else
      cy[ty] = d, ty++;
    t++;
  }
  dpx[0][0][cx[0]] = true;
  dpy[0][0][cy[0]] = dpy[0][cy[0] ? 1 : 0][cy[0]] = true;
  rep(i, 1, tx) repe(j, -n, n) if (dpx[i - 1][sign(j)][abs(j)])
      dpx[i][sign(j + cx[i])][abs(j + cx[i])] =
          dpx[i][sign(j - cx[i])][abs(j - cx[i])] = true;
  rep(i, 1, ty) repe(j, -n, n) if (dpy[i - 1][sign(j)][abs(j)])
      dpy[i][sign(j + cy[i])][abs(j + cy[i])] =
          dpy[i][sign(j - cy[i])][abs(j - cy[i])] = true;
}

signed main() {
  cin >> s;
  cin >> x >> y;

  makeDP();

  if (dpx[tx - 1][sign(x)][abs(x)] && dpy[ty - 1][sign(y)][abs(y)])
    Yes;
  else
    No;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i))
#define repr(i, a, n) for (int(i) = (int)(a); (i) > (int)(n); --(i))
#define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a) % MOD) + ((b) % MOD)) % MOD)
#define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;

string s;
int x, y;
int tx, ty;
int cx[8010], cy[8010];
bool dpx[8010][2][8010];
bool dpy[8010][2][8010];

int sign(int x) { return x >= 0 ? 0 : 1; }

void makeDP() {
  int n = SIZE(s);
  int t = 0;
  rep(i, 0, n) {
    int d = 0;
    while (s[i] != 'T' && i < n)
      i++, d++;
    if (t % 2 == 0)
      cx[tx] = d, tx++;
    else
      cy[ty] = d, ty++;
    t++;
  }
  dpx[0][0][cx[0]] = true;
  dpy[0][0][cy[0]] = dpy[0][cy[0] ? 1 : 0][cy[0]] = true;
  rep(i, 1, tx) repe(j, -n, n) if (dpx[i - 1][sign(j)][abs(j)])
      dpx[i][sign(j + cx[i])][abs(j + cx[i])] =
          dpx[i][sign(j - cx[i])][abs(j - cx[i])] = true;
  rep(i, 1, ty) repe(j, -n, n) if (dpy[i - 1][sign(j)][abs(j)])
      dpy[i][sign(j + cy[i])][abs(j + cy[i])] =
          dpy[i][sign(j - cy[i])][abs(j - cy[i])] = true;
}

signed main() {
  cin >> s;
  cin >> x >> y;

  makeDP();

  if (dpx[max(tx - 1, 0)][sign(x)][abs(x)] &&
      dpy[max(ty - 1, 0)][sign(y)][abs(y)])
    Yes;
  else
    No;

  return 0;
}