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
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int>pr(n),sf(n);
	for(int i=1; i<n; i++)
		pr[i]=pr[i-1]+(s[i-1]=='P'?1:0);
	for(int i=n-2; i>=0; i--)
		sf[i]=sf[i+1]+(s[i+1]=='L'?1:0);
	for(int i=0; i<n; i++)
		if(s[i]=='L')
			if(pr[i]>sf[i])
				cout<<sf[i]*2+1<<" ";
			else
				cout<<min(pr[i],sf[i])*2<<" ";
		else
			if(sf[i]>pr[i])
				cout<<pr[i]*2+1<<" ";
			else
				cout<<min(pr[i],sf[i])*2<<" ";
	cout<<"\n";
}