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
#include <iostream>
#include <vector>

int main() {
    int n;
    std::cin >> n;

    std::string directions;
    std::cin >> directions;

    int begin = 0;
    int end = n - 1;

    std::vector<int> res(n);

    while (begin < end){
        while (directions[begin] == 'L'){
            begin++;
        }
        while (directions[end] == 'P'){
            end--;
        }
        enum states {none, p};
        states state = none;

        for (int i = begin; i <= end; ++i) {
            if (directions[i] == 'P'){
                if (state == none){
                    state = p;
                }
            }
            else {
                if (state == p){
                    directions[i - 1] = 'L';
                    directions[i] = 'P';
                    res[i-1]++;
                    res[i]++;
                    state = none;
                }
            }
        }
    }

    for (int i = 0; i < res.size(); ++i) {
        if (i > 0){
            std::cout << " ";
        }
        std::cout << res[i];
    }
    std::cout << std::endl;

    return 0;
}