// Witold Milewski
// PA 2024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
const int maxn=3e5+7;
int A[maxn], pref[maxn], n;
string s;
int main() {
cin.tie(0) -> ios_base::sync_with_stdio(0);
cin >> n;
cin >> s;
set<int> left;
FOR(i, 1, n) {
A[i]=(s[i-1]=='P');
if(!A[i]) left.insert(i);
}
FOR(i, 1, n) {
if(!A[i]) continue;
auto it = left.upper_bound(i);
if(it==left.end()) break;
left.erase(it);
int idx=*it;
A[idx]=1;
++pref[i]; ++pref[i+1];
--pref[idx]; --pref[idx+1];
}
FOR(i, 1, n) pref[i]+=pref[i-1];
FOR(i, 1, n) cout << pref[i] << ' ';
cout << '\n';
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 | // Witold Milewski // PA 2024 #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i=a; i<=b; ++i) const int maxn=3e5+7; int A[maxn], pref[maxn], n; string s; int main() { cin.tie(0) -> ios_base::sync_with_stdio(0); cin >> n; cin >> s; set<int> left; FOR(i, 1, n) { A[i]=(s[i-1]=='P'); if(!A[i]) left.insert(i); } FOR(i, 1, n) { if(!A[i]) continue; auto it = left.upper_bound(i); if(it==left.end()) break; left.erase(it); int idx=*it; A[idx]=1; ++pref[i]; ++pref[i+1]; --pref[idx]; --pref[idx+1]; } FOR(i, 1, n) pref[i]+=pref[i-1]; FOR(i, 1, n) cout << pref[i] << ' '; cout << '\n'; return 0; } |
English