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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class experiment { static int M = 1_000_000_007; static int INF = 2_000_000_000; static final FastScanner fs = new FastScanner(); //variable public...
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.text.*; public class Main{ //SOLUTION BEGIN //Into the Hardware Mode void pre() throws Exception{} void solve(int TC)throws Exception{ int n = ni(); char[] ch = n().toCharArray(); int c = 0; for(int i = 0; i< n; 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; using ll = long long int; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } v...
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, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\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...
import java.util.*; public class cagon { public static void main(String[] args) { ArrayList<Integer> caca = new ArrayList<Integer>(); Scanner scn = new Scanner(System.in); int n = scn.nextInt(); StringBuilder m = new StringBuilder(scn.next()); if(n==1) {System.out.println(0);System.exit(0);} for(int 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()) s=input() w=s.count("W") b=n-w # s=list(s) if b%2==w%2==1: print(-1) else: c=0 p=0 ans=[] x="W" if w%2==0 else "B" for i in range(n): if (s[i]==x and p==0) or (s[i]!=x and p==1): p=1 c+=1 ans.append(i+1) else: p=0 print(c) print(*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...
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Cf205 implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceChar...
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=[];w=[];v=[] n=int(input()) x=input() for i in range(n): if x[i]=='B':b+=i+1, else:w+=i+1, lb,lw=len(b),len(w) if lb%2+lw%2==2:print(-1) else: if lb%2:b,w,lb,lw=w,b,lw,lb for i in range(1,lb,2): v.extend([i for i in range(b[i]-1,b[i-1],-1)]) v+=b[i-1], print(len(v)) print(*v)
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, copy n = int(sys.stdin.readline()) arr = list(sys.stdin.readline().rstrip()) btemp = copy.deepcopy(arr) wtemp = copy.deepcopy(arr) b2w = [] w2b = [] for i in range(n - 1): if btemp[i] == 'B': btemp[i] = 'W' if btemp[i + 1] == 'B': btemp[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...
n=int(input()) x=input() numW=0 outlist=[] num=0 for letter in x: if letter=='W': numW+=1 if numW%2==1 and len(x)%2==1: t=0 while t<len(x): if x[t]=='B': outlist.append(t+1) num+=1 if x[t+1]=='W': x=x[:t]+'WB'+x[t+2:] t+=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 collections # MAX = 20 # sys.setrecursionlimit(10**6) def inpu(): return input().split(' ') def inti(a): for i in range(len(a)): a[i] = int(a[i]) return a def inp(): a = inpu() a = inti(a) return a n = int(input()) a = input() b = 0 w = 0 for i in range(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...
n=int(input()) s=input() x=s.count('B') y=s.count('W') if(x==0 or y==0): print(0) else: B=list(s) A=[] for i in range(n-1): if(B[i]=='B'): B[i]='W' A.append(i+1) if(B[i+1]=='B'): B[i+1]='W' else: B[i+1]='B' if(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() noB,noW = 0,0 for i in s : if i =="B": noB += 1 else : noW += 1 if noW%2== 1 and noB%2== 1: print(-1) elif noB==0 or noW==0 : print(0) elif noW%2== 0 and noB%2== 1 : li = [] ans = [] count = 0 for i in range(len(s)): if s[i] == "W" : li.append(i) for i in range(int(len(li...
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...
# -*- coding: utf-8 -*- import sys W = 'W' B = 'B' def try_to_color(cubes, color): # if color == W: # print('whitening...') # else: # print('blackening...') r = 0 swaps = [] cubes = list(cubes) i = 0 opposite_color = B if color == B: opposite_color = W whil...
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, j = 0, cnt = 0, w = 0, b = 0, sam = 1; cin >> n; int ans[100000]; string s; cin >> s; for (i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) sam++; } for (i = 0; i < n - 1; i++) { if (s[i] == 'B' && s[i + 1] == 'W') { swap(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.util.*; public class MyClass { public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); String str=in.next(); char[] arr=str.toCharArray(); String ans=""; int cnt=0; for(int i=0;i<n;i++){ if((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...
n=(int)(input()) s=input() t=list(s) blm=0 bll=[] blp=1 for i in range(len(t)): if t[i]=='W': if i!=len(t)-1: t[i]="B" if t[i+1]=='W': t[i+1]="B" else: t[i+1]="W" blm=blm+1 bll.append(i+1) else: 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...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; string s; cin >> s; long long int w = 0, b = 0; for (long long int i = 0; i < n; i++) { if (s[i] == 'W') w++; else b++; } v...
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) throws IOException { FastScanner f = new FastScanner(); int ttt=1; // ttt=f.nextInt(); PrintWriter out=new PrintWriter(System.out); for(int tt=0;tt<ttt;tt++) { int n=f.nextInt(); char[] l=f.next().toChar...
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 = [] symbol = 'B' anti = 'W' if s.count('B') % 2: if s.count('W') % 2: print('-1') exit() else: symbol = 'W' anti = 'B' s = list(s) for i in range(len(s) - 1): if s[i] == symbol: s[i + 1] = symbol if s[i+1] != symbol else anti 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...
def f(a , c): #print a d = [] for i in xrange(len(a) - 1): if a[i] == c: if a[i] == 'B': a[i] = 'W' else: a[i] = 'B' if a[i + 1] == 'B': a[i + 1] = 'W' else: a[i + 1] = 'B' d.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...
//package CodeforcesProject; import java.io.*; import java.lang.*; import java.util.*; import java.util.function.BiFunction; public class Main extends IO { public static void main(String[] args) throws Exception { int quantity = readInt(); String[] base = readArrayString(""); long answer ...
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; cin >> n; string st, st1; cin >> st; st1 = st; vector<long long int> ve, ve1; for (int i = 1; i < n; i++) { if (st[i] == 'W') { if (st[i - 1] != st[i]) { ve.push_back(i); swap(st[i], st[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 check(arr): ans=[] for i in range(len(arr)-1): if arr[i]=="W": continue else: ans.append(i+1) arr[i]="W" if arr[i+1]=="W": arr[i+1]="B" else: arr[i+1]="W" if len(set(arr))==1: return 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...
n=int(input()) p=list(1 if i=="B" else 0for i in input()) q=p[:] c=[] d=[] for i in range(n-1): if p[i]==0: p[i]=1 p[i+1]=1-p[i+1] c.append(i+1) if q[i]==1: q[i]=0 q[i+1]=1-q[i+1] d.append(i+1) if sum(p)==n: print(len(c)) print(*c) elif sum(q)==0: prin...
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...
num = int(input()) string = input() def count(string): Black = 0 White = 0 for char in string : if char == "B": Black += 1 else : White += 1 return (Black,White) def Make(mylist,color): retlist = [] if color == "B" : for index in range(0,len(mylist)-1): if not mylist[index] == "B": mylist...
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()) st=input() w,b=[],[] ans=[] for i in range(n): if st[i]=='W': w.append(i) else: b.append(i) if len(w)==0 or len(b)==0: print(0) elif len(w)%2!=0 and len(b)%2!=0: print(-1) elif len(w)%2==0: ans=0 for i in range(0,len(w),2): ans+=w[i+1]-w[i] print(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...
n = int(input()) blocks = list(input()) b = blocks.count('B') w = blocks.count('W') if b * w == 0: print(0) else: if b * w % 2 == 1: print(-1) else: l1 = [] if b % 2 == 0: for i in range(n - 1): if blocks[i] == 'B': blocks[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...
from sys import stdin def main(): input = lambda: stdin.readline()[:-1] N = int(input()) S = input() bn, wn = S.count('B'), S.count('W') if bn % 2 and wn % 2: print(-1) return if not bn % 2: color = ('B', 'W') if not wn % 2: color = ('W', 'B') s = lis...
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('') p = [] for i in range(n): if(a[i] == 'B'): p.append(0) else: p.append(1) fin = [] i = 0 while(i<n-1): if(p[i] != p[i+1] and p[i] == 1): fin.append(i) p[i] = 0 p[i+1] = 1 if(p[i] == p[i+1] and p[i] == 1): p[i] = 0 p...
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()) count = 0 ans = [] while count <= n*3: for i in range(n - 1): if s[i] != "B": ans.append(i + 1) count += 1 s[i] = "B" if s[i + 1] == "B": s[i + 1] = "W" else: s[i + 1] = "B" 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...
n=int(input()) s=input() l=[] for i in s: l.append(i) ci=[] if l.count('B')%2==0: for i in range(n-1): if l[i]=='B': ci.append(i) l[i]='W' if l[i+1]=='W': l[i+1]='B' else: l[i+1]='W' #print(l) print(len(ci)) for i in ci: print(i+1,end=" ") print() elif l.count('W')%2==0: for i in range(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...
fl=[] def minKBitFlips(A, K): global fl N = len(A) hint = [0] * N ans = flip = 0 # When we flip a subarray like A[i], A[i+1], ..., A[i+K-1] # we can instead flip our current writing state, and put a hint at # position i+K to flip back our writing state. for i, x in enumerate(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 math import sys input = sys.stdin.readline R = lambda : list(map(int,input().split())) n=int(input()) s=input() w=s.count("W") b=n-w # s=list(s) if b%2==w%2==1: print(-1) else: c=0 p=0 ans=[] x="W" if w%2==0 else "B" for i in range(n): if (s[i]==x and p==0) or (s[i]!=x and p==1): p=1 c+=1 ans.ap...
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() def f(n, S, b): s = [b] + [i == 'W' for i in S] ops = [] for i in range(1, n): if s[i] != s[i - 1]: ops.append(i) s[i] = not s[i] s[i + 1] = not s[i + 1] if (not s[0]) in s : return False else: print(len(ops)) ...
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 N; string s; vector<int> res; bool Solve() { res.clear(); string t = s; for (int i = 0; i < (int)t.size() - 1; i++) { if (t[i] == 'W') { res.push_back(i + 1); t[i] = 'B'; if (t[i + 1] == 'W') t[i + 1] = 'B'; else t[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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Blocks { public static void main(String[] args) throws IOException { int n; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine(...
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()) string=input() s=list(string) counts=0 arr=[] ans='' W_count=s.count('W') B_count=s.count('B') Ws=W_count%2 Bs=B_count%2 while True: if Ws==1 and Bs==1: print(-1) break if s.count('W')==0 or s.count('B')==0: print(counts) for x in arr: ans+=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; int main() { int n; cin >> n; vector<int> q; string s; cin >> s; for (int i = 0; i < n - 1; i++) { if (s[i] == 'W') { s[i] = 'B'; s[i + 1] = s[i + 1] == 'W' ? 'B' : 'W'; q.push_back(i); } } if (s[n - 1] == 'B') { cout << q.size(...
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 os from io import BytesIO, IOBase ######################### # imgur.com/Pkt7iIf.png # ######################### # returns the list of prime numbers less than or equal to n: '''def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3 while p * p <= 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...
import copy a=int(input()) s=list(input()) n=len(s) s2=copy.deepcopy(s) ans1=[] for i in range(n-1): if s[i]=='W': None else: s[i]='B' if s[i+1]=='B': s[i+1]='W' else: s[i+1]='B' ans1.append(i+1) if s[n-1]=='W': print(len(ans1)) print(*ans1...
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(void) { long long n; cin >> n; vector<int> v; string a; cin >> a; int w = 0, b = 0; for (int i = 0; i < n; ++i) { if (a[i] == 'W') w++; else b++; } if (b % 2 == 1 && w % 2 == 1) { cout << -1; exit(0); } else if (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...
def solve(n,a): w=a.count('W');b=a.count('B') if w==0 or b==0:return 0 if w%2!=0 and b%2!=0:return -1 ind=[];ans=[];indw=[] for i in range(n): if a[i]=='B':ind.append(i) if a[i]=='W':indw.append(i) i=0 if b%2==0: while i<b:ans+=(int(x) for x in range(ind[i]+1,ind[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; const long long int maxn = 1e5 + 6; const long long int MOD = 1e9 + 7; vector<int> prim(1000005, 1); int fact[maxn]; long long int binomialCoeff(long long int n, long long int k) { long long int res = 1; if (k > n - k) k = n - k; for (long long int i = 0; i < k; ++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()) string = list(input().strip()) def make_white(s): inverts = [] for i in range(len(s) - 1): if s[i] == 'B': s[i] = 'W' if s[i+1] == 'W': s[i+1] = 'B' else: s[i+1] = 'W' inverts.append(i+1) if s[-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 java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Codeforces{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); sc.nextLine(); String color=sc.nextLine(); int B=0; int W=0; for(int i=0;i<n;i++) { if(String.val...
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 coloring { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=Integer.parseInt(sc.nextLine()); String s=sc.nextLine(); //System.out.println(s); char car[]=s.toCharArray(); char ca[]=new char[car.length]; int B=0; int 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 atexit import io import sys @atexit.register def flush(): sys.__stdout__.write(sys.stdout.getvalue()) sys.stdout = io.BytesIO() input = sys.stdin.readline sys.stdout = io.BytesIO() n = int(input()) b = list(input().strip()) w = b[:] moves = [] for i in xrange(n - 1): if b[i] == "W": moves.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...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, s1; cin >> s; s1 = s; vector<int> v; int coun = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') { coun++; continue; } else if (i < n - 1) { v.push_back(i + 1); s[i] = 'W'; coun++...
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...
/* If you want to aim high, aim high Don't let that studying and grades consume you Just live life young ****************************** If I'm the sun, you're the moon Because when I go up, you go down ******************************* */ import java.util.*; import java.io.*; public class x1271B { public sta...
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.Scanner; public class Codeforces1271B_Real { public static void main(String[] args) { Scanner input = new Scanner(System.in); int length = input.nextInt(); input.nextLine(); String given = input.nextLine(); int countW = 0; int i; for (i = 0; i < given.length(); i++) { if (given.charA...
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()) bb = list(input()) res = [] for i in range(len(bb) -1): if bb[i] == 'B': res.append(i+1) bb[i] = 'W' bb[i+1] = 'W' if bb[i+1] == 'B' else 'B' if bb[-1] == 'W': print(len(res)) if len(res) > 0: print(...
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.*; public class Main { static class Scan { private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws IOExcepti...
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, s_x, s_y = map(int, input().split()) # east = west = north = south = 0 # for i in range(n): # x, y = map(int, input().split()) # if x < s_x: # west += 1 # else: # east += 1 # if y < s_y: # # south-west # south += 1 # else: # north += 1 # ans = max([east, west, north, south]) # prin...
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() s = s.lower() l = [] o = [] c = 0 c2 = 0 o2 = [] for i in s: l.append(i) b = s.count("b") w = s.count("w") flag = 1 l2 = l[:] if(b % 2 != 0 and w % 2 != 0): print(-1) flag = 0 else: if(b % 2 == 0): for i in range(len(l) - 1): if(l[i] == 'b' and l[i + 1] == 'b'): c += 1 l[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 main(): n = int(input()) line = input() b = 0 w = 0 pos = dict() pos["B"] = [] pos["W"] = [] for i in range(len(line)): if line[i] == "B": b += 1 pos["B"].append(i) else: pos["W"].append(i) w += 1 if b % 2 == 1 and ...
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; ll fast_pow(ll a, ll b, ll m) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b = b / 2; } return res; } template <typename T, typename U> std::pair<T, U> operator-(const std::pair<T, U>& l, const std:...
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 = 0 w = 0 for i in s: if i == 'W':w+=1 else:b+=1 if w%2 and b%2: print(-1) elif w%2: a = [i for i in s] ans = [] for i in range(n): if a[i] != 'W': ans.append(i+1) if(a[i+1] == 'W'): a[i+1] = 'B' else: a[i+1] = 'W' print(len(ans)) for i in ans: print(i,end=' ') print()...
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 ceil from math import factorial from collections import Counter from operator import itemgetter ii = lambda: int(input()) iia = lambda: list(map(int,input().split())) isa = lambda: list(input().split()) n = ii() s = input() s = list(s) if(s.count('B')%2==1 and s.count('W')%2==1): print(-1) else: 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 collections import deque def solve(): n = int(input()) t = list(input()) res = [] if t.count(t[0]) == len(t): return "0\n" for i in range(len(t)-1): if t[i] == 'B': t[i] = 'W' t[i+1] = 'W' if t[i+1] == 'B' else "B" res.append(i+1) if t[-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() s = list(s) new = s.copy() ans = '' lst = [] def swap(a,b): if a=='W':a = 'B'; else : a='W'; if b=='W': b = 'B'; else: b = 'W'; return a,b #print(swap('B','B')) #let's make all white for i in range(len(s)-1): if s[i]=='B': s[i],s[i+1]=swap(s[i],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...
n = int(input()) s = input() b = 0 w = 0 for i in s: if i == 'B': b += 1 else: w += 1 if b % 2 and w % 2: print(-1) else: ch = 'W' if w % 2: ch = 'B' ans = [] for i in range(n): if s[i] == ch: s = list(s) if s[i] == 'B': s[i] = 'W' else: 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; //_________________________________________________________________ public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); //...
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 _ in range(int(input())): n=int(input()) s=input() t=s s=list(s) ans=[] for i in range(n-1): if s[i]=="W": continue else: ans.append(i+1) s[i+1]="W" if s[i+1]=="B" else "B" if s[-1]=="W": print(len(ans)) print(*ans) else: ans=[] t = list(t) for i in 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...
from math import sqrt n=int(input()) s=[i for i in input()] if (s.count('W'))%2 and (s.count('B'))%2:print(-1);exit() else: i=0;ans=[] if s.count('B')%2==0: while i<n-1: if s[i]=='B': ans.append(i+1) if s[i+1]=='W':s[i+1]='B' else:s[i+1]='W' i+=1 # print(s) 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...
def func(s,l,c): if c=="W":p="B" else:p="W" for i in range(n-1): if s[i]==c:s[i]=p;s[i+1]=c if s[i+1]==p else p;l.append(i+1) if len(set(s))==1:return l else:return [] n,s=int(input()),list(input()) a,b=func(list(s),[],"B"),func(list(s),[],"W") if len(set(s))==1:print(0) elif not a and not 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...
#include <bits/stdc++.h> using namespace std; vector<int> ans; char s[221]; int main() { int n; scanf("%d %s", &n, s); for (int i = 0; i < n - 1; ++i) { if (s[i] == 'W') { s[i] = 'B'; s[i + 1] = (s[i + 1] == 'W') ? 'B' : 'W'; ans.push_back(i + 1); } } if (s[n - 1] == 'B') { print...
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<int> v; bool slove(string s, char co, char nc) { v.clear(); for (int i = 0; i < s.length() - 1; ++i) { if (s[i] != co) { s[i] = co; if (s[i + 1] != co) s[i + 1] = co; else s[i + 1] = nc; v.push_back(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...
n = int(raw_input()) s = raw_input() b = s.count('B') w = s.count('W') if b % 2 == 1 and w % 2 == 1: print '-1' elif b % 2 == 0: s = list(s) a = [] for i in xrange(n): if s[i] == 'B': s[i] = 'W' s[i+1] = 'W' if s[i+1] == 'B' else 'B' a.append(i+1) print le...
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 = list(input()) ops = list() def opp(a): return 'B' if a=='W' else 'W' for i in range(n-1): if a[i] == "W": a[i] == "B" a[i+1] = opp(a[i+1]) ops.append(i+1) else: continue if a[n-1] == 'B': print(len(ops)) print(' '.join(map(str, ops))) 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...
#include <bits/stdc++.h> using namespace std; int main() { int c = 0; vector<int> v; 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++; } if (b == 0 && w == n) cout << "0"; else if (w == 0 && b == n) 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...
n = int(input()) s = input() if s.count("W")%2 == 1 and s.count("B")%2 == 1: print(-1) else: if s.count("B")%2==0: odp = [] cur = list(s) for i in range(n-1): if cur[i] != "W": odp.append(i+1) if cur[i+1] == "W": cur[i+1] = "B" else: cur[i+1] = "W" print(len(odp)) print(*odp) 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...
def do(s): if s == "B": return 1 return 0 n = input() arr = map(do,raw_input()) def f(a): return (a+1)%2 last = arr[0] ret = [] for i in range(1,n-1): if arr[i] != last: ret.append(i+1) arr[i] = f(arr[i]) arr[i+1] = f(arr[i+1]) last = arr[i] if arr[-1] == arr[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> using namespace std; using ll = long long; const ll mod = 1e9 + 7; const int q = 2e5 + 5; const int INF = 1e9; void done() { int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> pos; int ok = 0; for (int i = 2; i < 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...
n = int(input()) s = input() x=s.count('B') y=s.count('W') l= [] for i in s: if(i=='W'): l.append(1) else: l.append(0) if(x&1 and y&1): print(-1) exit() if(x==0 or y==0): print(0) exit() ans = [] for i in range(1,len(s)-1): if(l[i]!=l[i-1]): l[i] = not(l[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, s, l = int(input()), list(input()), [] w, b, default = s.count('W'), s.count('B'), 'B' if w % 2 and b % 2: exit(print(-1)) elif w % 2: default = 'W' for i in range(n-1): if s[i] != s[i + 1] and s[i] != default: s[i], s[i + 1] = s[i + 1], s[i] l.append(i+1) else: if s[i] == 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 input = sys.stdin.readline from collections import * n = int(input()) S = list(input()[:-1]) if S in [['B']*n, ['W']*n]: print(0) exit() B, W = 0, 0 for Si in S: if Si=='B': B += 1 else: W += 1 if B%2==1 and W%2==1: print(-1) exit() ans = [] if 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...
n = int(input()) s = list(input()) dup_s = s[::] i = 0 a1, a2 = list(), list() while i < n: if s[i] == 'W': i += 1 continue if i < n-1: s[i] = 'W' if s[i+1] == 'B': s[i+1] = 'W' else: s[i+1] = 'B' a1.append(i+1) i += 1 i = 0 while 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...
n = int(input()) inp = input() blacks = inp.count("B") whites = inp.count("W") ansCount_ = 0 ansList = [] if blacks % 2 == 1 and whites % 2 == 1: print(-1) else: if blacks % 2 == 1 and whites % 2 == 0: changeTo = "W" elif blacks % 2 == 0 and whites % 2 == 1: changeTo = "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...
/* 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 final class Main { public static void main (String[] args) throws java.lang.Exception { Scanner s = new Scanner(System.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() { vector<long long int> ans; long long int n, cw, i; char re; string s; cin >> n; cin >> s; cw = count(s.begin(), s.end(), 'W'); if (cw == 0 || cw == n) cout << "0"; else { re = s[n - 1]; for (i = n - 2; i > 0; i--) { if (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...
s=int(input()) s=input() arr=[] ans=[] for i in range(len(s)): arr.append(s[i]) black=s.count('B') white=s.count('W') if(black%2==white%2==1): print('-1') else: i=0 count=0 while(i<len(arr)-2): if(arr[i]!=arr[i+1]): count=count+1 arr[i+1]=arr[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 collections import Counter from collections import defaultdict import math import random import heapq as hq from math import sqrt import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, ...
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.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.io.Writer; ...
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()) st=input() s=list(st) f=0 if 'B' not in s or 'W' not in s: f=1 li=[] for i in range(n-1): if s[i]=='B' and s[i+1]=='B': s[i]='W' s[i+1]='W' li.append(i+1) elif s[i] == 'B' and s[i+1]=='W': s[i]='W' s[i+1]='B' li.append(i+1) if s[n-1]=='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 sys,math,bisect from random import randint inf = float('inf') mod = (10**9)+7 "========================================" def lcm(a,b): return int((a/math.gcd(a,b))*b) def gcd(a,b): return int(math.gcd(a,b)) def tobinary(n): return bin(n)[2:] def binarySearch(a,x): i = bisect.bisect_left(a,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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.Arrays; public class JavaApplication20 { public static void main(String[] args) { FastReader read = new FastReader(); int n = r...
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.*; public class B1271{ public static void main(String args[]) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = 1; br.readLine(); StringBuilder sb = new StringBuilder(); while((t--)>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 invert_c(c): if c == 'B': return 'W' return 'B' def invert_s(s, i): return s[:i] + invert_c(s[i]) + invert_c(s[i+1]) + s[i+2:] # init p = [] # input n = int(raw_input()) s = raw_input() # solve for i in range(1, n-1): if s[i] != s[i-1]: p.append(i+1) s = invert_s(s, i) f...
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, i = 0, b = 0, w = 0; vector<long long int> v; cin >> n; char s[230]; cin >> s; for (i = 0; i < n; i++) { if (s[i] == 'W') w++; else b++; } if (b % 2 == 1 && w % 2 == 1) cout << "-1" << endl; 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 os import sys from io import BytesIO, IOBase def solution(s, n): if 'B' not in s or 'W' not in s: write(0) return ss, res = list(s), [] for i in range(n - 1): if ss[i] == 'B': ss[i] = 'W' ss[i + 1] = 'W' if s[i + 1] == 'B' else 'B' res.ap...
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=[] x=0 for i in range(n-1): if(s[i]==s[i+1]): x+=1 if(x==n-1): print(0) else: for i in range(n-1): if(s[i]=="B"): if(s[i+1]=="B"): s=s[:i]+"WW"+s[i+2:] else: s=s[:i]+"WB"+s[i+2:] A.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...
import sys # inf = open('input.txt', 'r') # reader = (line.rstrip() for line in inf) reader = (line.rstrip() for line in sys.stdin) def inversions(s, n): k = s.count('B') if k % 2 == 0: todel = 'B' elif n % 2 == 1: todel = 'W' else: return None a = [c == todel for c in 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()) s=list(input()) b=0 w=0 for i in range(n): if s[i]=="B": b+=1 else: w+=1 if b%2 and w%2: print(-1) elif b==0 or w==0: print(0) else: if b%2: x="W" y="B" else: x="B" y="W" ans=[] for i in range(1,n): if s[i]==x and 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; public class Main { public static void ans(int []arr,int n) { int[] warr=new int[n]; for(int i=0;i<n;i++){ warr[i]=arr[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 MOD = 998244353; const int N = 2e5 + 7; int a[N]; void solve() { 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++; } vector<int> v; if (w % 2 && b % 2) { 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; signed main() { long long n; cin >> n; string s; cin >> s; string t = s; long long o = 0; vector<long long> v; for (long long i = 0; i < s.size() - 1; i++) { if (s[i] == 'B') { o++; v.push_back(i); s[i] = 'W'; 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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** * Created by flk on 2019/12/8. */ public class B { public static void main(String[] args) { Inp...
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; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, c = 0, c1 = 0; cin >> n; string s, s1; cin >> s; s1 = s; vector<long long> v, v1; for (long long i = 0; i < n - 1; i++) { if (s[i] == 'B') { 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; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int countb = 0; int countw = 0; for (int i = 0; i < s.length(); ++i) { if (s[i] == 'B') countb++; else if (s[i] == 'W') countw++; } ...