题解
2026-08-21 15:49:01
发布于:浙江
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
string s;
int n,m;
cin>>n>>m;
cin>>s;
stack<char>t;
for(int i=0;i<n;i++){
if(s[i]=='U'){
if(!t.empty()){
t.pop();
}
else{
if(m!=1){
m=m/2;
}
}
}
if(s[i]=='L'||s[i]=='R'){
t.push(s[i]);
}
}
stack<char>s1;
while(!t.empty()){
s1.push(t.top());
t.pop();
}
while(!s1.empty()){
if(s1.top()=='R'){
m=m*2+1;
}
else{
m=m*2;
}
s1.pop();
}
cout<<m;
return 0;
}
这里空空如也







有帮助,赞一个