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
50
51
52
53
54
55
56
57
58
59
// Zadanie Mrowki
// Solution by Mistrz Makaron

#include <iostream>
#include <vector>

using namespace std;

int main() {

	int num; cin >> num;

	string input; cin >> input;

	vector<int> Np(num, 0), Nl(num, 0); // Np - liczba P po lewej, Nl - liczba L po prawej

	for (int i = 1; i < num; i++) {
		Np[i] = Np[i - 1];
		if (input[i - 1] == 'P') {
			Np[i]++;
		}
	}

	for (int i = num - 2; i >= 0; i--) {
		Nl[i] = Nl[i + 1];
		if (input[i + 1] == 'L') {
			Nl[i]++;
		}
	}

	vector<int> res(num, 0);

	/*for (int i = 0; i < num; i++) {
		cout << Nl[i] << ' ';
	}
	cout << endl;

	for (int i = 0; i < num; i++) {
		cout << Np[i] << ' ';
	}
	cout << endl;*/

	for (int i = 0; i < num; i++) {
		res[i] = min(Nl[i], Np[i]) * 2;
		if (input[i] == 'L' && Np[i] > Nl[i]) {
			res[i]++;
		}
		if (input[i] == 'P' && Nl[i] > Np[i]) {
			res[i]++;
		}
	}

	for (int i = 0; i < num; i++) {
		cout << res[i] << ' ';
	}
	cout << endl;

	return 0;
}