#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
string s;
cin >> n >> s;
int odp[n+1];
deque<int> ant;
for (int i = 0; i < n; i++)
odp[i] = 0, ant.push_back(i);
while (!ant.empty()) {
while (!ant.empty() && s[ant.front()] == 'L')
ant.pop_front();
while (!ant.empty() && s[ant.back()] == 'P')
ant.pop_back();
if (ant.empty())
continue;
odp[ant.front()]++, odp[ant.back()+1]--;
ant.pop_front(), ant.pop_back();
if (!ant.empty())
odp[ant.front()]++, odp[ant.back()+1]--;
}
for (int i = 0; i < n; i++)
cout << odp[i] << " ", odp[i+1] += odp[i];
cout << endl;
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string s; cin >> n >> s; int odp[n+1]; deque<int> ant; for (int i = 0; i < n; i++) odp[i] = 0, ant.push_back(i); while (!ant.empty()) { while (!ant.empty() && s[ant.front()] == 'L') ant.pop_front(); while (!ant.empty() && s[ant.back()] == 'P') ant.pop_back(); if (ant.empty()) continue; odp[ant.front()]++, odp[ant.back()+1]--; ant.pop_front(), ant.pop_back(); if (!ant.empty()) odp[ant.front()]++, odp[ant.back()+1]--; } for (int i = 0; i < n; i++) cout << odp[i] << " ", odp[i+1] += odp[i]; cout << endl; return 0; } |
English