#include <bits/stdc++.h> #define ll int #define N 300010 using namespace std; ll n,ans[N]; string s; int main(){ ll i,j; cin>>n>>s; for(i=j=0;i<n;i++) { while(j<n&&s[j]=='P') { j++; } if(j>=n) { break; } if(i==j) { j++; continue; } ans[i]++; ans[i+1]++; ans[j]--; ans[j+1]--; j++; } for(i=1;i<n;i++) { ans[i]+=ans[i-1]; } for(i=0;i<n;i++) { cout<<ans[i]<<" "; } puts(""); 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 | #include <bits/stdc++.h> #define ll int #define N 300010 using namespace std; ll n,ans[N]; string s; int main(){ ll i,j; cin>>n>>s; for(i=j=0;i<n;i++) { while(j<n&&s[j]=='P') { j++; } if(j>=n) { break; } if(i==j) { j++; continue; } ans[i]++; ans[i+1]++; ans[j]--; ans[j+1]--; j++; } for(i=1;i<n;i++) { ans[i]+=ans[i-1]; } for(i=0;i<n;i++) { cout<<ans[i]<<" "; } puts(""); return 0; } |