#include <bits/stdc++.h>
using namespace std;
int n;
string s;
array<int, 300001> pref;
void solve() {
cin >> n >> s;
pref[0] = 0;
for (int i = 0; i < n; i++) {
pref[i + 1] = pref[i] + (s[i] == 'P');
}
// for (int i = 0; i <= n; i++) cerr << pref[i] << ' '; cerr << endl;
for (int i = 0; i < n; i++) {
int l = pref[i];
int r = n - pref[n] + pref[i + 1] - i - 1;
// cerr << i << ' ' << l << ' ' << r << endl;
cout << 2 * min(l, r) + ((s[i] == 'L') ? l > r : r > l) << ' ';
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// #ifdef LOCAL
// int t; cin >> t; while (t--)
// #endif
solve();
cout.flush();
}
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 | #include <bits/stdc++.h> using namespace std; int n; string s; array<int, 300001> pref; void solve() { cin >> n >> s; pref[0] = 0; for (int i = 0; i < n; i++) { pref[i + 1] = pref[i] + (s[i] == 'P'); } // for (int i = 0; i <= n; i++) cerr << pref[i] << ' '; cerr << endl; for (int i = 0; i < n; i++) { int l = pref[i]; int r = n - pref[n] + pref[i + 1] - i - 1; // cerr << i << ' ' << l << ' ' << r << endl; cout << 2 * min(l, r) + ((s[i] == 'L') ? l > r : r > l) << ' '; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // #ifdef LOCAL // int t; cin >> t; while (t--) // #endif solve(); cout.flush(); } |
English