description
stringlengths
35
9.39k
solution
stringlengths
7
465k
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") using namespace std; const long double EPS = 1e-8; const int inf = 1e9; const long double PI = acos(-1); int mod = (int)998244353; const int MOD7 = 1000000007; const int MOD9 = 1000000009; const int a228 = 18; const long long kekmod = 1791791791; const long ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
for g in range(0,1): n=int(input()) s=input() b=0 w=0 indexb=[] indexw=[] for i in range(0,len(s)): if(s[i]=="B"): b=b+1 indexb.append(i+1) else: w=w+1 indexw.append(i+1) ops=0 position=[] if(b==0): print(0) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def can(S, c): ans = '' nc = False for i in range(len(S)): if (S[i] != c and nc==False) or (S[i]==c and nc==True): ans += str(i+1) + ' ' nc = True else: nc = False if nc == True: return False return ans n = int(input()) s = input() ans = ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
t = int(input()) s = input() white = [] white_count = 0 temp = list(s) for j in range(len(s)-1): if(temp[j]=='B'): white_count+=1 temp[j+1]='W' if temp[j+1]=='B' else 'B' white.append(j+1) if(temp[-1]=='W'): print(white_count) if(len(white)!=0): print(*white) else: black ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; inline long long gcd(long long a, long long b) { a = ((a) < 0 ? -(a) : (a)); b = ((b) < 0 ? -(b) : (b)); while (b) { a = a % b; swa...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input().strip()) blocks = list(input().strip()) c = blocks[0] cnt = 0 for b in blocks: if b == c: cnt += 1 if cnt%2 and (n-cnt)%2: print(-1) else: moves = [] if (n-cnt)%2: c = 'W' if c == 'B' else 'B' for i in range(n-1): if blocks[i] != c: blocks[i] = c ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; vector<char> v1; for (i = 0; i < n; i++) { char in; cin >> in; v1.push_back(in); } vector<int> v2; for (i = 0; i < n - 1; i++) { if (v1[i] != 'W') { v2.push_back(i + 1); v1[i] = 'W'; if (v1[i +...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def num(): return int(input()) def line(): return map(int, input().split()) n = num() s = [c=='B' for c in input()] ans=[] for k in range(3): q=s[0] for i in range(1,n-1): if s[i]!=q: ans.append(i+1 if k%2==0 else n-i-1) s[i]=1-s[i] s[i+1]=1-s[i+1] if s[-...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import sys def I(): return sys.stdin.readline().rstrip() def main(): n = int(I()) s = I() ind = [] l = [ i == 'W' for i in s ] for i in range(n - 1): if l[ i ]: ind.append( i + 1 ) l[ i ] = not l[ i ] l[ i + 1 ] = not l[ i + 1 ] if not l[ -1 ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import sys import math import bisect def solve1(A, ans): n = len(A) ans.clear() for i in range(n - 1): if A[i] != 'B': A[i] = 'B' if A[i+1] == 'W': A[i+1] = 'B' else: A[i+1] = 'W' ans.append(i) #print('A: ' + str(A)...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class CF { private static Scanner cin = new Scanner(System.in); static final int N = 100111; static int tc; int n, q, c; int a[]; boolean use[]...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def swap(l,n,i): if(l[i]=='B'): l[i]='W' else: l[i]='B' return l def check(l,n,col): if(col=='B'): for i in l: if(i=='W'): return False return True else: for i in l: if(i=='B'): return False retur...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=input() i=0 a=[i for i in s] flag=1 arr1=[] while i<n: if a[i]=='W': i+=1 continue else: if i==n-1: flag=0 break a[i]='W' if a[i+1]=='B': a[i+1]='W' else: a[i+1]='B' arr1.append(i+1) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
inp = lambda cast=int: [cast(x) for x in input().split()] printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs) n, = inp() A, = inp(str) b = A.count('B') w = n - b A = list(A) B = A[::] if b%2 and w%2: print(-1) else: res, flag = 0, False R = [] for i in range(n-1): ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=input() a = [] for i in s: if i == "B": a.append(0) else: a.append(1) ans = [] st = a[0] for i in range(1,len(s)-1): if a[i]!=st: a[i]=(a[i]+1)%2 a[i+1]=(a[i+1]+1)%2 ans.append(i+1) st=a[i] if a[n-1]!=a[n-2] and n%2==1: for i in range(0,n-2,...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; int sum = 0; for (int i = 0; i < n; i++) { sum += (s[i] == 'B'); } vector<int> A; if (sum % 2 == 0) { for (int i = 0; i < n - 1; i++) { if (s[...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) seq = input() S = [(0 if c == 'W' else 1) for c in seq] operations = [] if seq.count('W') % 2 == 0: # transform all W -> B for start in range(n - 1): if S[start] == 0: S[start] = 1 - S[start] S[start + 1] = 1 - S[start + 1] operations.append(start +...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import sys n = int(input()) ss = raw_input() s = list(ss) w, b = 0, 0 for c in s: if c == 'W': w += 1 else: b += 1 if(w&1 and b&1): print -1 sys.exit(0) ans = list() if(w&1): for i in range(len(s)): if s[i] == 'B': ans.append(i+1) if i+1 < len(s): s[i+1] = 'B' if s[i+1] == 'W' else 'W' else: for i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const int MAX = 205; char input[MAX], s[MAX]; vector<int> v; map<char, char> mp; int main() { mp['W'] = 'B'; mp['B'] = 'W'; int n; scanf("%d%s", &n, input); strcpy(s, input); int tot = 0; for (int i = 0; i < n - 1; i++) if (s[i] == 'W') { s[i] = 'B';...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=input() b=s.count("B") w=s.count("W") f=False count=0 answer=[] if b%2!=0 and w%2!=0: print(-1) else: if b%2!=0: i=0 while i<(n-1): if s[i] == "W": f = True if f: count+=1 answer.append(i+1) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
a=int(input()) qqq=input() b=list(qqq) ans=[] p='B' q='W' for i in range(len(b)-1): if b[i] != p: b[i]=p ans.append(i+1) if b[i+1]==p: b[i+1]=q else : b[i+1]=p if b==list('W'*len(b)) or b == list('B'*len(b)): ans.reverse() if len(ans) == 0: pri...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def sol(): n = int(input()) s = input() b = sum(map(lambda x: x == 'B', s)) w = sum(map(lambda x: x == 'W', s)) if w % 2 == 1 and b % 2 == 1: print(-1) return ans = list() s = list(s) if w % 2 == 1: odd = 'W' even = 'B' else: odd = 'B' even = 'W' for i in range(n-1)...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def f(): n = int(input()) d = {'B':0,'W':1} line = [d[char] for char in input()] # print(line) if not any(line): print(0) return if all(line): print(0) return modify0 = [] modify1 = [] for i in range(n): if line[i]: modify1.append(...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#Bhargey Mehta (Junior) #DA-IICT, Gandhinagar import sys, math, queue, collections MOD = 10**9+7 #sys.stdin = open('input.txt', 'r') n = int(input()) s = list(input()) t = s[:] ans = [] for i in range(n-1): if s[i] == 'W': s[i] = 'B' if s[i+1] == 'W': s[i+1] = 'B' else: ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=input() t1=s.count('B') t2=s.count('W') a=[x for x in s] if t1%2==1 and t2%2==1: print("-1") else: c=0 a1=[] b="#" if t2%2==0: b="W" else: b="B" for i in range(n-1): if(a[i]==b): c+=1 if(a[i+1]=='W'): a[i+1]='B' else: a[i+1]='W' a1.append(i+1) print(c) print(*a1)
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; vector<long long int> change(string& s, char a, char b, long long int a_count, long long int b_count, long long int n) { vector<long long int> steps; long long int p1 = 0; while (p1 < n && a_count) { while (s[p1] == b) p1++; long l...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int b = 0, w = 0; for (int i = 0; i < n; i++) { if (s[i] == 'B') b++; else w++; } int count = 0; vector<int> a; if (b == 0 || w == 0) { cout << 0 << endl; return 0; } else if...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int b, i, j, k, m, n, w, x[600]; string s; void P(int i) { if (s[i] == 66) s[i] = 87; else s[i] = 66; } int main() { cin >> n >> s; for (; i < n; i++) s[i] % 2 ? w++ : b++; if (n % 2 < 1 && w % 2) m = 1; else if (n % 2 < 1) { for (i = 0; i < n - ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string colors; cin >> colors; vector<int> col(n); for (int i = 0; i < n; i++) col[i] = (colors[i] == 'W' ? 0 : 1); int p = col[0]; int k = 0; vector<int> op; for (int i = 1; i < n - 1;) { if (col[i] == p) i += 1; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def inv(c): if(c=="W"): return "B" else: return "W" n = int(input()) bs = list(input()) rs = [inv(s) for s in bs] changes = 0 cindex = [] flag = False while(len(bs)>2): el = len(bs) if(bs[el-1]=="W"): bs[el-1]="B" bs[el-2]=inv(bs[el-2]) changes += 1 cinde...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
//package CodeForces; import java.util.ArrayList; import java.util.Scanner; public class Blocks { static boolean solve(char ch[],int index,char x,ArrayList<Integer> arr) { if(index==ch.length) { StringBuilder ans=new StringBuilder(); System.out.println(arr.size()); for(int i=0;i<arr.size();i++) { ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); U...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using dl = double; const int N = 2e5 + 10; ll aarray[200000 + 10]; ll magic[101][101]; vector<ll> primes; bool prime[1000001]; vector<ll> B, W; int main() { ios_base::sync_with_stdio(false); string str, black, white; ll i, j, n, m, k, t; ve...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
b=int(input()) s=input() cb=s.count('B') cw=s.count('W') o='' co=0 if cb==0 or cw==0: print(0) elif cw%2==0: i=0 while i!=b-1: if s[i]=='W': c='B' if s[i+1]=='W': ci='B' else: ci='W' s=s[:i]+c+ci+s[i+2:] co+=...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
/* * * @Author Ajudiya_13(Bhargav Girdharbhai Ajudiya) * Dhirubhai Ambani Institute of Information And Communication Technology * */ import java.util.*; import java.io.*; import java.lang.*; public class Code56 { public static void main(String[] args) { InputReader in = new InputReader(System....
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long flag = 0, flag2 = 0; map<long long, lon...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public class test5 { public static final int mod=1000000007; public static void main(String[] args) throws IOException{ BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); //Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out)...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 1; int main() { int n; cin >> n; string s; cin >> s; string st = s; vector<int> output1, output2; for (int j = 0; j < 3; ++j) { for (int i = 0; i < n - 1; ++i) { if (s[i] == 'W') { output1.push_back(i + 1); s[i] ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; public class Block608 { public static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); sc.nextLine(); String str = sc.nextLine(); StringBuilder sub = new StringBuilder(str); ArrayList<Character> list = new ArrayList<>(); list....
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; int n; cin >> n; string s; cin >> s; string r = s; vector<int> v1, v2; for (long long i = 0; i < n; i++) { if (s[i] == 'W' && i < n - 1) { if (s[i + 1] == 'W') { ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") using namespace std; long long int n, a = 0, b = 0; string second; vector<long long int> v; int32_t main() { ios_base::sync_with_stdio(); cin.tie(); cout.tie(); ; cin >> n >> second; for (long long int i = 0; i < n; i++) i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; public class Blocks{ static Scanner in=new Scanner(System.in); public static void main(String array[]){ int n=in.nextInt(); char ch[]=in.next().toCharArray(); int white=0,black=0; ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0;i<n;i++){ if(ch[i]=='W') ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; vector<int> ans; int ct = 0; for (int i = int(0); i <= int(n - 1); i++) { if (s[i] == 'W') ct++; } int ct2 = n - ct; if (ct % 2 && ct2 ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) s = input() cnt = list() x = 0 if s.count('B') % 2 == 1 and s.count('W') % 2 == 1: print(-1) else: if s.count('B') % 2 == 0: while s.count('B') != 0: for i in range(s.find('B') + 1, s[s.find('B') + 1::].find('B') + s.find('B') + 2): cnt.append(str(x + i)) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
# HEY STALKER from collections import Counter n = int(input()) l = list(input()) x = Counter(l) if x['B'] % 2 and x['W'] % 2: print(-1) elif x['B'] == n or x['W'] == n: print(0) else: k = [] b = '' w = '' if not x['B'] % 2: b = 'B' w = 'W' else: b = 'W' w = 'B...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=input() sw=list(s) sb=list(s) ans=0 l=[] for j in range(n-1): if sw[j]=='B': sw[j]='W' sw[j+1]='W' if sw[j+1]=='B' else 'B' ans+=1 l.append(j+1) if sw[n-1]=='W': print(ans) print(*l) else: ans=0 l=[] for j in range(n-1): if sb[j]=='W': ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; import java.lang.Math; public class Main{ static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter writer; static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } static long nextLong() throws IOException { return Lon...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int count = scanner.nextInt(); String s = scanner.next(); StringBuffer str = n...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + c - '0'; c = getchar(); } return x * f; } int n, ans[10000], ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import sys input = sys.stdin.readline def sol(): n = int(input()) s = list(input()) b = s.count('B') w = s.count('W') if w % 2 == 1 and b % 2 == 1: print(-1) return ans = [] s = list(s) if w % 2 == 1: odd = 'W' even = 'B' else: odd = 'B' even = 'W' for i in range(n-1): i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; public class Ques2 { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()), i; Str...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def rev(s): if s=="B": return "W" else: return "B" n=int(input()) s=list(input()) ans=[] if n%2==0: if s.count("B")%2==1: print (-1) exit() if s.count("B")%2==0: i=0 while i<n-1: if s[i]=="B": ans.append(i+1) s[i+1]=rev(s[i+1]) i+=1 else: i=0 while i<n-1: if s[i]=="W": ans.append(i+1) s...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
# for t in range(int(input())): # s = input() # i, j = 0, 0 # cnt = 0 # ans = float('inf') # dic = {} # while j < len(s): # if len(dic) < 3: # dic[s[j]] = dic.get(s[j], 0) + 1 # # print(j) # # print(dic) # while len(dic) == 3: # ans = min(a...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int64_t n; cin >> n; string s, a, b; cin >> s; a = s, b = s; vector<int64_t> black, white; for (int64_t i = 0; i < n - 1; ++i) { if (a[i] == 'B') { white.push_back(i + 1); a[i] ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
from math import factorial from collections import Counter, defaultdict from heapq import heapify, heappop, heappush import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.bu...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; import java.io.*; import java.math.BigInteger; public class Main implements Runnable { static Scanner in; // static FastReader in; static PrintWriter out; static int[][] dirs8 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}}; static int[][] dirs = {{1, 0}, {-1, 0},...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; using namespace std; void rev(char &c) { if (c == 'W') c = 'B'; else c = 'W'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; bool b = 1; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) a = input() def go(s, x): b = [1 if c == 'B' else 0 for c in s] o = [] n = len(b) for i in range(n): if b[i] != x: if i + 1 >= n: return 0 o += i + 1, b[i + 1] = b[i + 1] ^ 1 print(len(o)) print(' '.join(map(str, o))) return 1 if not go(a, 0) and not go(a...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int mod = 998244353; const double PI = acos(-1); int main() { int n; cin >> n; string s; cin >> s; int c = 0; vector<int> v; for (int i = (0); i < (n - 1); i++) { if (s[i] == 'B' && s[i + 1] == 'W') { s[i] = 'W'; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int mod = 998244353; const int INF = 0x3f3f3f3f; char s[300]; int main() { int n; scanf("%d", &n); scanf("%s", s); int w = 0, b = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') w++; else b++; } if (w % 2 ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.math.*; import java.util.*; public class test { public static void main(String[] args) { // int test = fs.nextInt(); int test = 1; for (int cases = 0; cases < test; cases++) { int n = fs.nextInt(); String s = fs.next(); boolean ans1 = false; boolean ans2 = false; Str...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.math.*; import java.util.*; public class blocksthatarebw { public static void main(String[] args) throws IOException { FastScanner scan = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int n = Integer.parseInt(scan.nextToken()); ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
// template : secondThread import java.io.*; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class main2 { public static void main(String[] args) { try { PrintWriter fop = new PrintWriter(System.out); ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.Stack; import javax.swing.event.ListSelectionEvent; public class ROUGH{ public static class FastReader { BufferedReader br; StringTokenizer root; public FastReader() { br = new BufferedReader(new InputStreamReader(Sys...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; using pii = pair<long long, long long>; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; string b; cin >> b; string a = b; vector<long long> ans; for (long long i = 0; i + 1 < n; i++) { ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int w = 0; int b = 0; int c = 0; int f = 0; vector<int> vec; for (int i = 0; i < n; i++) { if (s[i] == 'B') { b++; } else { w++; } } if (w % 2 != 0 && b % 2 != 0) { cout <<...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def main(): N = int(input()) P = list(map(lambda x: 0 if x == "W" else 1, input())) for c in range(2): PP = P.copy() res = [] for i in range(N-1): if PP[i] != c: res.append(i+1) PP[i+1] = 1 - PP[i+1] if PP[N-1] == c: pri...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public class B { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String st = sc.nextLine(); char s1[] = st.toCharArray(); char s2[] = new char[st.length()]; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=input().strip() if s.count('W')==0 or s.count('B')==0: print(0) elif s.count('W')%2==1 and s.count('B')%2==1: print(-1) else: if s.count('B')%2==0: x=[] for i in range(n): if s[i]=='B': x.append(i) an=[] for i in range(0,len(x),...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) l=list(input()) d={'B':'W','W':'B'} ans=[] for i in range(1,len(l)-1): if l[i-1]!=l[i]: l[i]=d[l[i]] l[i+1]=d[l[i+1]] ans.append(i+1) f=0 if l[-2]!=l[-1]: if n&1: for i in range(n-2,0,-2): ans.append(i) else: f=1 print(-1) if f==0: ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class BTask { private static final String QUICK_ANSWER = "NO"; private final Input in; private final StringBuilder out; public BTask(Input in, StringBuilder out) { this.in = in; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) s=list(input().strip()) b=s.count('B') w=s.count('W') res=[] if(b%2 and w%2): print(-1) elif(b%2==0): i=n-1 while i-1>=0: #print(i,s[i]) if(s[i]=='W'): i-=1 elif(s[i]=='B' and s[i-1]=='B'): res.append(i) s[i]='W' s[i-1]=...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, ans; cin >> s; ans = s; vector<int> v; for (int i = 0; i < ans.length() - 1; i++) { if (ans[i] != 'B') { v.push_back(i + 1); ans[i] = 'B'; if (ans[i + 1] == 'B') ans[i + 1] = 'W'; else...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public class HelloWorld { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter(System.out); int n = Integer.parseInt(br.readLine()); String s = ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Blocks { public static String opp(String s) { if (s.equals("B")) return "W"; else return "B"...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; public class practice { public static void main(String[] args) { Scanner scn =new Scanner(System.in); int n=scn.nextInt(); scn.nextLine(); String s=scn.nextLine(); int white=0,black=0; for(int i=0;i<n;i++) { char ch=s.charAt(i); if(ch=='W') { white++; }else { black++;...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public final class code // class code // public class Solution { static void solve()throws IOException { int n=nextInt(); char s[]=(" "+nextLine()).toCharArray(); int w=0,b=0; for(int i=1;i<=n;i++) { if(s[i]=='B') b++; else w++; } if(w%2!=0 && b%2!=0) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; /* Name of the class has to be "Main" only if the...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static int check(char[] ch) { int B = 0, W = 0; for (int i = 0; i ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; public class _1271B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); int b = 0, w = 0; for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (ch ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; long long n, arr[200 + 5]; vector<long long> ans; string s; bool tf = 1; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> s; for (long long i = 0; i < n; i++) { if (s[i] == 'B') arr[i] = 0; else arr[i] = 1; } for (long long...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; map<char, char> m; int a[N]; int main() { int n, cnt = 0, t; string s, s1; cin >> n >> s; m['B'] = 'W'; m['W'] = 'B'; s1 = s; t = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == 'B') { a[cnt++] = i + 1; s[i] = m[s[i]]...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.ArrayList; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n =sc.nextInt(); char[] s = sc.next().toCharArray(); if(allSameCharacters(s)){ System.out.println(0); ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n=int(input()) a=input().strip() a1=list(a) c1=0 c2=0 x=[] c=0 for i in a: if i=="B": c1+=1 elif i=="W": c2+=1 if c1==0 or c2==0 : print(0) elif c1%2==1 and c2%2==1: print(-1) elif c2>=c1: for i in range(n-1): if a1[i]=="W" and a1[i]==a1[i+1]: a1[i]="B" ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
/*** * β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—=====β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—====β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—====β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—= * β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—====β–ˆβ–ˆβ•”β•β•β•β•β•====β–ˆβ–ˆβ•”β•β•β•β•β•====β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— * β–ˆβ–ˆβ•‘==β–ˆβ–ˆβ•‘====β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—======β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—======β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• * β–ˆβ–ˆβ•‘==β–ˆβ–ˆβ•‘====β–ˆβ–ˆβ•”β•β•β•======β–ˆβ–ˆβ•”β•β•β•======β–ˆβ–ˆβ•”β•β•β•β•= * β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•====β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—====β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—====β–ˆβ–ˆβ•‘===== * β•šβ•β•β•β•β•β•=====β•šβ•β•β•β•β•β•β•====β•šβ•β•β•β•β•β•β•====β•šβ•β•===== * ===...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; public class Main { public static void printAns(Vector<Integer> v) { System.out.println(v.size()); for(Integer i : v) System.out.print(i + " "); } public static void checkInvert(Vector<Integer> v, boolean[] a, int i, int j, int k) { if(a[i] != a[j...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public class Main { static int s, n, c; static long[] mem; static int[] arr; static class pair implements Comparable<pair>{ int f;int s; public pair(int ff,int ss){ f=ff; s=ss; } @Override public int compareTo(pair o) { ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
from __future__ import division, print_function import os import sys from io import BytesIO, IOBase from sys import stdin,stdout from collections import Counter from math import ceil from bisect import bisect_left from bisect import bisect_right import math if sys.version_info[0] < 3: from __builtin__ import xra...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#! /usr/bin/env python # -*- coding: utf-8 -*- def abc(l: list): def slip(n): if l[n] == 'B': l[n] = 'W' else: l[n] = 'B' if l[n+1] == 'B': l[n+1] = 'W' else: l[n+1] = 'B' def move1(): for i in range(long-1): ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class MAIN { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br =...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
a=int(input()) b=input().replace('',' ').split() c="";k=[] for i in range(a-1): if b[i]=='B':c+='W';b[i]='W';b[i+1]='BW'[b[i+1]!='W'];k+=[i+1] else:c+='W' if len(c)!=len(b):c+=b[-1] b=''.join(c) if b[-1]=='W':print(len(k));print(*k) else: if (a-1)%2:print(-1) else:print(len(k)+(a-1)//2);print(*k,*range(...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> bool notsame(char* c, int len) { bool a = false; for (int i = 0; i < len - 1; ++i) { if (c[i] != c[i + 1]) a = true; } return a; } bool notpresent(int* nums, int ele, int idx) { bool a = true; for (int i = 0; i < idx; i++) { if (nums[i] == ele) a = false; } return a; } i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
from fractions import Fraction as F import math import sys import random import time random.seed(time.time()) fi = sys.stdin fo = sys.stdout fe = sys.stderr exit = sys.exit readline = raw_input def readargs(tp=None): if tp is not None: return map(tp, readline().split()) return readline().split() def yesno(flag...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) s = input() b = s.count("B") w = s.count("W") f = 0 res = 0 ans = [] if b % 2 != 0 and w % 2 != 0: print(-1) else: if b % 2 != 0: i = 0 while i < (n - 1): if s[i] == "W": f = 1 if f==1: res += 1 ans.append(...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; char s[222]; int n; vector<int> r; bool colit(int type) { for (int i = 1; i < n - 1; i++) if (s[i] != type) { r.push_back(i + 1); s[i] ^= 1, s[i + 1] ^= 1; } if (s[n - 1] != type) return 0; return 1; } int main() { scanf("%d%s", &n, s); for (in...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, b = 0, w = 0, ans = 0; cin >> n; string str; cin >> str; vector<long long int> vec; for (long long int i = 0; i < n; ++i) { if (str[i] == 'B') ++b; else ++w; } if (b % 2 == 1 && w % 2 == 1) cout << "-1"; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#!/usr/bin/env python3 import sys input = sys.stdin.readline n = int(input()) s = input().rstrip() bcnt = s.count("B") wcnt = s.count("W") if bcnt % 2 == 1 and wcnt % 2 == 1: print(-1) exit() s_l = list(s) ans = [] for i in range(n-1): if s_l[i] == "W": ans.append(i + 1) s_l[i] = "B" ...