Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(a) a.begin(), a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template <class T, class U> inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s;
  cin >> s;
  s += 'T';
  int x, y;
  cin >> x >> y;
  x += 8000;
  y += 8000;
  vector<int> dx, dy;
  int n = s.size();
  int c = 0;
  bool fi = true;
  bool isx = true;
  rep(i, n) {
    if (s[i] == 'F')
      c++;
    else {
      if (fi) {
        x -= c;
        fi = false;
      } else if (isx)
        dx.pb(c);
      else
        dy.pb(c);
      c = 0;
      isx = !isx;
    }
  }
  vector<bitset<16000>> dpx(2010), dpy(2010);
  dpx[0][8000] = true;
  dpy[0][8000] = true;
  rep(i, dx.size()) dpx[i + 1] = (dpx[i] << dx[i]) | (dpx[i] >> dx[i]);
  rep(i, dy.size()) dpy[i + 1] = (dpy[i] << dy[i]) | (dpy[i] >> dy[i]);
  if (dpx[dx.size()][x] && dpy[dy.size()][y])
    cout << "Yes\n";
  else
    cout << "No\n";
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(a) a.begin(), a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template <class T, class U> inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s;
  cin >> s;
  s += 'T';
  int x, y;
  cin >> x >> y;
  x += 8000;
  y += 8000;
  vector<int> dx, dy;
  int n = s.size();
  int c = 0;
  bool fi = true;
  bool isx = true;
  rep(i, n) {
    if (s[i] == 'F')
      c++;
    else {
      if (fi) {
        x -= c;
        fi = false;
      } else if (isx)
        dx.pb(c);
      else
        dy.pb(c);
      c = 0;
      isx = !isx;
    }
  }
  if (x < 0) {
    cout << "No\n";
    return 0;
  }
  vector<bitset<16000>> dpx(10010), dpy(10010);
  dpx[0][8000] = true;
  dpy[0][8000] = true;
  rep(i, dx.size()) dpx[i + 1] = (dpx[i] << dx[i]) | (dpx[i] >> dx[i]);
  rep(i, dy.size()) dpy[i + 1] = (dpy[i] << dy[i]) | (dpy[i] >> dy[i]);
  if (dpx[dx.size()][x] && dpy[dy.size()][y])
    cout << "Yes\n";
  else
    cout << "No\n";
}