Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int px[6] = {0, 1, -1, 1, 0, 1}, py[6] = {-1, -1, 0, 0, 1, 1};
const int tx[8] = {-1, 0, 1, -1, 1, -1, 0, 1},
          ty[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

bool dpx[30000][8010], dpy[30000][8010];

int main() {
  string s;
  int x, y, now = 16000, fl = 2, fx = 0, fy = 0;
  cin >> s >> x >> y;
  x += 16000, y += 16000;
  int i = 0, b = 0;
  for (; i < s.size(); i++) {
    if (s[i] == 'T')
      break;
    b++;
  }
  i++;
  dpx[16000 + b][fx] = 1, dpy[16000][0] = 1, fl = 1;
  while (i < (int)s.size()) {
    int cnt = 0;
    for (; i < s.size(); i++) {
      if (s[i] == 'T')
        break;
      else
        cnt++;
    }
    if (fl) {
      fl = 0;
      fy++;
      for (int j = 8000; j <= 24000; j++) {
        if (dpy[j - cnt][fy - 1])
          dpy[j][fy] = 1;
        else if (dpy[j + cnt][fy - 1])
          dpy[j][fy] = 1;
        else
          dpy[j][fy] = 0;
      }
    } else {
      fl = 1;
      fx++;
      for (int j = 8000; j <= 24000; j++) {
        if (dpx[j - cnt][fx - 1])
          dpx[j][fx] = 1;
        else if (dpx[j + cnt][fx - 1])
          dpx[j][fx] = 1;
        else
          dpx[j][fx] = 0;
      }
    }
    i++;
  }
  if (dpx[x][fx] && dpy[y][fy])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int px[6] = {0, 1, -1, 1, 0, 1}, py[6] = {-1, -1, 0, 0, 1, 1};
const int tx[8] = {-1, 0, 1, -1, 1, -1, 0, 1},
          ty[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

bool dpx[32000][8010], dpy[32000][8010];

int main() {
  string s;
  int x, y, now = 16000, fl = 2, fx = 0, fy = 0;
  cin >> s >> x >> y;
  x += 16000, y += 16000;
  int i = 0, b = 0;
  for (; i < s.size(); i++) {
    if (s[i] == 'T')
      break;
    b++;
  }
  i++;
  dpx[16000 + b][fx] = 1, dpy[16000][0] = 1, fl = 1;
  while (i < (int)s.size()) {
    int cnt = 0;
    for (; i < s.size(); i++) {
      if (s[i] == 'T')
        break;
      else
        cnt++;
    }
    if (fl) {
      fl = 0;
      fy++;
      for (int j = 8000; j <= 24000; j++) {
        if (dpy[j - cnt][fy - 1])
          dpy[j][fy] = 1;
        else if (dpy[j + cnt][fy - 1])
          dpy[j][fy] = 1;
        else
          dpy[j][fy] = 0;
      }
    } else {
      fl = 1;
      fx++;
      for (int j = 8000; j <= 24000; j++) {
        if (dpx[j - cnt][fx - 1])
          dpx[j][fx] = 1;
        else if (dpx[j + cnt][fx - 1])
          dpx[j][fx] = 1;
        else
          dpx[j][fx] = 0;
      }
    }
    i++;
  }
  if (dpx[x][fx] && dpy[y][fy])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}