本人使用了奇怪的代码,在本题100000的数据下仍旧通过,使用多种STL,很奇怪
#include<bits/stdc++.h>
using namespace std;
vector<int> s={'R','B','W'};
map<char,int> l;
string k;
int main(){
int n,cnt=0;
cin>>n>>k;
l[s[1]]=1;
l[s[2]]=2;
l[s[3]]=3;
for(int i=0;i<n;i++){
while(!s.empty() && l[s.back()]>l[k[i]] && s.back()!=k[i]){
s.pop_back();
cnt++;
}
if(!s.empty() && s.back()!=k[i]){
s.push_back(k[i]);
cnt++;
}
}
cout<<cnt;
return 0;
}