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())
B,W = 0,0
s = input()
ss = []
for i in range(0,len(s)):
ss.append(s[i])
if(s[i] == 'B'):
B = B + 1
else:
W = W + 1
# print(B,W)
if(W % 2 == 1 and B % 2 == 1):
print(-1)
else:
a = []
flag = 0
# print(len(s))
if(B % 2 == 0):
flag = 1
elif(W % 2 == 0):
flag = 2
for i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int b = 0, w = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'W')
w++;
else
b++;
}
if (b % 2 == 1 && w % 2 == 1) {
cout << "-1";
return 0;
}
vector<int> v;
if (b % 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... | # code by RAJ BHAVSAR
n = int(input())
s = list(str(input()))
temp = s[:]
ans = []
for i in range(n-1):
if(s[i] == 'B'):
ans.append(i+1)
s[i] = 'W'
s[i+1] = 'W' if s[i+1] == 'B' else 'B'
if(len(set(s)) == 1):
print(len(ans))
print(*ans)
else:
ans = []
for i in range(n-1):
if(temp[i] == 'W'):
ans.append(... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
void resolve() {
int n;
string s;
cin >> n >> s;
int w = 0, b = 0;
for (int i = 0; i < s.size(); i++) w += (s[i] == 'W'), b += (s[i] == 'B');
if (w == 0 || b == 0)
cout << 0;
else if (w % 2 == 1 && b % 2 == 1)
cout << -1;
else {
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.*;
import java.util.*;
public class blocks {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
String blockString = in.readLine();
char[] block... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 affichage(L):
for i in range(len(L)):
L[i]=str(L[i])
return(' '.join(L))
def executeB(L,n):
L2=[]
for i in range(n):
if L[i]!='B':
L[i]='W'
if 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;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> v;
int b = count(s.begin(), s.end(), 'B');
int w = count(s.begin(), s.end(), 'W');
if (b % 2 == 1 && w % 2 == 1) {
cout << "-1";
return 0;
}
if (b % 2 == 0) {
for (int i = 0; i < (... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import defaultdict
from math import factorial as f
from fractions import gcd as g
n = int (raw_input ())
s = raw_input ()
l = []
w, b = 0, 0
result = []
for i in s:
if i == "B":
l.append(0)
b += 1
else:
l.append(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.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import java.lang.management.*;
import static java.lang.Math.*;
@SuppressWarnings("unchecked")
public class P1271B {
int n, k;
StringBuilder ans;
void change(char [] s, char c) {
k = 0;
ans = new StringBuilder();
f... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const long long INF = 1e15 + 7;
const long long N = 2e5 + 10;
const long long mod = 998244353;
long long pow(long long x, long long y) {
long long res = 1;
while (y > (long long)0) {
if (y & (long long)1) res = ((res) * (x));
y = y >> ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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>
char S[210];
int b = 0, w = 0, pos[210], tot = 0;
int main() {
int n, i, k;
scanf("%d%s", &n, S + 1);
for (i = 1; i <= n; i++)
if (S[i] == 'B')
b++;
else if (S[i] == 'W')
w++;
if (b == 0 || w == 0) {
printf("0\n");
return 0;
} else if ((b % 2) && (w % 2)) {... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the templa... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()
mod=1e9+7
"""========main code==============="""
t=1
#t=ii()
for _ in range(t):
n=ii()
s=ip()
a=s.count('B')
b=s.count('W')
k='N'
i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int32_t main() {
vector<long long> ans;
long long n;
cin >> n;
string a, b;
cin >> a;
b = a;
for (long long i = 0; i < n - 1; i++) {
if (b[i] == 'W') {
ans.push_back(i + 1);
b[i] = 'B';
if (b[i + 1] == 'W')
b[i + 1] = 'B';
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... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, z = 0, o = 0;
cin >> n;
char x;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> x;
if (x == 'B') {
v[i] = 0;
z++;
}
if (x == 'W') {
v[i] = 1;
o++;
}
}
if (z == 0 || o == 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;
long long int INF = 1e18;
const long long fact_table = 5000000;
double Pi = 3.1415926535897932384626;
vector<long long> G[550010];
vector<pair<long long, double> > tree[500010];
priority_queue<long long> pql;
priority_queue<pair<long long, long long> > pqp;
priority_queue<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... | n=int(input())
s=list(input())
i=0; ans=[]; ss=s.copy()
while i<n-1:
if s[i]=='B':
s[i]='W'
s[i+1]='B' if s[i+1]=='W' else 'W'
ans.append(i+1)
i+=1
if s.count('B')==0:
print(len(ans))
print(*ans)
else:
i=0; ans=[]; s=ss
while i<n-1:
if s[i]=='W':
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... | def invert(c):
if c=='W':
return 'B'
return 'W'
def solve():
n = int(input())
s = list(input())
w = s.count('W')
b = s.count('B')
if w%2!=0 and b%2!=0:
print(-1)
return
if b%2==1:
ch = 'B'
else:
ch = 'W'
ans = []
for i in range(len(s)-1... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | /* 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
{
// your code goes here
Scanner s = new Sca... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.ma... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
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... | /*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
****************************************
*... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 boost() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int main() {
boost();
int n;
string s;
cin >> n >> s;
vector<int> ans;
for (int i = 0; i < n - 1; i++) {
if (s[i] == 'W') {
s[i] = 'B';
if (s[i + 1] == 'W') {
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 check(int* a, int n) {
for (int i = 0; i < n; i++)
if (a[i] == 0) return i;
return -1;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int one = 0, zer = 0;
for (int i = 0; i < n; i++)
if (s[i] == 'W')
one++;
else
zer++;
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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
/**
* @author Mubtasim Shahriar
*/
public class Blocks {
public static 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... | import sys
def Solve():
N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()
S = [0 if a == 'B' else 1 for a in S]
ops = []
def Op(i):
S[i + 1] = S[i + 1] ^ 1
S[i] = S[i] ^ 1
ops.append(i)
for i in range(0, N - 1):
if S[i]: Op(i)
if S[-1]:
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int countColor(string s, char c) {
int ans = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == c) {
ans++;
}
}
return ans;
}
void change(char& c) {
if (c == 'W') {
c = 'B';
} else {
c = 'W';
}
}
void solve(string s, char c, vector<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())
s = input()
s = [0 if ss=='W' else 1 for ss in s]
target = sum(s)%2
count = 0
answer = []
for i in range(len(s)-1):
if s[i] != target:
count += 1
answer.append(i+1)
s[i+1] = 1 - s[i+1]
if s[-1]!=target:
print(-1)
else:
print (count)
print (" ".join(map(str,an... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import sys
inf = float("inf")
# sys.setrecursionlimit(10000000)
# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 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... | n = int(input())
arr = list(input())
n1 = 0
n2 = 0
for i in arr:
if i=='W':
n1 += 1
else:
n2 += 1
if (n1*n2)%2==1:
print(-1)
elif arr == [arr[0]]*n:
print(0)
else:
ans = []
i = 0
while arr[i]=='W':
i += 1
while i<n-1:
if arr[i]==... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | def main():
n=int(input())
l=list(input())
b=l.count('W')
val=[]
if ('B' not in(l))or('W' not in(l)):
print(0)
elif n%2==0 and b%2==1:
print(-1)
else:
if n%2==0:
for i in range(1,n-1):
if l[i-1]!=l[i]:
l[i]=l[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())
b = 0
w = 0
for x in s:
if x == 'W':
w += 1
else:
b += 1
if b % 2 and w % 2:
print(-1)
exit()
if b % 2:
c = 'B'
c1 = 'W'
else:
c = 'W'
c1 = 'B'
#c1 is W and c is B
a = []
for i in range(n - 1):
if s[i] == s[i + 1] == c1:
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;
const int maxn = 1e5 + 5;
string s;
int a[maxn], tot, n;
int main() {
while (cin >> n) {
memset(a, 0, sizeof a);
tot = 0;
cin >> s;
string temp = s;
if (n == 1) {
puts("0");
continue;
}
for (int i = n - 1; i >= 1; i--) {
if (s... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int debug = 1;
int test = 1;
long double pi = 3.14159265358979323846;
inline long long int min2(long long a, long long b) {
if (a < b) {
return a;
}
return b;
}
inline long long max3(long long a, long long b, long long c) {
return (a) > (b) ? ((a) > (c) ? (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() {
int n;
string s;
cin >> n;
cin >> s;
int c = 0, b = 0, w = 0, i;
vector<int> v;
for (i = 0; i < n; i = i + 1) {
if (s[i] == 'B')
b = b + 1;
else if (s[i] == 'W')
w = w + 1;
}
if (b % 2 != 0 && w % 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... | import java.io.BufferedReader;
//import java.io.CharConversionException;
import java.io.IOException;
import java.io.InputStreamReader;
//import java.util.Comparator;
//import java.util.Deque;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import javafx.beans.binding.StringBinding;
/... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
# B. Suits
# Link https://codeforces.com/contest/1271/problem/B
n = int(input())
a = list(input())
w = 0
b = 0
for it in a:
if it == 'W':
w+=1
else:
b+=1
x = 'W'
y = 'B'
if(w%2 == 1 and b % 2 == 1):
print(-1)
else:
if(b % 2 == 1):
x = 'B'
y = 'W'
ans = []
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... | 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.util.List;
import java.io.Writer;
impo... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 = []
n_B = 0
n_W = 0
ans = []
for c in s:
if c == 'W':
n_W += 1
x = 1
else:
n_B += 1
x = 0
L.append(x)
is_possible = True
if n_B % 2 and n_W % 2:
is_possible = False
if n_W == 0 or n_B == 0:
print(0)
elif is_possible:
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... | #include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long mod) {
if (b == 0 || a == 1) {
if (mod == 1)
return 0;
else
return 1;
}
if (b % 2 == 0) {
long long k = powmod(a, b / 2, mod);
return (k * k) % mod;
} else {
long long k = powmod(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()
b=[]
for j in s:
b.append(j)
res=[]
j=0
while(j<n-1):
if b[j]=="B" and b[j+1]=="W":
b[j],b[j+1]=b[j+1],b[j]
res.append(j+1)
j+=1
elif b[j]=="B" and b[j+1]=="B":
b[j]="W"
b[j+1]="W"
res.append(j+1)
j+=2
else:
j+=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... | a=int(input())
b=list(input())
n=0
n1=[]
z=b[:]
e=b
for i in range(len(b)-1):
if(b[i]=='W'):
b[i]='B'
if(b[i+1]=='W'):
b[i+1]='B'
else:
b[i+1]='W'
n+=1
n1.append(i+1)
if(b.count('W')!=a and b.count('B')!=a):
e=b[:]
for i in range(len(b)-1):
if(b[i]=='B'):
b[i]='W'
if(b[i+1]=='B'):
b[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())
blacks = s.count('B')
whites = n - blacks
operations = []
if( blacks&1== whites&1 ==1):
print(-1)
exit()
elif( blacks&1==1):
i=0
while(i<n):
if(s[i]=='W'):
operations.append(i+1)
s[i]='B'
if(i+1< n):
i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
bool inc[205];
vector<int> ans;
int main() {
cin >> n;
cin >> s;
for (int i = 0; i < n; i++) {
if ('B' == s[i]) {
inc[i + 1] = 1;
} else
inc[i + 1] = 0;
}
bool cop[205];
for (int i = 1; i <= n; i++) cop[i] = inc[i];
for (in... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.math.BigInteger;
public class asd
{static Scanner s=new Scanner(System.in);
public static void main(String args[]) throws Exception
{
int t=1;
while(t-->0)
{
solve();
}
}
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | /**
* BaZ :D
*/
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main
{
static MyScanner scan;
static PrintWriter pw;
static long MOD = 1_000_000_007;
static long INF = 1_000_000_000_000_000_000L;
static long inf = 2_000_000_000;
public static void main(Stri... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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;
class BBlocks {
public:
void solve(std::istream &in, std::ostream &out) {
string s;
in >> s >> s;
string x = "BW";
for (auto y : x) {
vector<int> answer;
int n = s.length();
string t = s;
for (int i = 0; i + 1 < n; ++i) {
i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=list(input())
c1=s.count('B')
c2=s.count('W')
if c1%2==1 and c2%2==1:
print(-1)
else:
x='W' if c2%2==0 else 'B'
q=0
c=0
a=[]
for i in range(n):
if s[i]==x and q==0 or s[i]!=x and q==1:
q=1
c+=1
a.append(i+1)
else:
q... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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.buffer.readline
n = int(input())
s = list(map(lambda x: 0 if x == 'B' else 1,list(input().strip())))
def flip(index):
if s[index] == 0:s[index] = 1
else:s[index] = 0
out = []
for i in range(1,len(s)-1):
if s[i] == s[0]:continue
flip(i); flip(i+1)
out.append(i + 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... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w = 0, b = 0;
char s[205];
vector<int> v;
scanf("%d %s", &n, s);
for (int i = 0; i < n; i++) {
if (s[i] == 'W')
w++;
else
b++;
}
if (w % 2 == 0) {
for (int i = n - 1; i > 0; i--)
if (s[i] == 'W') {
v.pu... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
import org.omg.CORBA.INTERNAL;
import sun.awt.image.ImageWatched;
import sun.reflect.generics.tree.Tree;
import java.nio.channels.ScatteringByteChannel;
import java.text.SimpleDateFormat;
import java.util.*;
public final class Main {
public static void main(String[] args) {
Scanner s = new Scanner(Syst... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
string str;
cin >> str;
int b = 0, w = 0;
for (int i = 0; i < n; i++) {
if (str[i] == 'W') {
w++;
} else {
b++;
}
}
if (w % 2 != 0 && b % 2 != 0) {
cout << "-1";
} else if (w == 0 || b == ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
public class File {
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a;
int n, i, b = 0, w = 0;
scanf("%d", &n);
char c[n];
scanf("%s", c);
for (i = 0; i < n; ++i) {
if (c[i] == 'B') ++b;
if (c[i] == 'W') ++w;
}
if (b == 0 || w == 0) {
printf("0");
return 0;
}
if (b % 2 == 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.Scanner;
public class BAy {
public static void main(String[] args) {
int num; String s;
Scanner scan = new Scanner(System.in);
num=scan.nextInt();
s=scan.next();
char[] s1 = s.toCharArray();
char[] s2 = s.toCharArray();
int dex=0;
int arr[] = new int[num];
for(int i=0;i<num-1;i++){
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int n;
string s, t;
vector<int> ans;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
cin >> s;
t = s;
for (int i = 0; i < n - 1; i++) {
if (s[i] == 'W') {
s[i] = 'B';
if (s[i + 1] == 'B')
s[i + 1] = 'W';
else
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
long long powm(long long base, long long exp, long long mod = 1000000007) {
long long ans = 1;
while (exp) {
if (exp & 1) ans = (ans * base) % mod;
exp >>= 1, base = (base * base) % mod;
}
return ans;
}
int32_t main() {
long long n;
cin >> n;
string s;... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
n = int(input())
s = [int(i=="B") for i in input()]
b = sum(s)
w = n-b
if w*b == 0:
print(0)
elif w%2 and b%2:
print(-1)
else:
target = 1 if b%2==0 else 0
ans = []
for i in range(n-1):
if s[i] == target:
ans.append(i+1)
s[i+1] ^= 1
print(len(ans))
print(*ans) |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import sys
n=int(sys.stdin.readline())
s=sys.stdin.readline().strip()
a=[]
for x in range(n):
a.append(s[x])
steps=[]
ans="YES"
for i in range(n-1):
if(a[i]=="B"):
a[i]="W"
if(a[i+1]=="B"):
a[i+1]="W"
else:
a[i+1]="B"
steps.append(str(i+1))
cont=0
for p in range(n):
if(a[p]=="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... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Blocks {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br =... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=input()
arr=[x for x in s]
B=arr.count('B')
W=arr.count('W')
if not B or not W:
print(0)
else:
if B&1 and W&1:
print(-1)
else:
ans=[]
if B%2==0:
for x in range(n-1):
if arr[x]=='B':
if arr[x+1]=='B':
ans.append(x)
arr[x]='W'
arr[x+1]='W'
else:
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=list(input())
z='W'
ans=[]
for i in range(n-1):
if l[i]!=z:
l[i]=z
l[i+1]='W' if l[i+1]=='B' else 'B'
ans.append(i+1)
if l!=['W']*n:
z='B'
for i in range(n-1):
if l[i]!=z:
l[i]=z
l[i+1]='W' if l[i+1]=='B' else '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... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, s1;
int count = 0, count1 = 0;
vector<int> v, v1;
cin.ignore(255, '\n');
getline(cin, s);
s1 = s;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == 'B') {
s[i] = 'W';
s[i + 1] == 'W' ? s[i + 1] = '... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = input()
s = raw_input()
b = s.count('B')
w = n - b
if w == 0 or b == 0:
print 0
else:
ans = []
t = s[0]
flag = 0
for i in range(n - 1):
if (s[i] != t and not flag) or (s[i] == t and flag):
ans.append(i + 1)
flag = 1
else:
flag = 0
if (s[n -... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, a[1000];
string s;
cin >> n;
cin >> s;
j = 0;
for (i = 0; i < n; ++i) {
if (s[i] == 'B') j++;
}
if (n % 2 == 0) {
if (j % 2 == 1) {
cout << -1;
return 0;
}
}
int ans = 0;
int num = 0;
if (j % 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... | from collections import Counter
n = int(input())
s = input()
rr = None
for x in "BW":
res = []
toggle = False
for i, v in enumerate(s):
if v == x:
toggle = not toggle
if toggle:
res.append(i+1)
if not toggle and (rr is None or len(res) < len(rr)):
rr = 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... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void solve() {
long long n;
cin >> n;
string s;
cin >> s;
long long x = 0;
vector<long long> ans;
for (auto &ch : s) {
if (ch == 'B') x++;
}
if (x == 0 || x == n) {
cout << 0;
return;
} else if ((x & 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... | n = int(input())
s = list(input())
k = sum([1 for i in s if i == "B"])
if(n % 2 == 0 and k % 2 == 1):
print(-1)
else:
color = s[0] if n % 2 == 0 else ("B" if k % 2 == 1 else "W")
moves = []
for i in range(n):
if(s[i] == color):
continue
else:
moves.append(str(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 os, sys, math
import collections
if os.path.exists('testing'):
name = os.path.basename(__file__)
if name.endswith('.py'):
name = name[:-3]
src = open(name + '.txt', encoding='utf8')
input = src.readline
def solve():
result = []
data = [ 1 if q == 'W' else 0 for q in n ]
count = 0
for x in range(len(d... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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=input()
c1="W"
c2="B"
WC=L.count(c1)
BC=L.count(c2)
s=[x for x in L]
if WC%2==1 and BC%2==1:
print(-1)
exit()
if WC==n or BC==n:
print(0)
exit()
count1=[]
if WC%2==1 and BC%2==0:
for i in range(len(s)-1):
if s[i]==c2:
count1.append(i+1)
s... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Q2 {
public static void main(String[] args) throws IOException {
// ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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())
out = []
if s.count("B") == n or s.count("W") == n:
print (0)
exit()
for i in range(n-1):
#Bγ«γγ
if s[i] == "W":
s[i] = "B"
out.append(i+1)
if s[i+1] == "B":
s[i+1] = "W"
else:
s[i+1] = "B"
if s.count("B") == n:
print (len(out))
print (" ".join(map(str,out)))
exit(... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | /*
_.!._
/O*@*O\
<\@(_)@/>
,;, .--;` `;--. ,
O@O_ / |d b| \ _hnn
| `/ \ | | / \` |
&&&& :##;\ /;##; &&&&
| \ / `##/| |##' \ / |
\... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
int n;
cin >> n;
cin >> s;
for (auto &c : s) c = (c == 'B') ? 1 : 0;
for (int col = 0; col < 2; col++) {
string t = s;
vector<int> ans;
for (int i = 0; i + 1 < n; i++) {
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = list(input())
cnt_b = 0
cnt_w = 0
for i in range(n):
if s[i] == "B":
cnt_b += 1
if s[i] == "W":
cnt_w += 1
if cnt_b % 2 == 1 and cnt_w % 2 == 1:
print(-1)
exit()
if cnt_b % 2 == 0:
num = 0
ans = []
for i in range(n):
if 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... | import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Short.parseShort;
import static java.lang.Byte.parseByte;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
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... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
public static int check(char[] ch) {
int B = 0, W = 0;
for (int i = 0; i <... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class CF1271B {
static class Pair{
int a;
int b;
Pair(int a,int b){
this.a = a;
this.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... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public c... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
string s;
cin >> s;
vector<int> ans;
for (i = 0; i < n - 1; i++) {
if (s[i] == 'W') {
ans.push_back(i);
s[i + 1] = (s[i + 1] == 'W' ? 'B' : 'W');
}
}
if (s[n - 1] == 'B') {
cout << ans.size() << endl;
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 itertools import product
n=int(input())
s=list(input())
d={'B':0,'W':1}
c1,c2=0,0
for i in range(len(s)):
if s[i]=='B':c1+=1
else:c2+=1
s[i]=d[s[i]]
ans=[]
if c1&1 and c2&1:
print(-1)
else:
for i in reversed(range(1,len(s)-1)):
if s[i]!=s[i+1]:
s[i]^=1
s[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... | N = int(input())
S_raw = input()
S = [0] * N
for i in range(N):
if S_raw[i] == 'B':
S[i] = 1
S_ori = S[:]
ans = []
for i in range(N-1):
if S[i] == 1:
S[i] = 0
S[i+1] = 1 - abs(S[i+1])
ans.append(i+1)
if S[-1] == 0:
print(len(ans))
print(*ans)
exit()
S = S_ori[:]
an... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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())
k = list(input())
b = k.count('B')
t = n-b
count = 0
a=[]
if(b%2 != 0 and t%2!=0):
print(-1)
elif(b==0 or t==0):
print(0)
else:
c=""
q = 1
if(b%(1+1)==0):
while q<n:
if(k[q] == 'B' and k[q-1]=='B'):
k[q] = k[q-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 Hello {
public static long primeFactors(int n)
{
long c = 0;
// Print the number of 2s that divide n
while (n % 2 == 0) {
c++;
n /= 2;
}
// n must be odd at this point... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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=sc.nextInt();
char[] arr=sc.next().toCharArray();
int w=0,b=0;
for(int i=0;i<n;i++)
{
if(arr[i]=='B')
b++;
else
w++;
}
if(w%2==1&&b%2==1)
System.out.printl... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 = input()
s = [l[i:i+1] for i in range(len(l))]
path = []
temp = 'B'
for i in range(len(s)):
if i<n-1:
if s[i]!=temp:
path.append(i)
if s[i+1]!=temp:
s[i+1] = temp
else:
s[i+1] = 'W'
s[i] = temp
flag = 0
for i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
string s, t;
cin >> s;
t = s;
vector<long long int> ans;
for (__typeof(n - 1) i = (0) - ((0) > (n - 1));
i != (n - 1) - ((0) > (n - 1)); i += 1 - 2 * ((0) > (n - 1))) {
if (t[i] != 'B') {
t[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>
const long long LL_INF = (long long)2e18 + 5;
using namespace std;
vector<long long> stone;
long long pow_of_10(long long x) {
long long result = 1;
for (long long i = 1; i < x + 1; i++) {
result *= 10;
}
return result;
}
long long c;
long long gcd(long long a, long long b) {
if (... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
public class Codeforces {
public static void main(String[] args) {
Scanner s = new Scanner(System. in);
// int t = 1;
// while(t>0) {
int n=s.nextInt();
String st=s.next();
char a[]=st.toCharArray();
ArrayList<Integer> a1=new ArrayList<>();
for(int i=0;i<n-1;i++){
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
def main():
nos = int(input())
p = input()
pattern = list(p)
bcount = pattern.count('B')
wcount = pattern.count('W')
if bcount%2 != 0 and wcount%2 != 0:
print(-1)
return 0
count = 0
steps = []
if bcount%2 == 0:
i = 0
while i< len(pattern)-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 i, n, cnt = 0;
cin >> n;
string s;
cin >> s;
vector<int> ans;
for (i = 0; i < n - 1; i++) {
if (s[i] == 'B') {
s[i] = 'W';
s[i + 1] == 'W' ? (s[i + 1] = 'B') : (s[i + 1] = 'W');
cnt++;
ans.push_back(i + 1);
} el... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
blocks = str(input())
count_b = sum([1 for i in blocks if i == 'B'])
count_w = sum([1 for i in blocks if i == 'W'])
if count_b % 2 != 0 and count_w % 2 != 0:
print(-1)
elif count_b == 0 or count_w == 0:
print(0)
else:
ans = []
blocks = list(blocks)
blocks += '1'
while count_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... | # ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
def main():
n = int(input())
sa = input()
s = list(sa)
# print(s)
if len(set(s)) == 1:
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | t=int(input())
l=list(input())
B=l.count('B')
W=l.count('W')
ll=[]
c=l.copy()
if t%2==0:
if B%2!=0 or W%2!=0:
print("-1")
else: ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a;
cin >> a;
string s;
cin >> s;
int len = s.size();
vector<int> v;
int countb = 0;
for (int i = 0; i < len; i++) {
if (s[i] == 'B') {
countb++;
}
}
int countw = len - 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... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string block;
cin >> block;
int b = 0, w = 0;
for (int i = 0; i < n; i++) {
b += block[i] == 'B';
w += block[i] == 'W';
}
if (b % 2 && w % 2) {
cout << -1;
} else {
char change = 'B', to = 'W';
if (b % 2) {... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
string choices = "BW";
for (int c = 0; c < 2; c++) {
string s2 = s;
vector<int> res;
for (int c2 = 1; c2 < s2.size(); c2++) {
if (s2[c2 - 1] != choices[c]) {
s2[c2 - 1] = choices[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... | n = int(input())
string = input()
sequence = [0] * n
for i in range(n):
if string[i] == 'B':
sequence[i] = -1
else:
sequence[i] = 1
def Try(char, seq):
commands = []
count = 0
for i in range(n-1):
if seq[i] != char:
seq[i] = char
seq[i+1] *= -1
commands.append(i+1)
count += 1
if seq[-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.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
char[] a1 = sc.next().substring(0, n).toCharArray();
char[] c = {'B', 'W'};
char[] a2;
int k;
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int w = 0, b = 0, k = 0, i, j, d = 0;
vector<int> v;
char a;
for (i = 0; i < s.size(); i++) {
if (s[i] == 'W')
w++;
else
b++;
}
if (w % 2 != 0 && b % 2 != 0)
cout << -1 << endl;
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.