#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
string s;
cin>>s;
int suma = 0;
int w_przeciw = 0;
vector <int> Ans_1;
for (auto &x: s) {
if (x == 'P'){
Ans_1.push_back(2*w_przeciw+1);
w_przeciw+=1;
}
else{
Ans_1.push_back(2*w_przeciw);
}
}
w_przeciw = 0;
reverse(s.begin(), s.end());
for(auto &x: s){
n--;
if(x=='L'){
Ans_1[n]=min(2*w_przeciw+1,Ans_1[n]);
w_przeciw+=1;
}
else{
Ans_1[n]=min(2*w_przeciw,Ans_1[n]);
}
}
for(auto &x: Ans_1){
cout<<x<<" ";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
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 | #include <bits/stdc++.h> using namespace std; void solve(){ int n; cin>>n; string s; cin>>s; int suma = 0; int w_przeciw = 0; vector <int> Ans_1; for (auto &x: s) { if (x == 'P'){ Ans_1.push_back(2*w_przeciw+1); w_przeciw+=1; } else{ Ans_1.push_back(2*w_przeciw); } } w_przeciw = 0; reverse(s.begin(), s.end()); for(auto &x: s){ n--; if(x=='L'){ Ans_1[n]=min(2*w_przeciw+1,Ans_1[n]); w_przeciw+=1; } else{ Ans_1[n]=min(2*w_przeciw,Ans_1[n]); } } for(auto &x: Ans_1){ cout<<x<<" "; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; } |
English