Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
1.8 kB
2
Indexable
Never
#include <iostream>
#include <vector>
#include <unordered_set>
#include <map>
#include <string>

using namespace std;

int main() {
    unordered_set<int> s;
    int n;
    cin >> n;
    vector<char> vc(n);
    vector<char> v_dir(n + 1);
    char cur_dir = 'R';
    int pos = 0;
    v_dir[0] = cur_dir;
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        if (vc[i] != 'F') {
            cur_dir = vc[i];
        } else {
            pos += (cur_dir == 'R') ? 1 : -1;
        }
        v_dir[i + 1] = cur_dir;
    }
    int lenf = 0;
    for (int i = n - 1; i >= 0; --i) {
        //cout << vc[i] << " " << v_dir[i] << " " << v_dir[i + 1] << endl;
        if (vc[i] == 'F') {
            if (v_dir[i + 1] == 'R') {
                s.insert(pos - (lenf * 2 + 1)); //F -> L (prev_dir R)
                s.insert(pos - 1);              //F -> R (prev_dir R)
            } else {
                s.insert(pos + (lenf * 2 + 1)); //F -> R (prev_dir L)
                s.insert(pos + 1);              //F -> L (prev_dir L)
            }
            lenf++;
        } else if (vc[i] == 'R') {
            if (v_dir[i] == 'R') {
                s.insert(pos + 1);              //R -> F (prev_dir R)
            } else {
                s.insert(pos - (1 + lenf * 2)); //R -> F (prev_dir L)
            }
            s.insert(pos - (lenf * 2));         //R -> L
            lenf = 0;
        } else {
            if (v_dir[i] == 'R') {
                s.insert(pos + (1 + lenf * 2)); //L -> F (prev_dir R)
            } else {
                s.insert(pos - 1);              //L -> F (prev_dir L)
            }
            s.insert(pos + (lenf * 2));         //L -> R
            lenf = 0;
        }
    }
    cout << s.size();

    return 0;
}
Leave a Comment