Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  string s;
  int x, y;
  cin >> s >> x >> y;
  int n = sz(s);
  s += 'T';

  vector<int> dx, dy;
  int cnt = 0;
  bool is_x = 1;
  for (int i = 0; i < n + 1; i++) {
    if (s[i] == 'F')
      cnt++;
    else {
      (is_x ? dx : dy).push_back(cnt);
      is_x ^= 1;
      cnt = 0;
    }
  }

  const int g = 17000;

  int p = sz(dx);
  vector<vector<bool>> dpx(p + 10, vector<bool>(34000));
  dpx[0][0 + g] = true;
  dpx[1][dx[0] + g] = true;
  for (int i = 1; i < p; i++) {
    for (int j = -8000; j <= 8000; j++) {
      dpx[i + 1][j + g] = (dpx[i][j - dx[i] + g] || dpx[i][j + dx[i] + g]);
    }
  }

  int q = sz(dy);
  vector<vector<bool>> dpy(p + 10, vector<bool>(20000));
  dpy[0][0 + g] = true;
  for (int i = 0; i < q; i++) {
    for (int j = -8000; j <= 8000; j++) {
      dpy[i + 1][j + g] = (dpy[i][j - dy[i] + g] || dpy[i][j + dy[i] + g]);
    }
  }

  cout << (dpx[p][x + g] && dpy[q][y + g] ? "Yes" : "No") << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
  string s;
  int x, y;
  cin >> s >> x >> y;
  int n = sz(s);
  s += 'T';

  vector<int> dx, dy;
  int cnt = 0;
  bool is_x = 1;
  for (int i = 0; i < n + 1; i++) {
    if (s[i] == 'F')
      cnt++;
    else {
      (is_x ? dx : dy).push_back(cnt);
      is_x ^= 1;
      cnt = 0;
    }
  }

  const int g = 17000;

  int p = sz(dx);
  vector<vector<bool>> dpx(p + 10, vector<bool>(34000));
  dpx[0][0 + g] = true;
  dpx[1][dx[0] + g] = true;
  for (int i = 1; i < p; i++) {
    for (int j = -8000; j <= 8000; j++) {
      dpx[i + 1][j + g] = (dpx[i][j - dx[i] + g] || dpx[i][j + dx[i] + g]);
    }
  }

  int q = sz(dy);
  vector<vector<bool>> dpy(p + 10, vector<bool>(34000));
  dpy[0][0 + g] = true;
  for (int i = 0; i < q; i++) {
    for (int j = -8000; j <= 8000; j++) {
      dpy[i + 1][j + g] = (dpy[i][j - dy[i] + g] || dpy[i][j + dy[i] + g]);
    }
  }

  cout << (dpx[p][x + g] && dpy[q][y + g] ? "Yes" : "No") << endl;
}