维护一个栈
U可以抵消上一位的L或者R
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long LL;
vector<int>v;
string str;
LL x;
int n;
int main()
{
cin >> n >> x >> str;
for (int i = 0;i < n;i++)
{
if (str[i] == 'L')v.push_back(0);
else if (str[i] == 'R')v.push_back(1);
else
{
if (v.size() && v.back() != 2)v.pop_back();
else v.push_back(2);
}
}
for (auto it : v)
{
if (it == 0)x = x << 1;
else if (it == 1)x = x << 1 | 1;
else x = x >> 1;
}
cout << x << endl;
return 0;
}