Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  int X, Y;
  cin >> S >> X >> Y;
  int N = S.size();
  int initPos = S.find('T');
  if (initPos == (int)string::npos) {

    if (X == N)
      print("Yes");
    else {
      print("No");
    }

    return 0;
  } else {
    // DEBUG(S);
    // DEBUG(initPos);
    X -= initPos;
    int dtype = 0; // xtype
    vec<vec<int>> xyLis(2, vec<int>());
    int cnt = 0;
    S.pb('T');
    int xyLisSum[2] = {0, 0};
    FOR(i, initPos, (int)S.size()) {
      if (S[i] == 'T') {
        if (cnt != 0) {
          xyLis[dtype].pb(cnt);
          xyLisSum[dtype] += cnt;
          cnt = 0;
        }
        dtype++;
        dtype %= 2;
      } else {
        cnt++;
      }
    }
    //
    int sx = xyLisSum[0] - X;
    int sy = xyLisSum[1] - Y;

    if (sx % 2 == 0 && sy % 2 == 0) {
      sx /= 2;
      sy /= 2;
      // DEBUG(sx);
      // DEBUG(sy);
      // PRINTALL(xyLis[0]);
      // PRINTALL(xyLis[1]);

      vec<bool> flgX(sx + 1, false);
      flgX[sx] = true;
      FORA(e, xyLis[0]) {
        REPS(i, sx) {
          if (flgX[i] && i - e >= 0) {
            if (!flgX[i - e]) {
              flgX[i - e] = true;
            }
          }
        }
      }

      vec<bool> flgY(sy + 1, false);
      flgY[sy] = true;
      FORA(e, xyLis[1]) {
        REPS(i, sy) {
          if (flgY[i] && i - e >= 0) {
            if (!flgY[i - e]) {
              flgY[i - e] = true;
            }
          }
        }
      }

      if (flgX[0] && flgY[0]) {
        print("Yes");
      } else {
        print("No");
      }
    } else {
      print("No");
    }
    return 0;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  int X, Y;
  cin >> S >> X >> Y;
  int N = S.size();
  int initPos = S.find('T');
  if (initPos == (int)string::npos) {

    if (X == N)
      print("Yes");
    else {
      print("No");
    }

    return 0;
  } else {
    // DEBUG(S);
    // DEBUG(initPos);
    X -= initPos;
    int dtype = 0; // xtype
    vec<vec<int>> xyLis(2, vec<int>());
    int cnt = 0;
    S.pb('T');
    int xyLisSum[2] = {0, 0};
    FOR(i, initPos, (int)S.size()) {
      if (S[i] == 'T') {
        if (cnt != 0) {
          xyLis[dtype].pb(cnt);
          xyLisSum[dtype] += cnt;
          cnt = 0;
        }
        dtype++;
        dtype %= 2;
      } else {
        cnt++;
      }
    }
    //
    int sx = xyLisSum[0] - X;
    int sy = xyLisSum[1] - Y;

    if (sx % 2 == 0 && sy % 2 == 0 && sx >= 0 && sy >= 0) {
      sx /= 2;
      sy /= 2;
      // DEBUG(sx);
      // DEBUG(sy);
      // PRINTALL(xyLis[0]);
      // PRINTALL(xyLis[1]);

      vec<bool> flgX(sx + 1, false);
      flgX[sx] = true;
      FORA(e, xyLis[0]) {
        REPS(i, sx) {
          if (flgX[i] && i - e >= 0) {
            if (!flgX[i - e]) {
              flgX[i - e] = true;
            }
          }
        }
      }

      vec<bool> flgY(sy + 1, false);
      flgY[sy] = true;
      FORA(e, xyLis[1]) {
        REPS(i, sy) {
          if (flgY[i] && i - e >= 0) {
            if (!flgY[i - e]) {
              flgY[i - e] = true;
            }
          }
        }
      }

      if (flgX[0] && flgY[0]) {
        print("Yes");
      } else {
        print("No");
      }
    } else {
      print("No");
    }
    return 0;
  }
}