#include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=3e5+5; int n;string s; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>s; int L=count(s.begin(),s.end(),'L'),R=0; for(int i=0;i<n;++i){ if(s[i]=='L'){ if(L<=R)cout<<2*L-1<<' '; else cout<<2*R<<' '; --L; } else{ ++R; if(R<=L)cout<<2*R-1<<' '; else cout<<2*L<<' '; } } 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 | #include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=3e5+5; int n;string s; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>s; int L=count(s.begin(),s.end(),'L'),R=0; for(int i=0;i<n;++i){ if(s[i]=='L'){ if(L<=R)cout<<2*L-1<<' '; else cout<<2*R<<' '; --L; } else{ ++R; if(R<=L)cout<<2*R-1<<' '; else cout<<2*L<<' '; } } return 0; } /* */ |