Problem p03488 (C++)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

bool dp_x[8010][2 * 8010], dp_y[8010][2 * 8010];

int main() {
  string s;
  cin >> s;
  ll x, y;
  cin >> x >> y;

  ll n = s.size();
  ll start;
  REP(i, n) {
    if (s[i] == 'T') {
      start = i + 1;
      break;
    }
    --x;
  }

  dp_x[0][8000] = dp_y[0][8000] = true;
  ll sum = 0, cnt = 1;
  vector<ll> xs, ys;
  FOR(i, start, n) {
    if (s[i] == 'T') {
      if (cnt % 2 == 0) {
        xs.push_back(sum);
      } else {
        ys.push_back(sum);
      }
      sum = 0;
      ++cnt;
      continue;
    }
    ++sum;
  }
  if (sum != 0) {
    if (cnt % 2 == 0) {
      xs.push_back(sum);
    } else {
      ys.push_back(sum);
    }
  }

  REP(i, xs.size()) {
    REP(j, 2 * 8010) {
      if (j + xs[i] < 2 * 8010)
        dp_x[i + 1][j + xs[i]] |= dp_x[i][j];
      if (0 <= j - xs[i])
        dp_x[i + 1][j - xs[i]] |= dp_x[i][j];
    }
  }
  REP(i, ys.size()) {
    REP(j, 2 * 8010) {
      if (j + ys[i] < 2 * 8010)
        dp_y[i + 1][j + ys[i]] |= dp_y[i][j];
      if (0 <= j - ys[i])
        dp_y[i + 1][j - ys[i]] |= dp_y[i][j];
    }
  }

  if (dp_x[xs.size()][x + 8000] && dp_y[ys.size()][y + 8000]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

bool dp_x[8010][2 * 8010], dp_y[8010][2 * 8010];

int main() {
  string s;
  cin >> s;
  ll x, y;
  cin >> x >> y;

  ll n = s.size();
  ll start = n;
  REP(i, n) {
    if (s[i] == 'T') {
      start = i + 1;
      break;
    }
    --x;
  }

  dp_x[0][8000] = dp_y[0][8000] = true;
  ll sum = 0, cnt = 1;
  vector<ll> xs, ys;
  FOR(i, start, n) {
    if (s[i] == 'T') {
      if (cnt % 2 == 0) {
        xs.push_back(sum);
      } else {
        ys.push_back(sum);
      }
      sum = 0;
      ++cnt;
      continue;
    }
    ++sum;
  }
  if (sum != 0) {
    if (cnt % 2 == 0) {
      xs.push_back(sum);
    } else {
      ys.push_back(sum);
    }
  }

  REP(i, xs.size()) {
    REP(j, 2 * 8010) {
      if (j + xs[i] < 2 * 8010)
        dp_x[i + 1][j + xs[i]] |= dp_x[i][j];
      if (0 <= j - xs[i])
        dp_x[i + 1][j - xs[i]] |= dp_x[i][j];
    }
  }
  REP(i, ys.size()) {
    REP(j, 2 * 8010) {
      if (j + ys[i] < 2 * 8010)
        dp_y[i + 1][j + ys[i]] |= dp_y[i][j];
      if (0 <= j - ys[i])
        dp_y[i + 1][j - ys[i]] |= dp_y[i][j];
    }
  }

  if (dp_x[xs.size()][x + 8000] && dp_y[ys.size()][y + 8000]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}