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

const int K = 300000;
char ants[K];
int result[K];

int main()
{
	int n, left_edge, right_edge;
	cin >> n;
	int left_ants = n;
	left_edge = 0;
	right_edge = n - 1;

	for (int i = 0; i < n; i++)
		cin >> ants[i];

	for (int i = 0; i < n; i++)
	{
		for (int j = left_edge; j <= right_edge && j < n; j++)
		{
			if (j == left_edge && ants[j] == 'L')
			{
				left_edge++;
				continue;
			}			
			if (j == right_edge && ants[j] == 'P')
			{
				right_edge--;
				continue;
			}
			if (ants[j] =='P' && ants[j] != ants[j + 1]) {
				result[j]++;
				result[j + 1]++;		
				ants[j] = 'L';
				ants[j + 1] = 'P';				
			}			
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			cout << result[i];
		}
		else {
			cout << result[i] << " ";
		}		
	}
	return 0;
}