#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s; cin >> s; vector<pair<int, int> > v(n); int Ls = count(s.begin(), s.end(), 'L'); for (int i = 0; i < Ls; i++) { if (i == 0) { if (s[i] == 'P') { v[i] = {0, 1}; } } else { if (s[i] == 'P') { v[i] = {v[i - 1].second, v[i - 1].second + 1}; } else { v[i] = {v[i - 1].second, v[i - 1].second}; } } } for (int i = n - 1; i >= Ls; i--) { if (i == n - 1) { if (s[i] == 'L') { v[i] = {0, 1}; } } else { if (s[i] == 'L') { v[i] = {v[i + 1].second, v[i + 1].second + 1}; } else { v[i] = {v[i + 1].second, v[i + 1].second}; } } } for (auto& [first, second] : v) { cout << first + second << " "; } 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s; cin >> s; vector<pair<int, int> > v(n); int Ls = count(s.begin(), s.end(), 'L'); for (int i = 0; i < Ls; i++) { if (i == 0) { if (s[i] == 'P') { v[i] = {0, 1}; } } else { if (s[i] == 'P') { v[i] = {v[i - 1].second, v[i - 1].second + 1}; } else { v[i] = {v[i - 1].second, v[i - 1].second}; } } } for (int i = n - 1; i >= Ls; i--) { if (i == n - 1) { if (s[i] == 'L') { v[i] = {0, 1}; } } else { if (s[i] == 'L') { v[i] = {v[i + 1].second, v[i + 1].second + 1}; } else { v[i] = {v[i + 1].second, v[i + 1].second}; } } } for (auto& [first, second] : v) { cout << first + second << " "; } cout << "\n"; return 0; } |