Problem p03488 (C++)

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

int main() {
  string s;
  int x, y;
  cin >> s >> x >> y;
  vector<int> xl, yl;
  int n = s.size();
  bool side = false, start = true;
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    while (i < n && s[i] == 'F') {
      ++cnt;
      ++i;
    }
    if (start) {
      x -= cnt;
      start = false;
    } else if (side) {
      xl.push_back(cnt);
      side = false;
    } else {
      yl.push_back(cnt);
      side = true;
    }
  }
  /*
  cout << "x:" << x << " y:" << y << endl;
  cout << "xlist:";
  for(int i=0; i<(int)xl.size(); ++i){
    if(i != (int)xl.size()-1) cout << xl[i] << " ";
    else cout << xl[i] << endl;
  }
  cout << "ylist:";
  for(int i=0; i<(int)yl.size(); ++i){
    if(i != (int)yl.size()-1) cout << yl[i] << " ";
    else cout << yl[i] << endl;
  }
  */
  vector<vector<bool>> dpx(xl.size() + 1, vector<bool>(16005, false));
  vector<vector<bool>> dpy(yl.size() + 1, vector<bool>(16005, false));
  dpx[0][zero] = true;
  dpy[0][zero] = true;
  for (int i = 0; i < (int)xl.size(); ++i) {
    for (int j = 0; j <= 16000; ++j) {
      if (j - xl[i] >= 0 && dpx[i][j - xl[i]])
        dpx[i + 1][j] = true;
      if (j + xl[i] <= 16000 && dpx[i][j + xl[i]])
        dpx[i + 1][j] = true;
    }
  }
  for (int i = 0; i < (int)yl.size(); ++i) {
    for (int j = 0; j <= 16000; ++j) {
      if (j - yl[i] >= 0 && dpy[i][j - yl[i]])
        dpy[i + 1][j] = true;
      if (j + yl[i] <= 16000 && dpy[i][j + yl[i]])
        dpy[i + 1][j] = true;
    }
  }
  if (dpx[xl.size()][zero + x] && dpy[yl.size()][zero + y]) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int zero = 8000;

int main() {
  string s;
  int x, y;
  cin >> s >> x >> y;
  vector<int> xl, yl;
  int n = s.size();
  bool side = false, start = true;
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    while (i < n && s[i] == 'F') {
      ++cnt;
      ++i;
    }
    if (start) {
      x -= cnt;
      start = false;
    } else if (side) {
      xl.push_back(cnt);
      side = false;
    } else {
      yl.push_back(cnt);
      side = true;
    }
  }
  /*
  cout << "x:" << x << " y:" << y << endl;
  cout << "xlist:";
  for(int i=0; i<(int)xl.size(); ++i){
    if(i != (int)xl.size()-1) cout << xl[i] << " ";
    else cout << xl[i] << endl;
  }
  cout << "ylist:";
  for(int i=0; i<(int)yl.size(); ++i){
    if(i != (int)yl.size()-1) cout << yl[i] << " ";
    else cout << yl[i] << endl;
  }
  */
  vector<vector<bool>> dpx(xl.size() + 1, vector<bool>(16005, false));
  vector<vector<bool>> dpy(yl.size() + 1, vector<bool>(16005, false));
  dpx[0][zero] = true;
  dpy[0][zero] = true;
  for (int i = 0; i < (int)xl.size(); ++i) {
    for (int j = 0; j <= 16000; ++j) {
      if (j - xl[i] >= 0 && dpx[i][j - xl[i]])
        dpx[i + 1][j] = true;
      if (j + xl[i] <= 16000 && dpx[i][j + xl[i]])
        dpx[i + 1][j] = true;
    }
  }
  for (int i = 0; i < (int)yl.size(); ++i) {
    for (int j = 0; j <= 16000; ++j) {
      if (j - yl[i] >= 0 && dpy[i][j - yl[i]])
        dpy[i + 1][j] = true;
      if (j + yl[i] <= 16000 && dpy[i][j + yl[i]])
        dpy[i + 1][j] = true;
    }
  }
  if (x > -zero && dpx[xl.size()][zero + x] && dpy[yl.size()][zero + y]) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}