Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

bool xDP[2010][8010] = {false};
bool yDP[2010][8010] = {false};

int main() {
  string S;
  int rl = 0;
  cin >> S;
  int ss = S.size(), F = 0, cnt = 0;
  vector<int> RL, UD;
  int i = 0;
  bool jud = 0;
  while (i < ss) {
    if (S[i] == 'T')
      break;
    i++;
    F++;
  }
  i++;
  int RLz = 0, UDz = 0, RLs = 0, UDs = 0;

  while (i < ss) {
    if (S[i] == 'F')
      cnt++;
    else {
      if (cnt) {
        if (rl) {
          RL.push_back(cnt);
          RLz++;
          RLs += cnt;
        } else {
          UD.push_back(cnt);
          UDz++;
          UDs += cnt;
        }
        cnt = 0;
      }
      rl = 1 - rl;
    }
    i++;
  }
  if (cnt) {
    if (rl) {
      RL.push_back(cnt);
      RLz++;
      RLs += cnt;
    } else {
      UD.push_back(cnt);
      UDz++;
      UDs += cnt;
    }
  }
  int x, y;
  cin >> x >> y;
  x = abs(F - x), y = abs(y);
  if ((RLs -= x) % 2) {
    cout << "No" << endl;
    return 0;
  }
  RLs /= 2;
  if (RLz == 0) {
    if (RLs) {
      cout << "No" << endl;
      return 0;
    }
  } else {
    xDP[0][0] = xDP[0][RL[0]] = true;
    for (int j = 1; j < RLz; j++) {
      for (int k = 0; k <= RLs; k++) {
        if (k == 0)
          xDP[j][k] = true;
        if (k >= RL[j] && xDP[j - 1][k - RL[j]])
          xDP[j][k] = true;
        if (xDP[j - 1][k])
          xDP[j][k] = true;
      }
    }
    if (!xDP[RLz - 1][RLs]) {
      cout << "No" << endl;
      return 0;
    }
  }

  if ((UDs -= y) % 2) {
    cout << "No" << endl;
    return 0;
  }
  UDs /= 2;
  if (UDz == 0) {
    if (UDs) {
      cout << "No" << endl;
      return 0;
    }
  } else {
    yDP[0][0] = yDP[0][UD[0]] = true;
    for (int j = 1; j < UDz; j++) {
      for (int k = 0; k <= UDs; k++) {
        if (k == 0)
          yDP[j][k] = true;
        if (k >= UD[j] && yDP[j - 1][k - UD[j]])
          yDP[j][k] = true;
        if (yDP[j - 1][k])
          yDP[j][k] = true;
      }
    }
    if (!yDP[UDz - 1][UDs]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

bool xDP[8010][8010] = {false};
bool yDP[8010][8010] = {false};

int main() {
  string S;
  int rl = 0;
  cin >> S;
  int ss = S.size(), F = 0, cnt = 0;
  vector<int> RL, UD;
  int i = 0;
  bool jud = 0;
  while (i < ss) {
    if (S[i] == 'T')
      break;
    i++;
    F++;
  }
  i++;
  int RLz = 0, UDz = 0, RLs = 0, UDs = 0;

  while (i < ss) {
    if (S[i] == 'F')
      cnt++;
    else {
      if (cnt) {
        if (rl) {
          RL.push_back(cnt);
          RLz++;
          RLs += cnt;
        } else {
          UD.push_back(cnt);
          UDz++;
          UDs += cnt;
        }
        cnt = 0;
      }
      rl = 1 - rl;
    }
    i++;
  }
  if (cnt) {
    if (rl) {
      RL.push_back(cnt);
      RLz++;
      RLs += cnt;
    } else {
      UD.push_back(cnt);
      UDz++;
      UDs += cnt;
    }
  }
  int x, y;
  cin >> x >> y;
  x = abs(F - x), y = abs(y);
  if ((RLs -= x) % 2) {
    cout << "No" << endl;
    return 0;
  }
  RLs /= 2;
  if (RLz == 0) {
    if (RLs) {
      cout << "No" << endl;
      return 0;
    }
  } else {
    xDP[0][0] = xDP[0][RL[0]] = true;
    for (int j = 1; j < RLz; j++) {
      for (int k = 0; k <= RLs; k++) {
        if (k == 0)
          xDP[j][k] = true;
        if (k >= RL[j] && xDP[j - 1][k - RL[j]])
          xDP[j][k] = true;
        if (xDP[j - 1][k])
          xDP[j][k] = true;
      }
    }
    if (!xDP[RLz - 1][RLs]) {
      cout << "No" << endl;
      return 0;
    }
  }

  if ((UDs -= y) % 2) {
    cout << "No" << endl;
    return 0;
  }
  UDs /= 2;
  if (UDz == 0) {
    if (UDs) {
      cout << "No" << endl;
      return 0;
    }
  } else {
    yDP[0][0] = yDP[0][UD[0]] = true;
    for (int j = 1; j < UDz; j++) {
      for (int k = 0; k <= UDs; k++) {
        if (k == 0)
          yDP[j][k] = true;
        if (k >= UD[j] && yDP[j - 1][k - UD[j]])
          yDP[j][k] = true;
        if (yDP[j - 1][k])
          yDP[j][k] = true;
      }
    }
    if (!yDP[UDz - 1][UDs]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}