Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define int long long
  4. #define pb push_back
  5. #define _ << ' ' <<
  6. #define end << "\n"
  7.  
  8. const int mod = 1e9 + 7;
  9. typedef long long ll;
  10. typedef long double ld;
  11.  
  12. using namespace std;
  13.  
  14. void solve(){
  15. int n;
  16. cin >> n;
  17. string a;
  18. cin >> a;
  19. vector<int> ans;
  20. int i = 1;
  21. while(i < n){
  22. if(a[i] == a[i - 1]){
  23. if(i > 1 && a[i - 2] != a[i]){
  24. if(a[i] == 'W'){
  25. a[i] = 'B';
  26. a[i - 1] = 'B';
  27. }
  28. else{
  29. a[i] = 'W';
  30. a[i - 1] = 'W';
  31. }
  32. ans.push_back(i - 1);
  33. }
  34. i += 2;
  35. }
  36. else{
  37. if(i > 1 && a[i - 2] != a[i - 1]){
  38. if(a[i] == 'W'){
  39. a[i] = 'B';
  40. a[i - 1] = 'W';
  41. }
  42. else{
  43. a[i] = 'W';
  44. a[i - 1] = 'B';
  45. }
  46. ans.push_back(i - 1);
  47. }
  48. else if(i + 1 < n && a[i + 1] != a[i]){
  49. if(a[i] == 'W'){
  50. a[i] = 'B';
  51. a[i - 1] = 'W';
  52. }
  53. else{
  54. a[i] = 'W';
  55. a[i - 1] = 'B';
  56. }
  57. ans.push_back(i - 1);
  58. }
  59. i += 1;
  60. }
  61. }
  62. if(a[n - 1] != a[n - 2]){
  63. cout << -1;
  64. }
  65. else{
  66. cout << ans.size() << '\n';
  67. for(auto x: ans){
  68. cout << x + 1 << ' ';
  69. }
  70. }
  71. }
  72. signed main(){
  73. ios_base::sync_with_stdio(0);
  74. cin.tie(0);
  75. cout.tie(0);
  76. int we = 1;
  77. //cin >> we;
  78. while(we--){
  79. solve();
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement