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...
t = int(input()) string = input() changes = [] adopted = [i for i in string] count = 0 i = 0 while(i < t-1 ): if adopted[i] == 'B': i += 1 else: adopted[i] = 'B' count += 1 changes.append(i+1) if adopted[i+1] == 'W': adopted[i+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...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string s; cin >> s; char arr[N + 1]; strcpy(arr, s.c_str()); vector<int> v; unordered_map<char, int> um; for (int i = 0; i < N; i++) { um[arr[i]]++; } if (um['B'] % 2 == 1 && um['W'] % 2 == 1) { cout << "-1\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...
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def solve(n, sarr): ans = [] if len(sarr) <= 1: return 0 def flip(x, y): ans.append(x + 1) sarr[x] = 'B' if sarr[x] == 'W' else 'W' sarr[y] = 'B' if sarr[y] == 'W' else 'W' for i, c in enumerate...
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() co = [] for i in range(0,n): if s[i] == 'B': co.append(0) else: co.append(1) bl = co.copy() wl = co.copy() abl = [] awl = [] for i in range(0,n-1): if bl[i] == 0: pass else: bl[i] = 0 abl.append(i+1) bl[i+1] = (bl[i+1]+1)%2 for...
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 main(): n = int( input()) S = list( input()) b = 0 w = 0 T = [0]*n for i in range(n): if S[i] == 'B': b += 1 else: w += 1 T[i] = 1 if b%2 == 1 and w%2 == 1: print(-1) return 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...
/*package whatever //do not write package name here */ import java.util.*; import java.io.*; public class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); char[] S = sc.nextLine().toCharArray(); int B = 0, W = 0; for(int 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; char s[300010]; vector<int> ans; int main() { ios::sync_with_stdio(false); int n; cin >> n; cin >> s + 1; for (int i = 1; i < n; i++) { if (s[i] == 'B') { s[i] = 'W'; if (s[i + 1] == 'W') s[i + 1] = 'B'; else 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.util.*; public class B_608{ public static void main(String[] args) { Scanner omkar = new Scanner(System.in); int size = omkar.nextInt(); int[] arr = new int[size]; int[] arr2 = new int[size]; String colors = omkar.next(); for(int i = 0; i < size; i++) { if(colors.charAt(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...
from copy import copy def arr_float_inp(): return [float(s) for s in input().split()] def arr_int_inp(): return [int(s) for s in input().split()] def int_inp(): return int(input()) def float_inp(): return float(input()) def comp(a): return a[0] if __name__ == '__main__': k = int_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; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; int l[n]; int wh = 0; int bl = 0; for (int i = 0; i < n; i++) { l[i] = s.at(i) == 'W' ? 1 : 0; if (l[i] == 0) { bl++; } else { wh++; } } ...
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 mod = 1e9 + 7; long long power(long long x, long long n) { if (n == 0) return 1; if (n == 1) return x % mod; if (n % 2 == 0) { long long y = power(x, n / 2) % mod; return (y * y) % mod; } if (n & 1) { long long y = power(x, n - 1); return...
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()) s = input() w = s.count('W') b = s.count('B') if w == 0 or b == 0: print(0) return s_s = [i for i in s] res = [] for i in range(1,len(s_s) - 1): if s_s[i] != s_s[i-1]: s_s[i] = invert(s_s[i]) s_s[i+1] = inv...
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 = lambda: sys.stdin.readline().strip('\r\n') n = int(input()) s = [(0 if c=='B' else 1) for c in input()] c = [s.count(0), s.count(1)] for i in 0, 1: if c[i]%2 == 0: t = i break else: print(-1) exit() out = [] for i in range(n-1): if s[i] == t: s[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...
n = int(input()) l = list(input()) #list of B and W def isDone(l, target): return l == [target]*len(l) #first considering making each element equal to the first element count = 0 steps='' target = l[0] for i in range(len(l)-1): #print(i, l[i]) if l[i]!=target: count +=1 steps+=str(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() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; char ar[n]; for (int i = 0; i < n; ++i) { cin >> ar[i]; } int co = 0; vector<int> po; for (int i = 0; i < n - 1; ++i) { if (ar[i] == 'W') { ar[i] = 'B'; 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...
#!/usr/bin/python3 import os import sys def main(): N = read_int() S = inp() ans = solve(N, S) if ans is None: print('-1') return print(len(ans)) if ans: print(*[x + 1 for x in ans]) def solve(N, S): A = [0 if c == 'W' else 1 for c in S] ans = [] for i 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...
/* package codechef; // 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 Main { public static void main (String[] args) throws java.lang.Exception { BufferedReader bf = new BufferedReader(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 os import sys from io import BytesIO, IOBase from collections import Counter BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write...
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()) x='B' def check(l): prev=l[0] for i in range(len(l)): if l[i]!=prev: return False return True count=0 ans=[i for i in s] l=[] for i in range(n-1): if s[i]!=x: s[i]=x if s[i+1]=='B': s[i+1]='W' else: 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 dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { file(); fast(); int n; cin >> n; string str; cin >> str; int flib = 0; map<char,...
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 BLOCK{ public static void main(String arggs[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String block = sc.next(); char [] a = block.toCharArray(); LinkedList<Integer> k = new LinkedList<Integer>(); for(int i = 0 ;i<n-1;i++){ if(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; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long ans, sum, tot, cnt, mx, mn, idx, chk, rem, ret, tmp, mid, lft, rgt, pos; long long tc, n, m, a, b, c, d, g, h, l, r, x, y, i, j, k; cin >> n; string s; cin >> s; 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...
import sys import math import heapq import collections def inputnum(): return(int(input())) def inputnums(): return(map(int,input().split())) def inputlist(): return(list(map(int,input().split()))) def inputstring(): return([x for x in input()]) def inputstringnum(): return([ord(x)-ord('a') for x 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; using ll = long long; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 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=list(input()) b=[] a=[] for i in range(n): a.append(s[i]) b.append(s[i]) c=[] for i in range(n-1): if(a[i]=="W"): continue else: a[i]="W" c.append(i+1) if(a[i+1]=="W"): a[i+1]="B" else: a[i+1]="W" if(a.count("W")==n): 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...
# --------------------------------------- START OF LICENSE NOTICE ------------------------------------------------------ # Copyright (c) 2019 Soroco Private Limited. All rights reserved. # # NO WARRANTY. THE PRODUCT IS PROVIDED BY SOROCO "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, TH...
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 from math import* def checker(s,s1,ans): for i in range(n-1): if s[i]==s1: if s[i]=="B": s[i]="W" else: s[i]="B" ans.append(i+1) if s[i+1]=="B": s[i+1]="W" else: s[i+1]="B" return ans n=int(input()) s=input() s=list(s) if "B" not in s or "W" not in s: print("0") 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 = list(str(input())) ans = [] countW = 0 countB = 0 bol = False if len(set(s)) == 1: print(0) exit(0) for i in range(n): if s[i] == 'B': countB += 1 else: countW += 1 if (countB & 1) == 1 and (countW & 1) == 1: print(-1) exit(0) i = 0 while i < 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=str(input()) l=list(s) lt=list(s) l1=[] l2=[] for i in range(n-1): if(l[i]=="W"): l1.append(i+1) l[i]="B" if(l[i+1]=="W"): l[i+1]="B" else: l[i+1]="W" if(l[n-1]=="B"): print(len(l1)) for i in l1: print(i,end=" ") ...
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.IOException; import java.io.InputStream; import java.math.BigInteger; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.List; public class B { final static int MOD = 1000000007; static final char BLACK = 'B'; static final char WHITE = 'W'; 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...
n=int(input()) s=str(input()) s1=list(s) b="B" w="W" if(s1.count(b)%2!=0 and s1.count(w)%2!=0): print(-1) else: if((s1.count(b)%2!=0 and s1.count(w)%2==0)): k=s1.count(w) a=[] i=0 while(i<len(s)-2): if(s1[i]=="W" and s1[i+1]!="W"): temp=s1[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() s=s.replace('B','0') s=s.replace('W','1') # print(s) zcount = s.count('0') ocount = s.count('1') if(zcount==0 or ocount==0): print(0) elif(zcount%2!=0 and ocount%2!=0): print(-1) else: ans = [] idx = [] bit = '0' if(zcount%2==0 and ocount%2==0): if(zcount<ocount): bit = '0' els...
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()) def DP_(color1, color2): DP = [[None for _ in range(2)] for _ in range(len(s))] DP[-1][0] = 0 if s[-1] == color1 else 10 ** 10 DP[-1][1] = 0 if s[-1] == color2 else 10 ** 10 parents = {} for i in range(len(s) - 2, -1, -1): DP[i][0] = DP[i + 1][0] 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...
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int a[1000]; int cnt = 0; for (int i = 1; i <= n - 2; i++) { if (s[i] != s[i - 1]) { if (s[i] == 'B') s[i] = 'W'; else s[i] = 'B'; if (s[i + 1] == 'B') 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...
n=int(input()) it=list(input()) tt=it[:] ans=[] for i in range(n-1): if it[i]=="W": it[i]="B" if it[i+1]=="B": it[i+1]="W" else: it[i+1]="B" ans.append(i+1) if it[-1]=="B": print(len(ans)) print(*ans) else: it=tt[:] ans=[] 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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Comparator; import java.util.List; public class Blocks { // Template for CF public static class ListComparator implements Comparator<List<Integer>> {...
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(false); cin.tie(nullptr); int n; string s; cin >> n >> s; int nb = 0, nw = 0; for (auto ai : s) { if (ai == 'B') { nb++; } else { nw++; } } if (nb & 1 && nw & 1) { cout << -1; return 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() b=list(a) e=-1 m=0 if(a.count("W")==len(a) or a.count("B")==len(a)): print(0) m=1 elif(a=="BWB" or a=="WBW"): print(2) print(2,1) m=1 elif(a.count("W")%2!=0 and a.count("B")%2!=0): print(-1) m=1 elif(a.count("W")%2==0): ans=[] while(b.count("W")>0): c=b.index("W",e+1) d=b.index("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...
n = int(input()) s = list(input()) b = s.count('B') w = s.count('W') order = [] if b % 2 and w % 2: print(-1) else: cur = 'B' if b % 2 else 'W' notcur = 'B' if cur == 'W' else 'W' for i in range(n-1): if s[i] == cur: continue order.append(i+1) s[i+1] = cur if 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; void solve() { int n; string s; cin >> n >> s; int white = count(s.begin(), s.end(), 'W'); int black = count(s.begin(), s.end(), 'B'); if (white % 2 && black % 2) { cout << "-1" << endl; return; } if (white == s.size() || black == s.size()) { cou...
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 b { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int n = stdin.nextInt(); char[] in = stdin.next().toCharArray(); int w = 0, b = 0; for (int i = 0; i < n; i ++) { if (in[i] == 'W') w ++; els...
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()) ans = [] if s.count('B') % 2 != 0 and s.count('W') % 2 != 0: print(-1) else: if s.count('B') % 2 == 0: now = 'B' else: now = 'W' for i in range(n - 1): if s[i] == now: if now == 'B': s[i] = '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...
""" // Author : snape_here - Susanta Mukherjee """ from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input(...
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(sys.stdin.readline().strip()) a=[0]*n cnt=[0,0] for i,v in enumerate(sys.stdin.readline().strip()): if v=='B': a[i]=1 cnt[1]+=1 else: a[i]=0 cnt[0]+=1 if cnt[0]%2==1 and 1==cnt[1]%2: print(-1) else: total=0 ans=[] for i in range(n-1): if a[i]==0: total+=1 ans.append(i+1) a[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()) a = list(input()) if a.count('B') % 2 and a.count('W') % 2: print(-1) else: if a.count('W') % 2: for q in range(len(a)): if a[q] == 'W': a[q] = 'B' else: a[q] = 'W' ans = [] for q in range(len(a)-1): if a[q] == '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(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; string str; cin >> str; int cw = 0, cb = 0; for (int i = 0; i < n; i++) { if (str[i] == 'B') { cb++; } else { cw++; } } if (cb % 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...
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static int check(char[]ch){ int B=0,W=0; for(int i=0;i<ch.length;i++) if(ch[i]=='B') B++; else W++; if(B==0 || W==0) return 1 ; return 0; } public static vo...
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()) arr = [i for i in input()] counter = 0 ans = [] for i in range(n - 1): if arr[i] == "B": arr[i] = "W" if arr[i + 1] == "B": arr[i + 1] = "W" else: arr[i + 1] = "B" counter += 1 ans.append(i + 1) if len(set(arr)) != 1: fo...
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()) arr = list(input()) ori = arr[:] temp = [] for i in range(n-1): if arr[i] == 'W': temp += [i+1] arr[i] = 'B' if arr[i+1] == 'W': arr[i+1] = 'B' else: arr[i+1] = 'W' if arr[-1] == 'B': print(len(temp)) print(*temp) exit() temp = [] arr = ori[:] for i in range(n-1): if arr[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() ss=s s=list(s) ss=list(ss) a=[] b=[] for i in range(n-1): if(s[i]=='W'): s[i]='B' if(s[i+1]=='W'): s[i+1]='B' else: s[i+1]='W' a.append(i+1) for i in range(n-1): if(ss[i]=='B'): ss[i]='W' if(ss[i+1]=='B'): ss[i+1]='W' else: ss[i+1]='B' b.append(i+1) if('W' not...
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.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHel...
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; void fragmentarA() { long long h1, h2, h3, h4, h5, h6, h7, h8, h9; h1 = h2 + h3 + h4; h2 = h1 + h3 + h5 + 9; h3 = h4 + h1 + h6; h3 = h5 + h6; h5 = h6 + h2; h1 = h2 + h5 + h6; h6 = h1 + h2; h5 = h2 + h3; h9 = h2 + h6; h5 = h6 + h7; h2 = h6 + h7 + h5; ...
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(nullptr); long long n; cin >> n; string s; cin >> s; string p = s; long long ans1 = 0, ans2 = 0; vector<long long> v1, v2; 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(raw_input()) s=list(raw_input()) nw=s.count("W") nb=n-nw if nw==0 or nb==0: print 0 exit() if nw%2==1 and nb%2==1: print -1 exit() if nw%2==1: # make all to be white ans="" tmp=s[:] x=0 for i in xrange(n-1): if tmp[i]=="B": ans=ans+" "+str(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...
from sys import stdin, stdout n = int(input()) s = list(input()) tmp = list() tmp += s if len(set(s)) == 1: print(0) else: ans = [] for i in range(n-1): if s[i] == 'B': s[i] = 'W' s[i+1] = 'W' if s[i+1] == 'B' else 'B' ans.append(str(i+1)) if len(set(s)) == 1: print(len(ans)) 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.lang.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next...
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()) sequence = [] for i in range(n-1): if s[i] =='B' and s[i+1] == 'W': s[i] = 'W' s[i+1] ='B' sequence.append(i) if s[i] =='B' and s[i+1] == 'B': s[i] = 'W' s[i+1] ='W' sequence.append(i) if s[n-1] == 'B': if n %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...
#include <bits/stdc++.h> using namespace std; int main() { int n; string z; cin >> n >> z; int c1 = 0, c2 = 0; for (int i = 0; i < n; i++) { if (z[i] == 'W') c1++; else c2++; } if (c1 % 2 != 0 && c2 % 2 != 0) { cout << -1; return 0; } if (c1 % 2 == 0) { vector<int> 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...
def minKBitFlips(A): K=2 N = len(A) hint = [0] * N # ans = flip = 0 flip=0 ans=[] # 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 ...
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 = list(s) protocol = [] i = 0 while i < n - 1: if l[i:i + 2] == ['W', 'B'] and i < n - 2 and l[i + 2] == 'W': l[i + 1] = 'W' l[i + 2] = 'B' protocol.append(i + 2) i += 2 elif l[i:i + 2] == ['B', 'W']: l[i] = 'W' l[i + 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...
#include <bits/stdc++.h> using namespace std; const int N = 10010; int pos[N]; int main() { int n; cin >> n; string s; cin >> s; s = " " + s; string b = s; int cnt = 0; int i; int s1 = 0, s2 = 0; for (i = 1; i <= s.size(); i++) { if (s[i] == 'W') s1++; } if (s1 == n || s1 == 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...
import os import sys from io import BytesIO, IOBase import math import itertools import bisect import heapq def main(): pass BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.m...
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<char> z; long long x, y, dl, mi, ma, b, s, m, k, w, a[1000], ko; char p; int main() { cin >> dl; for (int i = 0; i < dl; i++) { cin >> p; z.push_back(p); if (p == 'W') w++; else b++; } if (w % 2 != 0 && b % 2 != 0) { 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...
n = int(input()) a = list(input()) w = a.count('W') b = n-w flag = True if (w-b)%4==(n%4): flag = False c = 'W' elif (b-w)%4==(n%4): flag = False c = 'B' if flag: print(-1) else: p = [] for i in range(n-1): if a[i]!=c: p.append(str(i+1)) a[i]=c 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 c = 0; unordered_map<string, bool> memo; bool sb(int i, string s, vector<int> moves, vector<int>& sol, int mreset) { string rem = s; if (memo.find(rem) != memo.end()) return memo.at(rem); if (s.find('W') == string::npos || s.find('B') == string::npos) { sol = ...
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()) r=list(input()) for t in range(len(r)): if r[t]=='B': r[t]=1 else: r[t]=-1 g=0 m=0 l=[] jk=[] o=list(r) for i in range(0,n-1): if r[i]==-1: r[i]=-r[i] r[i+1]=-r[i+1] l+=[i+1] if r[n-1]!=1: g=1 for q in range(0,n-1): if o[q]==1: o[q]=-o[q] o[q+1]=-o[q+1] jk+=[q+1] if o[n-1]!=-1: m=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(target, a): return target ^ 1 not in a n = int(input()) a = [0 if ch == 'W' else 1 for ch in input()] for target in (0, 1): ret = [] t = a[::] for i in range(n - 2): sub = t[i:i + 3] if sub == [target, target ^ 1, target ^ 1]: ret.append(i + 2) 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...
n=int(input()) f=list(str(input())) s=f*1 i=0 b=[];w=[] while i<n-1: if s[i]=='B' and s[i+1]=='B': b.append(i+1) s[i]='W';s[i+1]='W' i+=2 elif s[i]=='B' and s[i+1]=='W': b.append(i+1) s[i],s[i+1]=s[i+1],s[i] i+=1 else: i+=1 if s.count('B')!=0: b=[9...
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, defaultdict, deque import bisect from sys import stdin, stdout,setrecursionlimit from itertools import repeat # sys.stdin = open('input') # n, k = map(int, raw_input().split()) # da = map(int, raw_input().split()) # db = map(int, raw_input().split()) def main(): n = map(int, raw_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; scanf("%d", &n); string s, s1; cin >> s; s1 = s; int i, j, k, l; vector<int> v; for (i = 0; i < n; i++) { if (i + 1 < n && s[i] == 'B') { v.push_back(i + 1); s[i] = 'W'; if (s[i + 1] == 'B') 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.util.*; import java.io.*; public class Solution{ long mod = 1000000007; public Solution(){ Scanner sc = new Scanner(System.in); int tests = 1; for(int t=0; t<tests; t++){ int n = sc.nextInt(); String s = sc.next(); char[] arr = s.toCharArray(); int bCount = 0; int wCount =...
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; int arrp[n]; int arrn[n]; char t; int b = 0, w = 0; for (int i = 0; i < n; i++) { cin >> t; if (t == 'B') { b++; arrp[i] = -1; arrn[i] = -1; } else { w++; arrp[i] = 1; arrn[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 B_Blocks { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int 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...
#include <bits/stdc++.h> int main() { int n; std::cin >> n; std::vector<char> str(n); int cnt[2] = {0, 0}; for (int i = 0; i < n; i++) { std::cin >> str[i]; str[i] = str[i] == 'B' ? 0 : 1; cnt[str[i]]++; } if (cnt[0] % 2 && cnt[1] % 2) { printf("-1\n"); return 0; } bool need = (cnt...
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()) b=0 w=0 for i in l: if i=='B': b+=1 else: w+=1 if b%2==w%2==1: print(-1) elif b==n or w==n: print(0) else: ans=[] s=l if w%2==0: for i in range(n-1): if s[i]=='W': if s[i+1]=='B': ans.appen...
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 = [int(c == 'B') for c in input()] res = [] for e in [1, 0]: for i in range(n - 1): if l[i] == e: l[i] ^= 1 l[i + 1] ^= 1 res.append(i + 1) if sum(l) == (e ^ 1) * n: print(len(res)) print(*res, sep=' ') exit(0) print(-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 ans[1000]; int ans2[1000]; int main() { int n; scanf("%d", &n); string a; cin >> a; string b = a; int flag1 = 1; int flag2 = 1; int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < a.length() - 1; i++) { if (a[i] == 'B') { ans[++cnt1] = 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=list(input()) w=s.count('W') b=n-w f = lambda c: 'B' if c=='W' else 'W' if not b&1: l = [] for i in range(n-1): if s[i]=='B': s[i],s[i+1]=f(s[i]),f(s[i+1]) l.append(i+1) le=len(l) print(le) if le: print(*l) elif not w&1: l = [] 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...
import sys import collections import heapq import math import bisect input = sys.stdin.readline def rints(): return map(int, input().strip().split()) def rstr(): return input().strip() def rint(): return int(input().strip()) def rintas(): return [int(i) for i in input().strip().split()] def gcd(a, 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...
a = int(input()) b = input() sum = 0 line = [] for i in range(a): if b[i] == 'B': sum+=1 line.append(1) else: line.append(0) if sum % 2 == a % 2: ans = [] if a % 2 == 1: for i in range(a-1): if line[i] == 0: line[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 str; cin >> str; int cw = 0, cb = 0; for (int i = 0; i < n; i++) { if (str[i] == 'W') cw++; else cb++; } if (cb % 2 != 0 && cw % 2 != 0) { cout << "-1" << endl; return 0; } vector<int> 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()) a=[0]*n cnt=[0,0] for i,v in enumerate(input()): if v=='B': a[i]=1 cnt[1]+=1 else: a[i]=0 cnt[0]+=1 if cnt[0]%2==1 and 1==cnt[1]%2: print(-1) else: total=0 ans=[] for i in range(n-1): if a[i]==0: total+=1 ans.append(i+1) a[i]=1 if a[i+1]==1: a[i+1]=0 else: a[i+1]=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 ilo=int(input()) kloc=list(input()) iloW=0 iloB=0 kol="W" iloZ=0 zmia='' for i in range(ilo): if kloc[i]=='W': iloW+=1 else: iloB+=1 if iloW==ilo: print(0) sys.exit() elif iloB==ilo: print(0) sys.exit() if (iloW%2==1)and(iloB%2==1): print(-1) sys.e...
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 main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.next()); String str = sc.next(); int cntW = 0, cntB = 0; char[] ch = new char[n]; int[] num = new int[n]; for(int i = 0; i < n; i++) { 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...
import sys # sys.setrecursionlimit(10**6) from sys import stdin, stdout import bisect #c++ upperbound import math import heapq def modinv(n,p): return pow(n,p-2,p) def cin(): return map(int,sin().split()) def ain(): #takes array as input return list(map(int,sin().split...
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 rev(s): if s == "W": return "B" else: return "W" n = int(input()) p = list(input()) w = 0 b = 0 for i in p: if i == "B": b += 1 else: w += 1 if w % 2 == 1 and b % 2 == 1: print (-1) sys.exit() if b % 2 == 1: #all b ans = [] for i 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() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; bool a[n]; char c; for (int i = 0; i < n; ++i) { cin >> c; a[i] = (c == 'W'); } bool b[2][n]; for (int i = 0; i < n; ++i) { b[0][i] = 0; b[1][i] = 1; } vector<int> 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.BufferedReader; import java.io.*; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; import java.math.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; 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...
n = int(input()) bk = list(input()) if bk.count('W') % 2 == 1 and bk.count('B') % 2 == 1: print(-1) else: ans = [] if bk.count('W') % 2 == 0 and bk.count('B') % 2 == 0: if bk.count('W') > bk.count('B'): c = 'W' else: c = 'B' elif bk.count('W') % 2 == 0: 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...
i1=int(input()) ar=list(input()) if(ar.count('W')%2!=0 and ar.count('B')%2!=0): print(-1) else: if(ar.count('W')%2==0): count=0 swap=[] for i in range(len(ar)-1): if(ar[i]=='W' and ar[i+1]=='W'): count+=1 swap.append(str(i+1)) 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...
n = int(input()) s = input() if s.count("W")%2 == 1 and s.count("B")%2 == 1: print(-1) exit() l = [] for i in range(n): l.append(s[i]) if l.count("W")%2 == 1: t = "B" t1 = "W" else: t = "W" t1 = "B" ans = [] # print(l) # while l.count(t1) == len(t1) for i in range(n-1): # print(*l) if t == "B" and 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...
import java.io.*; import java.util.*; public class CF608B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.par...
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(NULL); cout.tie(NULL); long long T = 1; while (T--) { long long n, b = 0, w = 0; cin >> n; string s; cin >> s; for (long long i = 0; i < n; i++) { if (s[i] == 'B') 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; void solve() { long long n; cin >> n; string str; cin >> str; vector<char> sv, sb; for (long long i = 0; i < n; i++) { sv.push_back(str[i]); sb.push_back(str[i]); } vector<long long> ans; for (long long i = 0; i < n - 1; i++) { if (sv[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...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string c; cin >> c; int cntb = 0, cntw = 0; for (int i = 0; i < n; i++) { if (c[i] == 'B') cntb++; else cntw++; } if (cntb % 2 == 1 && cntw % 2 == 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; unsigned long long gcd(unsigned long long n, unsigned long long m) { if (m == 0) return n; else return gcd(m, n % m); } int longestsub(string x, string y, int n, int m) { int lcs[n + 1][m + 1]; int result = 0; for (int i = 0; i < n + 1; i++) { for (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...
n = int(input()) stri = input() stringa = [] for i in range(len(stri)): stringa.append(stri[i]) counta = 0 countb = 0 for i in range(len(stringa)): if(stringa[i] == 'W'): counta += 1 else: countb += 1 if(counta%2 == 1 and countb%2 == 1): print(-1) elif(counta == n or countb == 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; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; void IO() {} template <class T> void unisort(vector<T>& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } long long gcd(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...
import math,sys from collections import Counter, defaultdict, deque from sys import stdin, stdout input = stdin.readline lili=lambda:list(map(int,sys.stdin.readlines())) li = lambda:list(map(int,input().split())) #for deque append(),pop(),appendleft(),popleft(),count() I=lambda:int(input()) S=lambda:input().strip() mod...
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 minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int,minp().split()) def change(s, i): if s[i] == 'W': s[i] = 'B' else: s[i] = 'W' def check(s, c): r = [] for i in range(len(s)-1): if s[i] != c: r.append(i+1) change(s, i) chang...