Problem p03488 (C++)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template <typename T, typename S> void amax(T &x, S y) {
  if (x < y)
    x = y;
}
template <typename T, typename S> void amin(T &x, S y) {
  if (y < x)
    x = y;
}

bool dp[2][2010][20100];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string s;
  int x, y;
  cin >> s >> x >> y;
  int n = s.size(), cnt = 0;
  rep(i, n) if (s[i] == 'F') cnt++;
  else break;
  x -= cnt;
  if (cnt == n) {
    if (x == 0 && y == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    return 0;
  }
  vi32 op[2];
  {
    int t = 0, c = 0;
    repi(i, cnt, n) {
      if (s[i] == 'F')
        c++;
      else {
        op[t].push_back(c);
        c = 0;
        t = 1 - t;
      }
    }
    op[t].push_back(c);
  }
  dp[0][0][10000] = true;
  dp[1][0][10000] = true;
  rep(i, 2) rep(j, op[i].size()) rep(k, 20010) {
    if (!dp[i][j][k])
      continue;
    dp[i][j + 1][k + op[i][j]] = true;
    dp[i][j + 1][k - op[i][j]] = true;
  }
  if (dp[0][op[0].size()][10000 + x] && dp[1][op[1].size()][10000 + y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template <typename T, typename S> void amax(T &x, S y) {
  if (x < y)
    x = y;
}
template <typename T, typename S> void amin(T &x, S y) {
  if (y < x)
    x = y;
}

bool dp[2][4010][20100];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string s;
  int x, y;
  cin >> s >> x >> y;
  int n = s.size(), cnt = 0;
  rep(i, n) if (s[i] == 'F') cnt++;
  else break;
  x -= cnt;
  if (cnt == n) {
    if (x == 0 && y == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    return 0;
  }
  vi32 op[2];
  {
    int t = 0, c = 0;
    repi(i, cnt, n) {
      if (s[i] == 'F')
        c++;
      else {
        op[t].push_back(c);
        c = 0;
        t = 1 - t;
      }
    }
    op[t].push_back(c);
  }
  dp[0][0][10000] = true;
  dp[1][0][10000] = true;
  rep(i, 2) rep(j, op[i].size()) rep(k, 20010) {
    if (!dp[i][j][k])
      continue;
    dp[i][j + 1][k + op[i][j]] = true;
    dp[i][j + 1][k - op[i][j]] = true;
  }
  if (dp[0][op[0].size()][10000 + x] && dp[1][op[1].size()][10000 + y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}