Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define int long long
- #define pb push_back
- #define _ << ' ' <<
- #define end << "\n"
- const int mod = 1e9 + 7;
- typedef long long ll;
- typedef long double ld;
- using namespace std;
- void solve(){
- int n;
- cin >> n;
- string a;
- cin >> a;
- vector<int> ans;
- int i = 1;
- while(i < n){
- if(a[i] == a[i - 1]){
- if(i > 1 && a[i - 2] != a[i]){
- if(a[i] == 'W'){
- a[i] = 'B';
- a[i - 1] = 'B';
- }
- else{
- a[i] = 'W';
- a[i - 1] = 'W';
- }
- ans.push_back(i - 1);
- }
- i += 2;
- }
- else{
- if(i > 1 && a[i - 2] != a[i - 1]){
- if(a[i] == 'W'){
- a[i] = 'B';
- a[i - 1] = 'W';
- }
- else{
- a[i] = 'W';
- a[i - 1] = 'B';
- }
- ans.push_back(i - 1);
- }
- else if(i + 1 < n && a[i + 1] != a[i]){
- if(a[i] == 'W'){
- a[i] = 'B';
- a[i - 1] = 'W';
- }
- else{
- a[i] = 'W';
- a[i - 1] = 'B';
- }
- ans.push_back(i - 1);
- }
- i += 1;
- }
- }
- if(a[n - 1] != a[n - 2]){
- cout << -1;
- }
- else{
- cout << ans.size() << '\n';
- for(auto x: ans){
- cout << x + 1 << ' ';
- }
- }
- }
- signed main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int we = 1;
- //cin >> we;
- while(we--){
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement