Language: C++

#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int> const &v, int target) {
    vector<map<int, bool>> dp(v.size() + 1);

    dp[0][0] = true;
    for (int i = 0; i < v.size(); i++) {
        for (auto const &pair: dp[i]) {
            dp[i+1][pair.first + v[i]] = true;
            dp[i+1][pair.first - v[i]] = true;
        }
    }
    return dp[v.size()][target];
}
int main(void)
{
    string s;
    vector<int> v[2];
    int init_x = 0;
    bool first = true;
    bool just_changed = true;
    int dir = 0; // 0: x, 1: y

    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        switch (s[i]) {
            case 'F':
                if (just_changed) {
                    just_changed = false;
                    v[dir].push_back(1);
                } else {
                    v[dir].back()++;
                }
                break;
            case 'T':
                dir++;
                dir &= 1;
                if (first && !v[0].empty()) {
                    init_x = v[0][0];
                    v[0].erase(v[0].begin());
                    assert(v[0].size() == 0 && v[1].size() == 0);
                }
                first = false;
                just_changed = true;
                break;
        }
    }

    int x, y;
    cin >> x >> y;
    if (first && !v[0].empty()) {
        init_x = v[0][0];
        v[0].erase(v[0].begin());
        assert(v[0].size() == 0 && v[1].size() == 0);
    }

    cout << ((solve(v[0], x - init_x) && solve(v[1], y)) ? "Yes" : "No") << endl;
    
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int> const &v, int target) {
    vector<map<int, bool>> dp(v.size() + 1);

    dp[0][0] = true;
    for (int i = 0; i < v.size(); i++) {
        for (auto const &pair: dp[i]) {
            dp[i+1][pair.first + v[i]] = true;
            dp[i+1][pair.first - v[i]] = true;
        }
    }
    return dp[v.size()][target];
}
int main(void)
{
    string s;
    vector<int> v[2];
    int init_x = 0;
    bool first = true;
    bool just_changed = true;
    int dir = 0; // 0: x, 1: y

    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        switch (s[i]) {
            case 'F':
                if (just_changed) {
                    just_changed = false;
                    v[dir].push_back(1);
                } else {
                    v[dir].back()++;
                }
                break;
            case 'T':
                dir++;
                dir &= 1;
                if (first && !v[0].empty()) {
                    init_x = v[0][0];
                    v[0].erase(v[0].begin());
                    assert(v[0].size() == 0 && v[1].size() == 0);
                }
                first = false;
                just_changed = true;
                break;
        }
    }

    int x, y;
    cin >> x >> y;
    if (first && !v[0].empty()) {
        init_x = v[0][0];
        v[0].erase(v[0].begin());
        assert(v[0].size() == 0 && v[1].size() == 0);
    }

    cout << ((solve(v[0], x - init_x) && solve(v[1], y)) ? "Yes" : "No") << endl;
    
    return 0;
}


Compiler output:
a.cc:63:6: error: redefinition of 'bool solve(const std::vector<int>&, int)'
   63 | bool solve(vector<int> const &v, int target) {
      |      ^~~~~
a.cc:3:6: note: 'bool solve(const std::vector<int>&, int)' previously defined here
    3 | bool solve(vector<int> const &v, int target) {
      |      ^~~~~
a.cc:75:5: error: redefinition of 'int main()'
   75 | int main(void)
      |     ^~~~
a.cc:15:5: note: 'int main()' previously defined here
   15 | int main(void)
      |     ^~~~