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
91
92
93
94
95
96
#include <cstdio>

using namespace std;

int n, l, r, nl, nr;
char t[300000];
int w[300000];

int main() {
  scanf("%d", &n);
  scanf("%s", t);

  if (n == 1) {
    printf("0\n");
  } else {
    l = 0;
    r = n - 1;
    
    while (t[l] == 'L') {
      w[l] = 0;
      l++;
      if (l > r) {
        break;
      }
    }

    if (l <= r) {
      while (t[r] == 'P') {
        w[r] = 0;
        r--;
        if (l > r) {
          break;
        }
      }
    }

    if (l <= r) {
      w[l] = 1;
      l++;
    }

    if (l <= r) {
      w[r] = 1;
      r--;
    }

    while (l <= r) {
      if (l == r) {
        if (w[l - 1] > w [r + 1]) {
          w[l] = w[l - 1];
        } else if (w[l - 1] < w [r + 1]) {
          w[l] = w[r + 1];
        } else if (w[l - 1] % 2 == 0) {
          w[l] = w[l - 1];
        } else {
          w[l] = w[l - 1] + 1;
        }
        l++;
      } else {
        if (t[l] != t[l - 1]) {
          nl = w[l - 1] + 1;
        } else {
          if (t[l] == 'L') {
            nl = w[l - 1];
          } else {
            nl = w[l - 1] + 2;
          }
        }
        if (t[r] != t[r + 1]) {
          nr = w[r + 1] + 1;
        } else {
          if (t[r] == 'P') {
            nr = w[r + 1];
          } else {
            nr = w[r + 1] + 2;
          }
        }
        if (nl <= nr) {
          w[l] = nl;
          l++;
        } else {
          w[r] = nr;
          r--;
        }
      }
    }

    printf("%d", w[0]);
    for (int i = 1; i < n; i++) {
      printf(" %d", w[i]);
    }
    printf("\n");
  }

  return 0;
}