#include <iostream> #include <vector> using namespace std; int main() { int n; string m; cin >> n >> m; vector<int> cntL; vector<int> cntP; cntL.resize(n); cntP.resize(n); int c = 0; for (int i = 0; i < n; ++i) { cntP[i] = c; if (m[i] == 'P') c++; } c = 0; for (int i = n-1; i >= 0; --i) { cntL[i] = c; if (m[i] == 'L') c++; } for (int i = 0; i < n; ++i) { int l = cntL[i]; int p = cntP[i]; if (m[i] == 'P') { swap(l, p); } if (p > l) cout << 2*l+1 << ' '; else cout << 2*p << ' '; } 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 | #include <iostream> #include <vector> using namespace std; int main() { int n; string m; cin >> n >> m; vector<int> cntL; vector<int> cntP; cntL.resize(n); cntP.resize(n); int c = 0; for (int i = 0; i < n; ++i) { cntP[i] = c; if (m[i] == 'P') c++; } c = 0; for (int i = n-1; i >= 0; --i) { cntL[i] = c; if (m[i] == 'L') c++; } for (int i = 0; i < n; ++i) { int l = cntL[i]; int p = cntP[i]; if (m[i] == 'P') { swap(l, p); } if (p > l) cout << 2*l+1 << ' '; else cout << 2*p << ' '; } return 0; } |