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

int main() {
    int64_t n;
    std::string desc;
    std::cin >> n >> desc;

    std::vector<int64_t> left_pressure(n), right_pressure(n);

    {
        int i = 0;
        auto desc_it = desc.begin();
        auto left_it = left_pressure.begin();
        for (; desc_it != desc.end(); ++desc_it, ++left_it) {
            *left_it = i;
            if (*desc_it == 'P') {
                i += 1;
            }
        }
    }

    {
        int i = 0;
        auto desc_rit = desc.rbegin();
        auto right_rit = right_pressure.rbegin();
        for (; desc_rit != desc.rend(); ++desc_rit, ++right_rit) {
            *right_rit = i;
            if (*desc_rit == 'L') {
                i += 1;
            }
        }
    }

    {
        auto desc_it = desc.begin();
        auto left_it = left_pressure.begin();
        auto right_it = right_pressure.begin();
        for (; desc_it != desc.end(); ++desc_it, ++left_it, ++right_it) {
            if (*desc_it == 'L') {
                if (*right_it > *left_it) {
                    *right_it = *left_it;
                } else if (*left_it > *right_it + 1) {
                    *left_it = *right_it + 1;
                }
            } else {
                if (*left_it > *right_it) {
                    *left_it = *right_it;
                } else if (*right_it > *left_it + 1) {
                    *right_it = *left_it + 1;
                }
            }
            std::cout << *left_it + *right_it << " ";
        }
        std::cout << "\n";
    }
}