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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <cstdio>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

int n;
int num_final_dest = 0;

std::vector<float>  tab_position;
std::string         tab_direction;
std::vector<int>    tab_bump_num;


void changeDirection(int i){
  if(tab_direction[i] == 'P'){
    tab_direction[i] = 'L';
  }
  else{
    tab_direction[i] = 'P';
  }
}


int main () {
  std::cin >> n ;

  if (n <= 1 || n >= 300000){
    std::cout << "error num input" << std::endl;
    return 1;
  }

  for (int i = 0; i < n; i++) {
    tab_position.push_back(i);
    tab_bump_num.push_back(0);
  }

  std::cin >> tab_direction;

  if(tab_direction.length() != n){
    std::cout << "error string input" << std::endl;
    return 1;
  }

  while (num_final_dest != n) {
    //set zero for next counting
    num_final_dest = 0;

    //move
    for(int i = 0;i < n; i++){
      if(tab_direction[i] == 'L'){
        if(tab_position[i] == 0){
          num_final_dest++;
        }else{
          tab_position[i] -= 0.5;
        }
      }else if(tab_direction[i] == 'P'){
        if(tab_position[i] == float(n)){
          num_final_dest++;
        }else{
          tab_position[i] += 0.5;
        } 
      }else{
        std::cout << "error char" << std::endl;
        return 1;
      }
    }
    //resolve bumps
    for(int j = 0; j < n-1; j++){
     for(int k = j+1; k < n; k++){
        if(tab_position[j] == tab_position[k] && tab_direction[j] != tab_direction[k]){
          tab_bump_num[j]++;
          tab_bump_num[k]++;

          changeDirection(j);
          changeDirection(k);

          break;
        }
      }
    }
  }

  for(int i = 0; i < tab_bump_num.size(); i++){
    printf("%d ",tab_bump_num.at(i));
  }
  printf("\n");
	
  return 0;
}