Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int main() {
  string s;
  int x, y, sx = 0, num = 0, ans = 0;
  vector<int> xm, ym;
  bool dp[2001][16001] = {};
  cin >> s >> x >> y;
  char d = 'x';
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'F') {
      if (i == 0) {
        while (s[i] == 'F') {
          sx++;
          i++;
        }
        i--;
        num++;
      } else {
        int count = 0;
        while (s[i] == 'F') {
          count++;
          i++;
        }
        i--;
        if (d == 'x')
          xm.push_back(count);
        else
          ym.push_back(count);
        num++;
      }
    } else {
      if (d == 'x')
        d = 'y';
      else
        d = 'x';
    }
  }

  dp[0][sx + 8000] = true;
  for (int i = 1; i <= xm.size(); i++) {
    for (int j = 0; j <= 16000; j++) {
      if (dp[i - 1][j] == true) {
        dp[i][j + xm[i - 1]] = true;
        dp[i][j - xm[i - 1]] = true;
      }
    }
  }
  if (dp[xm.size()][x + 8000] == true)
    ans++;

  fill(dp[0], dp[2000], 0);
  dp[0][8000] = true;
  for (int i = 1; i <= ym.size(); i++) {
    for (int j = 0; j <= 16000; j++) {
      if (dp[i - 1][j] == true) {
        dp[i][j + ym[i - 1]] = true;
        dp[i][j - ym[i - 1]] = true;
      }
    }
  }
  if (dp[ym.size()][y + 8000] == true)
    ans++;

  if (ans == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int main() {
  string s;
  int x, y, sx = 0, num = 0, ans = 0;
  vector<int> xm, ym;
  bool dp[3000][16010] = {};
  cin >> s >> x >> y;
  char d = 'x';
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'F') {
      if (i == 0) {
        while (s[i] == 'F') {
          sx++;
          i++;
        }
        i--;
        num++;
      } else {
        int count = 0;
        while (s[i] == 'F') {
          count++;
          i++;
        }
        i--;
        if (d == 'x')
          xm.push_back(count);
        else
          ym.push_back(count);
        num++;
      }
    } else {
      if (d == 'x')
        d = 'y';
      else
        d = 'x';
    }
  }

  dp[0][sx + 8000] = true;
  for (int i = 1; i <= xm.size(); i++) {
    for (int j = 0; j <= 16000; j++) {
      if (dp[i - 1][j] == true) {
        dp[i][j + xm[i - 1]] = true;
        dp[i][j - xm[i - 1]] = true;
      }
    }
  }
  if (dp[xm.size()][x + 8000] == true)
    ans++;

  fill(dp[0], dp[2000], 0);
  dp[0][8000] = true;
  for (int i = 1; i <= ym.size(); i++) {
    for (int j = 0; j <= 16000; j++) {
      if (dp[i - 1][j] == true) {
        dp[i][j + ym[i - 1]] = true;
        dp[i][j - ym[i - 1]] = true;
      }
    }
  }
  if (dp[ym.size()][y + 8000] == true)
    ans++;

  if (ans == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}