Problem p03490 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>
using namespace std;

#define MOD 1000000007
#define ll int
#define ld long double
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rmsame(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define rmvector(a, b)                                                         \
  rep(i, a.size()) rep(j, b.size()) if (a[i] == b[j]) {                        \
    a.erase(a.begin() + i);                                                    \
    i--;                                                                       \
    break;                                                                     \
  }
template <typename X> bool exist(vector<X> vec, X item) {
  return find(all(vec), item) != vec.end();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  bool a[8080];
  bool b[8080];

  a[0] = b[0] = true;

  string str;
  cin >> str;
  str += 'T';
  vector<ll> s;
  ll x, y;
  cin >> x >> y;

  vector<ll> xx, yy;

  ll co = 0;
  rep(i, str.size()) {
    if (str[i] != 'T')
      co++;
    else {
      s.pb(co);
      co = 0;
    }
  }

  if (s.size() == 0) {
    if ((x == 0) && (y == 0))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    return 0;
  }

  rep(i, s.size()) {
    if (i % 2 == 0)
      xx.pb(s[i]);
    else
      yy.pb(s[i]);
  }

  x -= xx[0];
  xx.erase(xx.begin() + 0);

  xx.pb(abs(x));
  yy.pb(abs(y));

  sort(rall(xx));
  sort(rall(yy));

  ll sumx = 0;
  rep(i, xx.size()) sumx += xx[i];
  ll sumy = 0;
  rep(i, yy.size()) sumy += yy[i];

  x = 0;
  rep(i, xx.size()) {
    for (ll j = x; j >= 0; j--)
      if (a[j])
        a[j + xx[i]] = true;

    x += xx[i];
  }

  y = 0;
  rep(i, yy.size()) {
    for (ll j = y; j >= 0; j--)
      if (b[j])
        b[j + yy[i]] = true;

    y += yy[i];
  }

  if (((sumx % 2) == 0) && ((sumy % 2) == 0)) {
    if (a[sumx / 2] && b[sumy / 2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  // cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>
using namespace std;

#define MOD 1000000007
#define ll int
#define ld long double
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rmsame(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define rmvector(a, b)                                                         \
  rep(i, a.size()) rep(j, b.size()) if (a[i] == b[j]) {                        \
    a.erase(a.begin() + i);                                                    \
    i--;                                                                       \
    break;                                                                     \
  }
template <typename X> bool exist(vector<X> vec, X item) {
  return find(all(vec), item) != vec.end();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  bool a[16080];
  bool b[16080];

  a[0] = b[0] = true;

  string str;
  cin >> str;
  str += 'T';
  vector<ll> s;
  ll x, y;
  cin >> x >> y;

  vector<ll> xx, yy;

  ll co = 0;
  rep(i, str.size()) {
    if (str[i] != 'T')
      co++;
    else {
      s.pb(co);
      co = 0;
    }
  }

  if (s.size() == 0) {
    if ((x == 0) && (y == 0))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    return 0;
  }

  rep(i, s.size()) {
    if (i % 2 == 0)
      xx.pb(s[i]);
    else
      yy.pb(s[i]);
  }

  x -= xx[0];
  xx.erase(xx.begin() + 0);

  xx.pb(abs(x));
  yy.pb(abs(y));

  sort(rall(xx));
  sort(rall(yy));

  ll sumx = 0;
  rep(i, xx.size()) sumx += xx[i];
  ll sumy = 0;
  rep(i, yy.size()) sumy += yy[i];

  x = 0;
  rep(i, xx.size()) {
    for (ll j = x; j >= 0; j--)
      if (a[j])
        a[j + xx[i]] = true;

    x += xx[i];
  }

  y = 0;
  rep(i, yy.size()) {
    for (ll j = y; j >= 0; j--)
      if (b[j])
        b[j + yy[i]] = true;

    y += yy[i];
  }

  if (((sumx % 2) == 0) && ((sumy % 2) == 0)) {
    if (a[sumx / 2] && b[sumy / 2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  // cout << fixed << setprecision(16) << ans << endl;
  return 0;
}