Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

bool Check(vector<int> s, int l) {
  if (s.empty()) {
    return l == 0;
  }
  int N = s.size();
  int R = 0;
  for (int i = 0; i < N; i++) {
    R += s[i];
  }
  bool DP[N + 1][2 * R + 1];
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= 2 * R; j++) {
      DP[i][j] = false;
    }
  }
  DP[0][R] = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 2 * R; j++) {
      if (DP[i][j]) {
        DP[i + 1][j + s[i]] = true;
        DP[i + 1][j - s[i]] = true;
      }
    }
  }
  return DP[N][R + l];
}

int main() {
  string S;
  cin >> S;
  int x, y;
  cin >> x >> y;
  int N = S.size();
  int xstart = 0;
  int ystart = 0;
  vector<int> xlis;
  vector<int> ylis;
  int cnt = 0;
  int streak = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'F') {
      streak++;
    } else {
      if (streak == 0) {
        streak = 0;
        cnt++;
        continue;
      }
      if (cnt == 0) {
        xstart += streak;
      } else if (cnt % 2 == 1) {
        ylis.push_back(streak);
      } else {
        xlis.push_back(streak);
      }
      streak = 0;
      cnt++;
    }
  }
  if (streak != 0) {
    if (cnt == 0) {
      xstart += streak;
    } else if (cnt % 2 == 1) {
      ylis.push_back(streak);
    } else {
      xlis.push_back(streak);
    }
  }
  if (Check(xlis, x - xstart) && Check(ylis, y - ystart)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

bool Check(vector<int> s, int l) {
  if (s.empty()) {
    return l == 0;
  }
  int N = s.size();
  int R = 0;
  for (int i = 0; i < N; i++) {
    R += s[i];
  }
  bool DP[N + 1][2 * R + 1];
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= 2 * R; j++) {
      DP[i][j] = false;
    }
  }
  DP[0][R] = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 2 * R; j++) {
      if (DP[i][j]) {
        DP[i + 1][j + s[i]] = true;
        DP[i + 1][j - s[i]] = true;
      }
    }
  }
  if (abs(l) > R) {
    return false;
  } else {
    return DP[N][R + l];
  }
}

int main() {
  string S;
  cin >> S;
  int x, y;
  cin >> x >> y;
  int N = S.size();
  int xstart = 0;
  int ystart = 0;
  vector<int> xlis;
  vector<int> ylis;
  int cnt = 0;
  int streak = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'F') {
      streak++;
    } else {
      if (streak == 0) {
        streak = 0;
        cnt++;
        continue;
      }
      if (cnt == 0) {
        xstart += streak;
      } else if (cnt % 2 == 1) {
        ylis.push_back(streak);
      } else {
        xlis.push_back(streak);
      }
      streak = 0;
      cnt++;
    }
  }
  if (streak != 0) {
    if (cnt == 0) {
      xstart += streak;
    } else if (cnt % 2 == 1) {
      ylis.push_back(streak);
    } else {
      xlis.push_back(streak);
    }
  }
  if (Check(xlis, x - xstart) && Check(ylis, y - ystart)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}