Problem p03488 (C++)

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

#define rep(i, n) for (i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {
  ll i, j;
  string s;
  ll x, y;
  cin >> s >> x >> y;
  ll n = s.size();
  vector<ll> yoko;
  vector<ll> tate;
  bool now = true;
  ll tmp = 0;
  for (i = 0; i < n; ++i) {
    if (s.at(i) == 'F')
      ++tmp;
    else {
      if (tmp == 0) {
        if (now)
          now = false;
        else
          now = true;
        continue;
      }
      if (now) {
        yoko.push_back(tmp);
        now = false;
        tmp = 0;
      } else {
        tate.push_back(tmp);
        now = true;
        tmp = 0;
      }
    }
  }
  if (tmp != 0) {
    if (now)
      yoko.push_back(tmp);
    else
      tate.push_back(tmp);
  }
  ll n1 = yoko.size();
  ll n2 = tate.size();

  vector<vector<ll>> dp1(n1 + 1, vector<ll>(16001, 0));
  dp1.at(0).at(8000) = 1;
  dp1.at(1).at(8000 + yoko.at(0)) = 1;
  for (i = 2; i <= n1; ++i) {
    rep(j, 16001) {
      ll moto1 = j + yoko.at(i - 1);
      ll moto2 = j - yoko.at(i - 1);
      if (moto1 <= 16000)
        dp1.at(i).at(j) += dp1.at(i - 1).at(moto1);
      if (moto2 >= 0)
        dp1.at(i).at(j) += dp1.at(i - 1).at(moto2);
    }
  }

  vector<vector<ll>> dp2(n2 + 1, vector<ll>(16001, 0));
  dp2.at(0).at(8000) = 1;
  for (i = 1; i <= n2; ++i) {
    rep(j, 16001) {
      ll moto1 = j + tate.at(i - 1);
      ll moto2 = j - tate.at(i - 1);
      if (moto1 <= 16000)
        dp2.at(i).at(j) += dp2.at(i - 1).at(moto1);
      if (moto2 >= 0)
        dp2.at(i).at(j) += dp2.at(i - 1).at(moto2);
    }
  }
  if (dp1.at(n1).at(8000 + x) && dp2.at(n2).at(8000 + y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

#define rep(i, n) for (i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {
  ll i, j;
  string s;
  ll x, y;
  cin >> s >> x >> y;
  ll n = s.size();
  vector<ll> yoko;
  vector<ll> tate;
  bool now = true;
  ll tmp = 0;
  for (i = 0; i < n; ++i) {
    if (s.at(i) == 'F')
      ++tmp;
    else {
      if (tmp == 0) {
        if (now)
          now = false;
        else
          now = true;
        continue;
      }
      if (now) {
        yoko.push_back(tmp);
        now = false;
        tmp = 0;
      } else {
        tate.push_back(tmp);
        now = true;
        tmp = 0;
      }
    }
  }
  if (tmp != 0) {
    if (now)
      yoko.push_back(tmp);
    else
      tate.push_back(tmp);
  }
  ll n1 = yoko.size();
  ll n2 = tate.size();

  vector<vector<ll>> dp1(n1 + 1, vector<ll>(16001, 0));
  dp1.at(0).at(8000) = 1;
  if (n1) {
    if (s.at(0) == 'F')
      dp1.at(1).at(8000 + yoko.at(0)) = 1;
    else {
      dp1.at(1).at(8000 + yoko.at(0)) = 1;
      dp1.at(1).at(8000 - yoko.at(0)) = 1;
    }
  }
  for (i = 2; i <= n1; ++i) {
    rep(j, 16001) {
      ll moto1 = j + yoko.at(i - 1);
      ll moto2 = j - yoko.at(i - 1);
      if (moto1 <= 16000)
        dp1.at(i).at(j) += dp1.at(i - 1).at(moto1);
      if (moto2 >= 0)
        dp1.at(i).at(j) += dp1.at(i - 1).at(moto2);
    }
  }

  vector<vector<ll>> dp2(n2 + 1, vector<ll>(16001, 0));
  dp2.at(0).at(8000) = 1;
  for (i = 1; i <= n2; ++i) {
    rep(j, 16001) {
      ll moto1 = j + tate.at(i - 1);
      ll moto2 = j - tate.at(i - 1);
      if (moto1 <= 16000)
        dp2.at(i).at(j) += dp2.at(i - 1).at(moto1);
      if (moto2 >= 0)
        dp2.at(i).at(j) += dp2.at(i - 1).at(moto2);
    }
  }
  if (dp1.at(n1).at(8000 + x) && dp2.at(n2).at(8000 + y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}