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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>

using namespace std;
int ile,i,l,p,x=0,y=0;
string ciag;
int main()
{
    cin>>ile;
    cin>>ciag;
    int mrowki[ile];
    i=0;
    while(ciag[i]=='L' && i<ile-2)
    {
        mrowki[i]=0;
        i++;
    }
    l=i;
    i=ile-1;
    while(ciag[i]=='P' && i>=0)
    {
        mrowki[i]=0;
        i--;
    }
    p=i;
     for(i=l;i<p;i++)
    {
        mrowki[i]=0;
    }
    for(i=l;i<=p;i++)
    {
        if(ciag[i]=='L')
        {
            y++;
        }
    }
    for(i=l;i<=p;i++)
    {
       if(ciag[i]=='L')
       {
           y--;
       }
       if(i-l>=y)
       {
         mrowki[i]+=y;
       }
       else
       {
         mrowki[i]+=i-l;
       }
       if(p-i>=x)
       {
           mrowki[i]+=x;
       }
       else
       {
           mrowki[i]+=p-i;
       }
       if(ciag[i]=='P')
       {
         x++;
       }

    }
    for(i=0;i<l;i++)
    {
        cout << 0 << " ";
    }
    cout<< mrowki[l]+1 << " ";
    for(i=l+1;i<ile-1;i++)
    {
        cout << mrowki[i] <<" ";
    }
    cout << mrowki[i]+1;
    return 0;
}