#include <iostream>
using namespace std;
const int mxN = 3e5 + 13;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, jed = 0;
cin >> n;
string s;
cin >> s;
int dod = 0, ost = n - 1;
for (int i = 0; i < n; i++)
jed += s[i] == 'P';
for (int i = n - 1; i >= 0; i--)
if (s[i] == 'P')
ost--;
else
break;
for (int i = 0; i < n; i++)
{
int odp = 2 * dod;
if (i >= n - jed)
odp--, dod--;
dod += s[i] == 'P';
odp += s[i] == 'P';
cout << odp << ' ';
}
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 | #include <iostream> using namespace std; const int mxN = 3e5 + 13; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, jed = 0; cin >> n; string s; cin >> s; int dod = 0, ost = n - 1; for (int i = 0; i < n; i++) jed += s[i] == 'P'; for (int i = n - 1; i >= 0; i--) if (s[i] == 'P') ost--; else break; for (int i = 0; i < n; i++) { int odp = 2 * dod; if (i >= n - jed) odp--, dod--; dod += s[i] == 'P'; odp += s[i] == 'P'; cout << odp << ' '; } return 0; } |
English