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<bits/stdc++.h>
using namespace std;

const int maxn = 3e6+10;
string stri;
char str[maxn];
int ds[maxn];
int s[maxn];
int n;

void tc()
{
    cin >> n;
    cin >> stri;
    for (int i = 1; i <= n; i++)
    {
        str[i] = stri[i-1];
    }

    int j = n;
    for (int i = n; i >= 1; i--)
    {
        if (str[i] == 'P')
        {
            if (i == j)
            {
                j--;
                continue;
            }
            ds[i] += 1;
            ds[i+1] += 1;
            ds[j] -= 1;
            ds[j+1] -= 1;
            j--;
        }
    }

    for (int i = 1; i <= n; i++)
    {
        s[i] = s[i-1] + ds[i];
    }

    for (int i = 1; i <= n; i++)
    {
        cout << s[i] << " ";
    }
    cout << endl;
}

int main()
{
    tc();
}