#include <iostream>
using namespace std;
int s[300001];
int main()
{
int n;
string dane2;
cin >> n;
cin >> dane2;
int pp=0;
for(int i=0; i<n; i++){
if(dane2[i]=='P') pp++;
s[i]=pp;
}
int pl=0;
int ii=n-1;
while(s[ii]>pl){
if(dane2[ii]=='L') pl++;
ii--;
}
int wp=(-1);
for(int i=0; i<=ii; i++){
if(dane2[i]=='L'){
s[i]=wp+1;
}else{
wp+=2;
s[i]=wp;
}
}
wp=(-1);
for(int i=n-1; i>ii; i--){
if(dane2[i]=='P'){
s[i]=wp+1;
}else{
wp+=2;
s[i]=wp;
}
}
for(int i=0; i<n; i++){
cout << s[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 | #include <iostream> using namespace std; int s[300001]; int main() { int n; string dane2; cin >> n; cin >> dane2; int pp=0; for(int i=0; i<n; i++){ if(dane2[i]=='P') pp++; s[i]=pp; } int pl=0; int ii=n-1; while(s[ii]>pl){ if(dane2[ii]=='L') pl++; ii--; } int wp=(-1); for(int i=0; i<=ii; i++){ if(dane2[i]=='L'){ s[i]=wp+1; }else{ wp+=2; s[i]=wp; } } wp=(-1); for(int i=n-1; i>ii; i--){ if(dane2[i]=='P'){ s[i]=wp+1; }else{ wp+=2; s[i]=wp; } } for(int i=0; i<n; i++){ cout << s[i] << " "; } return 0; } |
English