#include <bits/stdc++.h>
using namespace std;
int n, l, p;
string s;
int t[300000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cin >> s;
for (char c : s)
{
if (c == 'L') l++;
else p++;
}
for (int i = 0; i < n-1; i++)
{
char cel = ((i < l) ? 'L' : 'P');
int dodaj = 0;
if (cel == s[i])
dodaj = t[i];
else
{
if (s[i] == 'P') dodaj = t[i] + 1;
else dodaj = t[i] - 1;
}
t[i] += dodaj;
t[i + 1] += dodaj;
}
for (int i = 0; i < n; i++)
cout << t[i] << ' ';
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; int n, l, p; string s; int t[300000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; cin >> s; for (char c : s) { if (c == 'L') l++; else p++; } for (int i = 0; i < n-1; i++) { char cel = ((i < l) ? 'L' : 'P'); int dodaj = 0; if (cel == s[i]) dodaj = t[i]; else { if (s[i] == 'P') dodaj = t[i] + 1; else dodaj = t[i] - 1; } t[i] += dodaj; t[i + 1] += dodaj; } for (int i = 0; i < n; i++) cout << t[i] << ' '; return 0; } |
English