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

int n;
char a[1000000];

int result[1000000];
int adding[1000000];

vector< pair<int, int> > moves;

int main(){
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> a[i];
  }

  int lewy = 0;
  int prawy = n - 1;
  int first_l = 0;
  while(lewy < prawy) {

    while(a[lewy] == 'L')
      lewy++;
    while (a[prawy] == 'P' && lewy <= prawy)
      prawy--;
    if(lewy >= prawy)
      break;

    int i = max(lewy, first_l);
    while(a[i] == 'P')
      i++;
    if(i > prawy)
      break;
    moves.push_back({lewy + 1, i - 1});
    result[lewy] += 1;
    result[i] += 1;
    a[lewy] = 'L';
    a[i] = 'P';
    first_l = i + 1;
  }
  
  for(auto move : moves){
    adding[move.first] += 2;
    adding[move.second + 1] -= 2;
  }

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

  for(int i = 0 ; i < n ; i++){
    result[i] += adding[i];
  }

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