#include <iostream>
using namespace std;
const int maxP=300013;
unsigned int n,m[maxP],stat[maxP],pos[maxP];
std::string inp,hoh="LP";
bool checkv(){
unsigned int bck=stat[0];
for(int i=1;i<n;i++){
if(stat[i]!=bck){
if(bck==1){
return true;
}
bck=1;
}
}
return false;
}
int main(int argc, char** argv) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
cin>>inp;
for(int h=0;h<n;h++){
if(inp[h]==hoh[1]){
stat[h]=1;
}else{
stat[h]= -1;
}
pos[h]=2*h;
}
while(checkv()==true){
for(int i=0;i<n;i++){
pos[i]+=stat[i];
}
for(int i=0;i<n;i++){
if(pos[i]==pos[i+1]&&i!=n){
m[i]++;
m[i+1]++;
stat[i]= -1*stat[i];
stat[i+1]= -1*stat[i+1];
}
}
}
for(int i=0;i<n;i++){
std::cout<<m[i]<<" ";
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <iostream> using namespace std; const int maxP=300013; unsigned int n,m[maxP],stat[maxP],pos[maxP]; std::string inp,hoh="LP"; bool checkv(){ unsigned int bck=stat[0]; for(int i=1;i<n;i++){ if(stat[i]!=bck){ if(bck==1){ return true; } bck=1; } } return false; } int main(int argc, char** argv) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; cin>>inp; for(int h=0;h<n;h++){ if(inp[h]==hoh[1]){ stat[h]=1; }else{ stat[h]= -1; } pos[h]=2*h; } while(checkv()==true){ for(int i=0;i<n;i++){ pos[i]+=stat[i]; } for(int i=0;i<n;i++){ if(pos[i]==pos[i+1]&&i!=n){ m[i]++; m[i+1]++; stat[i]= -1*stat[i]; stat[i+1]= -1*stat[i+1]; } } } for(int i=0;i<n;i++){ std::cout<<m[i]<<" "; } return 0; } |
English