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

int main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector <char> tab(n);
    for (int i=0; i<n; i++)
        cin >> tab[i];

    vector <int> wnk(n, 0);
    int a= 0;
    while (a < n && tab[a] == 'L')
        a++;
    if (a < n) {

        int num_of_Ls= 0;
        for (int i=a; i<n; i++)
            if (tab[i] == 'L')
                num_of_Ls++;
        
        for (int i=0; i<num_of_Ls; i++) {
            wnk[a+i] = 1;   // zamiana na 1
        }

        for (int i=a; i<n; i++) {
            if (tab[i] == 'L') {
                wnk[i]+= 1; // zamiana z 1
                num_of_Ls--;
            }
            wnk[i] += min(i-a, num_of_Ls) * 2;  // przesunięcie w lewo
        }

    }

    for (int i=0; i<n; i++)
        cout << wnk[i] << ' ';
    cout << endl;

    return 0;
}