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
#include <iostream>
using namespace std;

const int N = 3e5 + 5;

int n;
string s;
int pr[N];
int sf[N];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> n >> s;

    for(int i=0;i<n;i++){
        pr[i] = (i ? pr[i-1] : 0) + (i ? s[i-1] == 'P' : 0);
    }

    for(int i=n-1;i>=0;i--){
        sf[i] = (i!=n-1 ? sf[i+1] : 0) + (i != n-1 ? s[i-1] == 'L' : 0);
    }

    for(int i=0;i<n;i++){
        if(s[i] == 'P'){
            if(sf[i] >= pr[i]){
                cout << pr[i]*2+1 << " ";
            }
            else{
                cout << sf[i]*2 << " ";
            }
        }
        else{
            if(pr[i] >= sf[i]){
                cout << sf[i]*2+1 << " ";
            }
            else{
                cout << pr[i]*2 << " ";
            }
        }
    }
    cout << "\n";

    return 0;
}