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...
n=int(input()) s=list(input()) count=0 l=[] cb=0 cw=0 def swap(char ): if char=="W": return "B" else: return "W" for i in range(len(s)): if s[i]=="B": cb+=1 else: cw+=1 if (cb%2!=0) and (cw%2!=0): print(-1) elif( cb==0 or cw==0): print(0) else: 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 collections import Counter def flip_colors(s, i): if s[i] == 'W': s[i] = 'B' else: s[i] = 'W' if __name__ == '__main__': n = int(input()) s = list(input()) wb = Counter(s) if wb['W'] < wb['B']: min_wb = wb['W'] min_wb_color = 'W' else: min_wb ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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; int main() { int numOfBlocks, white = 0, black = 0; string block; cin >> numOfBlocks >> block; for (int i = 0; i < numOfBlocks; i++) { if (block[i] == 'W') white++; else black++; } if (white == 0 || black == 0) { cout << 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.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.util.Scanner; import...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
l = int(input()) s = list(input()) counts = {'B':0, 'W':0} for i in range(l): counts[s[i]] += 1 if counts['B']%2==1 and counts['W']%2==1: print(-1) exit(0) if counts['B']%2==0: c = 'B' ci = 'W' elif counts['W']%2==0: c = 'W' ci = "B" # print(c, ci) actions = [] for i in range(l-1): 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...
import os import sys from io import BytesIO, IOBase def solution(s, n): 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.append(i + 1) if 'B' not in ss: write(len(res)) wri...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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()) q = a.copy() ans=[] count = 0 for i in range(n-1): if a[i] == 'W' and a[i+1] =='B': a[i] ='B' a[i+1] = 'W' ans.append(i+1) count = count +1 elif a[i] == 'W' and a[i+1] =='W': a[i] ='B' a[i+1] = 'B' ans.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...
from sys import stdin, stdout #import math from collections import deque input = stdin.readline n = int(input()) seqB = list(input()) seqW = seqB.copy() for i in range(0, n): if seqB[i] == 'B': seqB[i] = True seqW[i] = False else: seqB[i] = False seqW[i] = True opsB = deque()...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 primeFactors(long long int n) { long long int count = 0; long long int answer = 1; while (n % 2 == 0) { count++; n = n / 2; } if (count % 2 == 1) answer = 2; for (long long int i = 3; i <= sqrt(n); i = i + 2) { count = 0; while (n % i == 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 oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) n=int(input()) s=input() #with every move, the black parity and white parity don't change if s.count('B')%2!=n%2 and s.count('W')%2!=n%2: #impossible print(-1) else: #make everything B. B counts must have same parity as n if s.count('...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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.*; public class Blocks { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(input.readLine()); String str = input.readLine(); char[] blocks = new char[n]; for (int i = 0; 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=list(input()) Nb=0 Nw=0 for i in s: if i=='W':Nw+=1 elif i=='B':Nb+=1 if Nb%2==1 and Nw%2==1:print(-1) elif Nb==0 or Nw==0:print(0) else: ans='' count=0 WB=['W','B'] tmp=[0,1][Nb%2==0] for i in range(n-1): if s[i] == WB[tmp]: s[i]=WB[1-tmp] ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 from __future__ import division, print_function import os import 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 # region fastio BUFSIZE = 8192 class FastIO(IOBase): ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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(input()) pp = p[:] ans = [] for i in range(n-1): if pp[i]=='W': ans.append(i+1) if pp[i+1]=='W': pp[i+1] = 'B' else: pp[i+1] = 'W' if pp[-1]=='B': print(len(ans)) print(*ans) exit(0) pp = p[:] ans = [] for i in range(n-1): 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...
I = input n=int(I()) s=list(I()) b=[] w=[] for i in range(n): if s[i]=='W': w.append(i+1) else: b.append(i+1) bc=len(b) wc=len(w) ans=[] q=-1 if bc==0 and bc==n: print(0) elif wc==0 and wc==n: print(0) else: if bc%2!=0: if wc%2!=0: q=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...
from functools import reduce import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import * from io import BytesIO, IOBase input = lambda: sys.stdin.readline().rstrip("\r\n") def value(): return tuple(map(int, input().split())) # multiple values def ar...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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; char a[n + 1]; for (long long int i = 0; i < n; ++i) { cin >> a[i]; } char ini = a[0]; long long int count = 0; vector<long long int> v1; for (long long int i = 1; i < n; ++i) { if (a[i] != ini) { if (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()) word = input() arr = list(map(str,word)) if word==n*'B': print(0) elif word==n*'W': print(0) else: ans = [] for i in range(n-1): if arr[i]=='B': ans.append(i+1) arr[i] = 'W' if arr[i+1]=='W': arr[i+1] = 'B' else: ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; char a[205]; void solve() { int n; cin >> n; int w = 0, b = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == 'W') w++; if (a[i] == 'B') b++; } int cnt = 0; vector<int> ans; ans.clear(); if (w % 2 && 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; char a1[10000]; int s = 0, p = 0, k = 0; int a2[1000]; void chnage_fun12(int i, int g) { if (a1[i] == 'W') a1[i] = 'B'; else a1[i] = 'W'; if (a1[g] == 'W') a1[g] = 'B'; else a1[g] = 'W'; } void chnage_fun(int i, int g) { s--; a2[p] = i + 1; 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=input() ar=list(s) br=list(s) b=0 w=0 for i in(ar): if i=="B": b+=1 else: w+=1 ans=[] ans1=[] count=0 flag=0 if b==0 or w==0: print("0") else: for i in range(n): if(i==n-1): break if(ar[i]==ar[i+1]): if(ar[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 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...
import java.io.*; import java.util.*; public class Main{ static int mod = (int)(Math.pow(10, 9) + 7); public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n =sc.nextInt(); String s= sc.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...
x = int(input()) y = input() out = list() printo = list() for i in range(len(y)): if y[i] == "W": out.append(1) else: out.append(0) if out.count(0) % 2 == 0 or out.count(1) % 2 == 0: for j in range(len(out) - 1): if out[j] % 2 != out[0] % 2: out[j] += 1 out[j ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; void faster() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); if (0) { freopen( "input" ".in", "r", stdin); freopen( "input" ".out", "w", stdout); } } int n; string s; bool w[2100], b[2100], go...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int resultbool = 1; string x = s; vector<int> v1, v2; for (int i = 0; i < n - 1; i++) { if (s[i] == 'B') { s[i] = 'W'; v1.push_back(i + 1); if (s[i + 1] == 'W') s[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...
# Whatever the mind of man can conceive and believe, it can achieve. Napoleon Hill # by : Blue Edge - Create some chaos n=int(input()) s=input() b=s.count("B") w=n-b if b&1 and w&1 and n%2==0: print(-1) elif n&1: d={"W":"B","B":"W"} c={"W":w,"B":b} s=list(s) if b&1: t="W" else: ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import collections n=int(input()) a=input() d=collections.Counter(a) if d['B']%2!=0 and d['W']%2!=0: print("-1") else: if d['B']==0 or d['W']==0: print(0) else: # doing for W ans=list(a) ansf=[] for i in range(0,n-1): if ans[i]=='B': ans[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 javafx.beans.NamedArg; import java.io.*; import java.util.Comparator; import java.util.*; /** * @author Yuxuan Wu */ public class Main { public static final int RANGE = 1000000; static int MAX = Integer.MAX_VALUE; static int MIN = Integer.MIN_VALUE; static int MODULO = 1000000007; static Sc...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
t = int(input()) s = list(input()) l1 = [] l2 = [] B = 0 W = 0 j = 0 p = [] q = [] for i in s: l1.append(i) l2.append(i) if l1[j] == "W": W += 1 else: B += 1 j += 1 if W==0 or B==0: print(0) else: for k in range(t-1): if l1[k] != 'B': l1[k] = '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 calculate_p(l): p = [] for i in range(0, len(l), 2): if l[i + 1] - l[i] == 1: p.append(l[i] + 1) # 1-indexed else: p.extend([j + 1 for j in range(l[i], l[i + 1])]) # 1-indexed return p def blocks(n, s): b = [] w = [] for i in range(n): if s...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import 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.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.Writer; import java.io.OutputStream...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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()) k = 0; result = [] for i in range(n - 1): if a[i] == 'W': k += 1 result.append(i + 1) a[i] = 'B' if a[i + 1] == 'W': a[i + 1] = 'B' else: a[i + 1] = 'W' if a[n - 1] == 'B': print(k) print(*result) else: if (n - 1) % 2 == 0: print(k + (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...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, c1 = 0, c2 = 0, cnt = 0; cin >> n; string s; cin >> s; vector<long long> v; vector<long long> ans; for (i = 0; i < s.length(); i++) { if (s[i] == 'W') { v.push_back(0); c1++; } else { v.push_back(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()) aa=input() a=[i for i in aa] b=0 w=0 for i in a: if i=='W': w += 1 else: b += 1 if w==0 or b==0: print(0) else: ans=[] for i in range(n-1): if a[i]=='B': ans.append(i+1) a[i]='W' if a[i+1]=='B': a[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...
from sys import stdin, stdout from collections import Counter, defaultdict pr=stdout.write def ni(): return int(raw_input()) def li(): return list(map(int,raw_input().split())) def pn(n): stdout.write(str(n)+'\n') def pa(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total intege...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 white(arr1): arr = arr1.copy() ans = [] for i in range(1,len(arr)): if arr[i-1] == 0: arr[i-1]^=1 arr[i]^=1 ans.append(i) if arr[-1] == 1: return ans else: return 0 def black(arr1): arr = arr1.copy() ans = [] for i in rang...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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; import java.util.Vector; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); String a = sc.next(); char arr[] = a.toCharArray(); int x[] = new in...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; import java.io.*; public class problem2 { public static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.math.*; import java.util.*; public class test { static int INF = 1000000007; public static void main(String[] args) { // int test = fs.nextInt(); int test = 1; for (int cases = 0; cases < test; cases++) { int n = fs.nextInt(); char ar[] = fs.next().toCharArray(); int 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() l=[] i=0 s=list(s) x=s.copy() tag=True while i<len(s): if i==len(s)-1: if s[i]=='W': tag=False break else: break elif s[i]=='W': l.append(i+1) 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...
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; long long int inf = 1000000000000000000; vector<int> ans, from, to; string s; int n; void suka(char c, char cc) { int sc = 0; for (int i = 0; i < n; i++) { if (s[i] == s[i + 1] && s[i] == c) sc++, i++; } for (int i = 0; i < n; i++) { 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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; imp...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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,ar): track = [] cnt = 0 s = ar[:] ##make everything white blocks for i in range(n-1): if s[i] == 'W': continue else: s[i] = 'W' if s[i+1] == 'B': s[i+1] = 'W' else: s[i+1] = 'B' cnt += 1 track.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...
import javax.print.DocFlavor; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.IllegalCharsetNameException; import java.sql.SQLOutput; import java.util.*; public class Main { static int[] arr; static boolean[] 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...
n=int(input()) s=input() c1=s.count('W') def swap(s): if s=='W':return 'B' else:return'W' if 'W' not in s or 'B' not in s:print(0) elif (n-c1)%2 and c1%2:print(-1) else: L=list(s) sol=[] for i in range(1,n-1): if L[i]!=L[i-1]: L[i],L[i+1]=swap(L[i]),swap(L[i+1]) sol.a...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) throws IOException { Reader.init(); int n=Reader.nextInt(); String S=Reader.next(); int w=0; int b=0; for(int i=0;i<n;i++){ if(S.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...
from typing import List def solve_for(c: bool, blocks: List[bool]): flipped = [] for i in range(len(blocks) - 1): if blocks[i] != c: blocks[i] = not blocks[i] blocks[i+1] = not blocks[i+1] flipped.append(i) if blocks[-1] == c: return flipped else: return None def main(): n: int = 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...
//package com.company; import java.io.*; import java.util.*; import java.lang.*; public class Main{ public static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 typing import List def make_equal_to(x: bool, blocks): flips = [] for i in range(len(blocks)-1): # blocks[i] if blocks[i] != x: # flip i, i+1 blocks[i] = not blocks[i] blocks[i+1] = not blocks[i+1] flips.append(i+1) if blocks[-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...
//package dec15; import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class B { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(i...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, c; cin >> s; vector<int> vw, vb; c = s; int a = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == 'B' && s[i + 1] == 'B') { s[i] = 'W'; s[i + 1] = 'W'; vw.push_back(i + 1); } else 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...
import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class ProbB { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=0; List<Integer> l = new ArrayList<>(); n = sc.nextInt(); String s = sc.next(); char a[] = s.toCharArray(); ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): n = ri() S = list(input()) S2 = list(S) target = S[0] moves = [] swap = {"W":"B", "B":"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 = input() b,w = s.count('B'),s.count('W') if b==n or w==n: print(0) elif b%2==1 and w%2==1: print(-1) else: c,p = 0,0 ans = [] if w%2==0: x = "W" else: x = "B" for i in range(n): if (s[i]==x and p==0) or (s[i]!=x and p==1): p = 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...
// package com.company; import java.util.*; import java.lang.*; import java.io.*; //****Use Integer Wrapper Class for Arrays.sort()**** public class BE2 { public static void main(String[] Args){ FastReader scan=new FastReader(); int n=scan.nextInt(); StringBuilder s=new StringBuilder(scan.ne...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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) 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 N; string s; int arr[210]; vector<int> res; int main() { ios_base::sync_with_stdio(0); cin >> N >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == 'B') arr[i] = 1; else arr[i] = 0; } for (int i = 1; i + 1 < s.length(); i++) { 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...
#!/usr/bin/env python3 import sys #lines = stdin.readlines() def rint(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline().rstrip('\n') def oint(): return int(input()) n = oint() s = list(input()) bc = s.count('B') wc = s.count('W') if bc %2 and wc %2: 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...
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); String str=s.next(); char[] arr=new char[n]; for(int i=0;i<n;i++) { arr[i]=str.charAt(i); } ArrayList<Integer> 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...
#include <bits/stdc++.h> using namespace std; void change(char &x) { if (x == 'B') x = 'W'; else x = 'B'; } int main() { string s; int n; cin >> n; cin >> s; int w = 0, b = 0; for (int i = 0; i < n; i++) { if (s[i] == 'B') b++; else w++; } if (b % 2 != 0 && w % 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.*; import java.io.*; public class Codeforces { static InputReader in=new InputReader(System.in); static OutputWriter out=new OutputWriter(System.out); static StringBuilder sb=new StringBuilder(); static long MOD = (long)(998244353); // Main Class Starts Here pub...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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; vector<int> ans; for (int i = 0; i < n; i++) { if (i < n - 1) { if (s[i] == 'W') continue; if (s[i + 1] == 'B') { ans.push_back(i + 1); s[i] = 'W'; 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.*; import java.util.ArrayList; /** * Created by Ayushi on 15/12/2019. */ public class B { public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); String[] a = r.readLine().split(" "); int n = Inte...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 flip(s,i): s[i] = 'B' if s[i] == 'W' else 'W' n = int(raw_input()) s = list(raw_input()) color = s[0] ops = [] for i in xrange(1,n-1): if s[i] != color: ops.append(i+1) flip(s,i) flip(s,i+1) if s[-1] == color: # we are done! print len(ops) for op in ops: print op, else: # oh no, the last one must be ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
/** * Date: 15 Dec, 2019 * Link: https://codeforces.com/contest/1271/problem/B * * @author Prasad Chaudhari * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/ * @git: https://github.com/Prasad-Chaudhari */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; impor...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
'''input 3 BWB ''' n = int(input()) string = input() temp = [] for ele in string: if ele == 'B': temp.append(0) else: temp.append(1) string = temp[::] ans = [] temp = string[::] for i in range(n - 1): if temp[i] == 0: temp[i] ^= 1 temp[i + 1] ^= 1 ans.append(i +...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const int MAX = 5e5 + 10; int main() { int n; string s, s1; cin >> n >> s; s1 = s; int i = n - 1; vector<int> v1, v2; while (i > 0) { while (i >= 1 && s1[i] == 'B') i--; if (i >= 1) { s1[i] = 'B'; if (s1[i - 1] == 'W') s1[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()) cw=0 cb=0 l=[] for i in range(n-1): if s[i]=='B': s[i]='W' s[i+1]='W' if s[i+1]=='B' else 'B' l.append(i+1) if s[n-1]=='W': print(len(l)) if len(l)>0: print(*l,sep=" ") else: if n%2==1: for i in range(0,n-1,2): ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; public class vk18 { public static void main(String[]st) throws Exception { Scanner scan=new Scanner(System.in); //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //String[] s; int n; String na; n=scan.nextI...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 N = int(input()) S = [1 if a == 'W' else 0 for a in list(input().rstrip())] ans = [] for i in range(1,N-1): if S[i-1] != S[i]: S[i] ^= 1 S[i+1] ^= 1 ans.append(i+1) if S[N-2] != S[N-1] and N%2 == 0: print(-1) else: if S[N-2] != S[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...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; public class P9 { public static void main(String args[]) { try{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String a=br.readLine(); if(Blocks(a)==null) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
def swap(a): if(a=='B'): return 'W' return 'B' n = int(input()) s = list(input()) w = s.count('W') b = len(s)-w ans = 0 arr = [] if(b%2==0): for i in range(len(s)-1): if(s[i]=='B'): s[i]=swap(s[i]) s[i+1]=swap(s[i+1]) ans+=1 arr.append(i) elif(w%2==0): for i in range(len(s)-1): if(s[i]=='W'): 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...
#include <bits/stdc++.h> using namespace std; struct FASTINPUT { void f(string& s) { char buf[400005]; long long a = scanf("%s", buf); a++; s = buf; } void f(long long& x) { long long a = scanf("%lld", &x); a++; } void f(int& x) { long long a = scanf("%d", &x); a++; } void ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; long long fact(long long n); long long nCr(long long n, long l...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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()) sq = input().strip() sq = list(sq) b, w = (0, 0) for ch in sq: if ch == 'B': b += 1 else: w += 1 # only single type if b == 0 or w == 0: print(0) exit(0) # if both of them is odd elif b & 1 == 1 and w & 1 == 1: print(-1) exit(0) if b & 1 == 0: f = 'W' 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...
from collections import Counter as C,defaultdict as D,deque as Q from operator import itemgetter as I from itertools import product as P,permutations as PERMUT from bisect import bisect_left as BL,bisect_right as BR,insort as INSORT from heapq import heappush as HPUSH,heappop as HPOP from math import floor as MF,ceil 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() arr=[] for i in s: if i=='B': arr.append(1) else: arr.append(0) b=sum(arr) w=n-b if w*b == 0: print(0) elif w%2 and b%2: print(-1) else: if b%2: target=0 else: target=1 ans=[] for i in range(n-1): if arr[i]==target: ans.append(i+1) arr[i+1]=1-arr[i+1] print(len(ans)) 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 = input() b = w = 0 for c in s: if c == 'B': b += 1 else: w += 1 if w % 2 == 1 and b % 2 == 1: print(-1) else: ans = list() s = list(s) if w % 2 == 1: for i in range(len(s)-1): if s[i] != 'W': ans.append(i + 1) s[i] = 'W' s[i+1] = 'B' 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; int main() { int n; cin >> n; string s, t; cin >> s; t = s; vector<int> ans, an; for (int i = int(0); i <= int(n - 2); i++) { if (s[i] == 'W') continue; s[i] = 'W'; if (s[i + 1] == 'B') s[i + 1] = 'W'; else s[i + 1] = 'B'; ans.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...
#include <bits/stdc++.h> using namespace std; string s; int main() { ios::sync_with_stdio(false); long long n, num = 0; cin >> n >> s; for (long long i = 0; i < s.size(); i++) { if (s[i] == 'B') num++; } if (n % 2 == 0 && num % 2 == 1) { cout << -1; return 0; } if (n % 2 == 0) { vector<l...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; const long long mod = (1e9) + 7; void solve() { int n, i, a = 0, b = 0; string s; vector<int> v; cin >> n >> s; for (i = 0; i < n; i++) { if (s[i] == 'W') a++; else b++; } if (a % 2 == 1 && b % 2 == 1) { 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...
from fractions import gcd # from datetime import date, timedelta from heapq import* import math from collections import defaultdict, Counter, deque from bisect import * import itertools import sys sys.setrecursionlimit(10 ** 7) MOD = 10 ** 9 + 7 # input = sys.stdin.readline def main(): n = int(input()) 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...
import java.util.ArrayList; import java.util.Scanner; public class Blocks { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); String str = s.next(); char[] a = str.toCharArray(); ArrayList<Integer> index = new ArrayList<>(); ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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() oper=[] operation=0 blackwhite=[0,0] for i in b: if i=='B': blackwhite[0]+=1 else: blackwhite[1]+=1 if (a-blackwhite[0])%2==0: glavcvet='B' zapcvet='W' elif (a-blackwhite[1])%2==0: glavcvet='W' zapcvet='B' else: glavcvet='Z' print(-1) if glavcvet!...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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; import java.util.ArrayList; public class Main { public static void main(String args[]) { Scanner s = new Scanner(System.in); int n = s.nextInt(); String str = s.next(); int b = 0,w = 0; ArrayList<Integer> black = new ArrayList<>(); ArrayList<...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.io.*; import java.util.*; import java.lang.*; public class Codechef { static long mod = 1000000007; PrintWriter out; StringTokenizer st; BufferedReader br; class Pair { int f; int s; public Pair(int t, int r) { f = t; s = r; } } String ns() {...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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 turn(blocks, frc, toc): res=[] for i in range(len(blocks) - 1): if blocks[i] == frc: res.append(i + 1) blocks[i] = toc if blocks[i+1] == frc: blocks[i + 1] = toc else: blocks[i + 1] = frc print(len(res)) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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; public class Blocks { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(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...
// No sorceries shall previal. // import java.util.Scanner; import java.io.PrintWriter; import java.util.*; import java.util.Arrays; public class _InVoker_ { public static void sort(int arr[], int start, int end) { if(start>=end) return; int mid=(start+end)/2; sort(arr,start,mid)...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more 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.math.*; import java.util.*; public class BruteForce { public static Scanner in = new Scanner(System.in); public static boolean ok(char[] z) { boolean ans = true; StringBuilder build = new StringBuilder(); for (char c : z) { build.append(c); } 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; long long a, b, c, d, e, f; int n; string s; void kaisa() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; cin >> s; s = " " + s; int dem1 = 0, dem2 = 0; for (int i = 1; i <= n; i++) { if (s[i] == 'B') dem1++; else ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
import java.util.*; import java.io.*; public class Main { public static PrintStream out = new PrintStream(System.out);; public static void main(String[] args){ FastScanner sc = new FastScanner(); int countW = 0; int countB = 0; int n = sc.nextInt(); String s = sc.nextLine(); 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...
n = input() a = raw_input() if a.count('B')%2!=0 and a.count('W')%2!=0: print -1 exit(0) if a.count('B')%2==0: l = [] s = 0 ans = [] for i in range(n): if l==[]: l.append(a[i]) s+=1 continue if l[-1]=='W': l.append(a[i]) ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i <= 1; i++) { char x = "WB"[i]; string t = s; vector<int> ve; for (int j = 0; j + 1 < n; j++) { if (t[j] != x) { t[j] ^= 'w' ^ 'B'; t[j + 1] ^= 'W' ^ 'B'; ...
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; public final class GFG { public static void main (String[] args) { Scanner in =new Scanner(System.in); int n=in.nextInt();in.nextLine(); String input=in.nextLine(); char[] line=input.toCharArray(); 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 n, a[205], cnt, b, w, t[205]; string x; int main() { cin >> n; cin >> x; for (int i = 0; i < x.size(); i++) { if (x[i] == 'B') t[i] = 0, b++; else t[i] = 1, w++; } if (b % 2 & w % 2) { cout << -1; return 0; } b = b % 2 ? 0 : 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; char s[300]; int a[300], n; vector<int> ans; bool check1() { int cnt = 0; for (int i = 1; i <= n; i++) if (a[i] == 1) cnt++; return cnt == n; } bool check2() { int cnt = 0; for (int i = 1; i <= n; i++) if (a[i] == 0) cnt++; return cnt == n; } void work(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...
/* package codechef; // don't place package name! */ import java.util.*; import java.util.regex.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { S...