Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprep(i, j, w, h) rep(j, h) rep(i, w)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n)                                                     \
  std::vector<type> a(n);                                                      \
  rep(i, n) std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a)                                            \
  vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a)                                          \
  vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<int>(n, a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main() {
  string s;
  int x, y;
  std::cin >> s;
  std::cin >> x >> y;
  std::vector<int> dum;
  int c = 0;
  rep(i, s.size()) {
    if (s[i] == 'F')
      c++;
    else {
      dum.pb(c);
      c = 0;
    }
  }
  if (c != 0)
    dum.pb(c);
  std::vector<int> tate, yoko;
  x -= dum[0];
  rrep(i, 1, dum.size()) {
    if (pow(-1, i) == 1)
      yoko.pb(dum[i]);
    else
      tate.pb(dum[i]);
  }
  int ys = yoko.size(), ts = tate.size();
  vvector(ydp, bool, ys + 1, 20000, 0);
  vvector(tdp, bool, ts + 1, 20000, 0);
  ydp[0][10000] = 1;
  tdp[0][10000] = 1;
  rep(i, ts) {
    rep(j, 20000) {
      if (tdp[i][j]) {
        tdp[i + 1][j + tate[i]] = 1;
        tdp[i + 1][j - tate[i]] = 1;
      }
    }
  }
  rep(i, ys) {
    rep(j, 20000) {
      if (ydp[i][j]) {
        ydp[i + 1][j + yoko[i]] = 1;
        ydp[i + 1][j - yoko[i]] = 1;
      }
    }
  }
  if (x + 10000 > 19999) {
    std::cout << "No" << std::endl;
    exit(0);
  }
  if (ydp[ys][10000 + x] && tdp[ts][y + 10000])
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprep(i, j, w, h) rep(j, h) rep(i, w)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n)                                                     \
  std::vector<type> a(n);                                                      \
  rep(i, n) std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a)                                            \
  vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a)                                          \
  vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<int>(n, a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main() {
  string s;
  int x, y;
  std::cin >> s;
  std::cin >> x >> y;
  std::vector<int> dum;
  int c = 0;
  rep(i, s.size()) {
    if (s[i] == 'F')
      c++;
    else {
      dum.pb(c);
      c = 0;
    }
  }
  if (c != 0)
    dum.pb(c);
  std::vector<int> tate, yoko;
  x -= dum[0];
  rrep(i, 1, dum.size()) {
    if (pow(-1, i) == 1)
      yoko.pb(dum[i]);
    else
      tate.pb(dum[i]);
  }
  int ys = yoko.size(), ts = tate.size();
  vvector(ydp, bool, ys + 1, 20000, 0);
  vvector(tdp, bool, ts + 1, 20000, 0);
  ydp[0][10000] = 1;
  tdp[0][10000] = 1;
  rep(i, ts) {
    rep(j, 20000) {
      if (tdp[i][j]) {
        tdp[i + 1][j + tate[i]] = 1;
        tdp[i + 1][j - tate[i]] = 1;
      }
    }
  }
  rep(i, ys) {
    rep(j, 20000) {
      if (ydp[i][j]) {
        ydp[i + 1][j + yoko[i]] = 1;
        ydp[i + 1][j - yoko[i]] = 1;
      }
    }
  }
  if (x + 10000 > 19999 || x + 10000 < 0) {
    std::cout << "No" << std::endl;
    exit(0);
  }
  if (ydp[ys][10000 + x] && tdp[ts][y + 10000])
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}