description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
void fastik() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
void solve() {}
bool check(string a) {
set<char> st;
for (auto i : a) {
st.insert(i);
}
return (int)st.size() == 1;
}
void tryBlack(string s) {}
int main() {
fastik();
long long n;
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... | from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
mod = 10**9 + 7
n = int(input())
a = list(input())
ans = []
for i in range(n-1):
if(a[i] == 'B'):
continue
else:
a[i] = 'B'
if(a[i+1] == 'B'): a[i+1] = 'W'
else: a[i+1] = 'B'
ans.append(i+1)
if(a[-1] == 'W' and n%2 == 0):
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
const int N = (int)1e3 + 10;
int n;
string s;
vector<int> ans;
void change(char &x) {
if (x == 'B')
x = 'W';
else
x = 'B';
}
int check(string s) {
for (int i = 1; i < (int)s.size() - 1; i++) {
if (s[i] != s[i - 1]) {
ans.push_back(i + 1);
chang... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = input()
a = list()
test = 0
for i in s:
if i == 'W':
test += 1
a.append(1)
else:
a.append(0)
answer = list()
if test == 0 or test == n:
print(0)
elif ((test % 2 != 0) or ((n-test) % 2 != 0)) and n % 2 == 0:
print(-1)
else:
for i in range(1,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... | #include <bits/stdc++.h>
using namespace std;
int N;
string str;
int A[205], B[205];
bool inv[205];
void trn(int p) {
B[p] = 1 - B[p];
B[p - 1] = 1 - B[p - 1];
}
bool solve(int p, bool c) {
if (p == N) {
return B[p - 1] == c;
}
if (B[p - 1] != c) {
inv[p] = 1;
trn(p);
} else {
inv[p] = 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.math.BigInteger;
import java.util.*;
import java.io.*;
import java.text.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer t;
static String sn() {
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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;
char s[n], c;
cin >> s;
vector<int> v;
int w[n], b[n];
if (s[0] == 'B')
c = 'W';
else
c = 'B';
for (int i = 0; i < n - 1; i++) {
if (s[i] != c) {
s[i] = c;
if (s[i + 1] == 'B')
s[i + 1] = 'W';
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=input()
s_=[]
for i in s:
if i=="W":
s_.append(1)
else:
s_.append(0)
if len(set(s_))==1:
print(0)
exit()
A=[]
for i in range(n-1):
if s_[i]:
A.append(i+1)
s_[i]^=1
s_[i+1]^=1
if len(set(s_))==1:
print(len(A))
for i in A:
print(i,end=' ')
else:
if len(s_)%2!=0:
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 203;
int n;
char s[N];
char t[N];
vector<int> ans;
void print() {
printf("%d\n", (int)ans.size());
for (int i = 0; i < (int)ans.size(); i++) {
printf("%d%c", ans[i] + 1, " \n"[i + 1 == (int)ans.size()]);
}
exit(0);
}
void solv... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | mod=10**9+7
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**27)
#import sys
#sys.setrecursionlimit(10**6)
#fact=[1]
#for i in range(1,1000001):
# fact.append((fact[-1]*i)%mod)
#ifact=[0]*1000001
#ifact[1000000]=pow(fact[100... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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
#入力受け取り
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N = int(input())
S = list(input())
B = 0
W = 0
for i in range(N):
if S[i] == "B":
B += 1
else:
W += 1
if B % 2 == 1 and W % 2 == 1:
print(-1)
return
if B % 2 == 0:
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = input()
moves = []
b=w=0
for char in s:
if char == 'B':
b+=1
else:
w+=1
if b&1:
s = [ False if s[i]=='W' else True for i in range(n)]
else:
s = [ True if s[i]=='W' else False for i in range(n)]
for i in range(n-1):
if s[i] :
continue
else:
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... | '''input
3 2
192
'''
# A coding delight
from sys import stdin
def counter(c):
if c == 'B':
return 'W'
return 'B'
# main starts
n = int(stdin.readline().strip())
string = list(stdin.readline().strip())
temp = string[:]
# changing to B
ans = []
for i in range(n - 1):
if string[i] == 'B':
pa... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<bool> cub(n);
char c;
for (int i = 0; i < n; i++) {
cin >> c;
if (c == 'W')
cub[i] = 1;
else
cub[i] = 0;
}
vector<int> ans;
for (int i = 0; i < n - 1; i++) {
if (cub[i]) {
cub[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... | import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
public class realfast implements Runnable {
private static final int INF = (int) 1e9;
public void solve() throws IOException
{
int n = r... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
public class C {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
InputReader s = new Inpu... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long ll_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
const long long MAX = 2000000;
void disp(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... | from sys import stdin
input = stdin.readline
def mp():return map(int,input().split())
def it():return int(input())
n=it()
s=list(input())
s=s[:n]
k=s.copy()
v=[]
for i in range(n-1):
# print(s[i])
if s[i]=='B' and s[i+1]=='W':
s[i],s[i+1]=s[i+1],s[i]
v.append(i+1)
elif s[i]=='W':
pass
elif s[i]=='B' and s[i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | a=int(input())
b=input()
l=len(b)
lw=b.count('W')
lb=b.count('B')
b=[i for i in b]
if lw%2==0:
ans=0
arr=[]
for i in range(l-1):
if b[i]=='W':
b[i]='B'
if b[i+1]=='W':
b[i+1]='B'
else:
b[i+1]='W'
ans+=1
arr.a... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.text.*;
import java.io.*;
public final class Solve {
static PrintWriter out = new PrintWriter(System.out);
static void flush() {
out.flush();
}
static void run(long s, long e) {
NumberFormat formatter = ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'W')
cnt1++;
else
cnt2++;
}
if (cnt1 % 2 == 1 && cnt2 % 2 == 1) {
cout << -1;
return;
}
if (cnt1 & 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... | length = int(input())
x = input()
tot = 0
in_binary = []
for i in range(length):
if x[i] == 'B':
tot += 1
to_change = []
x = [x[i] for i in range(length)]
if (length-tot) % 2 == 0:
for i in range(length-1):
if x[i] == 'W':
to_change.append(i+1)
if x[i+1] == 'W':
x[i+1] = 'B'
else:
x[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;
cin >> s;
vector<int> posz;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'W' && i + 1 < s.size()) {
s[i] = 'B';
if (s[i + 1] == 'B')
s[i + 1] = 'W';
else
s[i + 1] = 'B';
posz... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 final class Blocks{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
char[] s = sc.next().toCharArray();
ArrayList<Integer> l = new ArrayList<>();
int count = 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 gcd(long long a, long long b) {
for (; b; a %= b, swap(a, b))
;
return a;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
string s;
cin >> n >> s;
int w = 0, b = 0;
for (int i = 0; i < n; i++) {
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... | n=int(input())
s=list(reversed(input()))
s1=s[::-1]
s2=s[::-1]
ans=[]
for i in range(n-1):
if s1[i]=='W':
ans.append(i+1)
if s1[i+1]=='W':
s1[i+1]='B'
else:
s1[i+1]='W'
if s1[n-1]=='B':
print(len(ans))
print(*ans,sep=' ')
else:
ans=[]
for i in range(n-... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = list(input())
if n % 2 == 1:
t = 'W' if s.count('W') % 2 == 1 else 'B'
o = 'B' if t == 'W' else 'W'
# print (s, t * n)
c = 0
array = []
for i in range(n - 1):
if s[i] == o and s[i + 1] == o:
s[i] = t
s[i + 1] = t
c += 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.util.*;
import java.lang.*;
public class Blocks{
public static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public FastRea... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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=input().strip()
s=list(s)
a=s.count('W')
b=s.count("B")
for i in range(n):
if s[i]=='W':
s[i]=0
else:
s[i]=1
if a&1 and b&1:
print(-1)
exit()
if a%2==0:
#all white
ans=[]
for i in range(n-1):
if s[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... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, w, b;
cin >> s;
w = s;
b = s;
std::vector<int> v1, v2;
for (int i = 0; i < n - 1; ++i) {
if (w[i] == 'B') {
v1.push_back(i + 1);
w[i] = 'W';
if (w[i + 1] == 'W') {
w[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... | n = int(input())
inp = list(input())
res = []
res1 = []
subans = []
ind = 0
changes = True
while changes:
changes = False
ind = 0
while ind < n - 2:
if inp[ind] == 'B' and inp[ind + 1] == 'W' and inp[ind + 2] == 'B':
inp[ind] = 'W'
inp[ind + 1] = 'W'
inp[ind + 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.util.ArrayList;
import java.util.Scanner;
public final class Blocks {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
String str=sc.nextLine();
StringBuilder ans=new StringBuilder(str);
int w=... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = list(input())
sB = 0
sW = 0
for i in range(len(s)):
if s[i] == 'W':
sW += 1
else:
sB += 1
if sW % 2 == 1 and sB % 2 == 1:
print(-1)
exit()
if (sW % 2 == 1 and sB % 2 == 0)or(sW % 2 == 0 and sB % 2 == 0 and sB < sW) :
for i in range(len(s)):
if s[i] == 'W... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
using namespace std;
int s[211];
int m[211];
int bb[211];
int n;
int t[211];
int main() {
cin >> n;
string a;
cin >> a;
for (int i = 0; i < n; i++) {
if (a[i] == 'W') {
s[i + 1] = 1;
t[i + 1] = 1;
}
}
int sumss = 0;
for (int i = 1; i < n - ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
public class _1271B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
int b = 0, w = 0;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
string = input()
s = list(string)
ans1 = []
ans2 = []
i = 0
count = 0
while i < n-1:
if s[i] == 'B' and s[i+1] == 'B':
i+=2
elif s[i] == 'B' and s[i+1] == 'W':
i+=1
elif s[i] == 'W' and s[i+1] == 'B':
s[i],s[i+1] = s[i+1],s[i]
count+=1
ans1.append(i+1)
i+=1
else:
s[i],s[i+... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
t = list(input())
r = []
f = False
m = [0 if i == 'W' else 1 for i in t]
# print(m)
for i in range(1, len(m) - 1):
if m[i] != m[i - 1]:
r.append(i + 1)
m[i] ^= 1
m[i + 1] ^= 1
# print(m)
if sum(m) == n or sum(m) == 0:
# print('YES')
f = True
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.*;
import java.util.*;
public class P608B {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
char[] blocks = br.readLine().toCharArray();
int su... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = list(input().strip())
b = 0
w = 0
for i in range(n):
if s[i]=="B":
b+=1
else:
w+=1
op = []
if b%2==1 and w%2==1:
print(-1)
elif b==0 or w==0:
print(0)
else:
if b%2==0 and w%2==0:
if b<w:
for i in range(n-1):
if s[i]<s[i+1]:
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
def paint(blocks,num,colour,idx,changelist):
if(idx==num-1):
if(blocks[idx]==colour):
return True
else:
return False
if(blocks[idx]==colour):
return paint(blocks,num,colour,idx+1,changelist)
else:
blocks[idx] = colour
if(blocks[idx+1]=="B"):... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
Reader scan = new Reader();
scan.init(System.in);
OutputStream output = System.out;
PrintWriter out = new PrintWriter(output);
int N = scan.nextInt();
S... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Vector;
public class ProblemB {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
char[] c = s.toC... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.uti... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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())
s1=list(input())
s2=s1
ans1=ans2=[]
for i in range(n-1):
if s1[i]=='B':
s1[i]='W'
if s1[i+1]=='B':
s1[i+1]='W'
else:
s1[i+1]='B'
ans1.append(i+1)
if s1[n-1]=='W':
print(len(ans1))
if len(ans1)>0:
print(*ans1)
else:
for i in r... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
bool res, res2 = false;
char swapc(char a) {
if (a == 'W')
return 'B';
else
return 'W';
}
void solution(string s, char d, vector<int> &a) {
int cnt = 0;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] != d) {
s[i] = swapc(s[i]);
s[i + 1] = ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=input()
l=list(s)
s=list(s)
for i in range(n):
if s[i]=='W':
s[i]=1
l[i]=1
else:
s[i]=0
l[i]=0
f=1
p=[]
c=0
for i in range(n-1):
if s[i]==1:
continue
else:
p.append(i+1)
s[i]=1-s[i]
s[i+1]=1-s[i+1]
c+=1
#print(s... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
public class Blocks
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
int t=1;
while(t-->0)
{
int n=Integer.parseInt(br.readLine().tr... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1000;
int n;
int path[N];
vector<int> v;
char s[N];
int tot;
int main() {
cin >> n;
cin >> (s + 1);
for (int i = 1; i < n; i++) {
if (s[i] == 'B') {
s[i] = 'W';
if (s[i + 1] == 'W')
s[i + 1] = 'B';
else
s[i + 1... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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, count = 0, flag = 0, i, j, sum = 0;
cin >> n;
int arr[n], k = 0;
char str[n + 1];
cin >> str;
str[n] = '\0';
for (i = 0; i < n; i++) {
if (str[i] == 'B') {
count++;
}
}
if (count % 2 != 0) {
if (n % 2 == 0)
cout ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | 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)
# any of them is odd
elif b & 1 == 1 and w & 1 == 1:
print(-1)
exit(0)
c_to = None
other = None
if b & 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())
def inv(si):
if si == "W":
return "B"
else:
return "W"
fs = []
i = 0
while i < n-2:
b = s[i]
s1 = s[i+1]
s2 = s[i+2]
if b == s1 and s1 == s2:
i+=2
elif b == s1:
i+=1
elif b != s1:
s[i+1] = inv(s[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... | n = int(input())
arr = list(input().strip())
def foo(arr, c1, c2):
global n
c = 0
st = []
for i in range(n-1):
if arr[i] == c1:
continue
else:
arr[i] = c1
arr[i+1] = c1 if arr[i+1] == c2 else c2
c += 1
st.append(i+1)
if arr[-1] == c2:
return(-1, -1)
else:
return(c, ' '.join(map(str, 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... | import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader st = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(st.readLine());
String str = st.readLine();
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... | amount = int(input())
line = list(input())
if line.count('W') % 2 == 1 and line.count('B') % 2 == 1:
print(-1)
elif line.count('B') % 2 == 0:
ans = []
for i in range(amount - 1):
if line[i] == 'B' and line[i + 1] == 'B':
ans.append(i + 1)
line[i] = 'W'
line[i + 1]... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=input()
d = {'B':[], 'W':[]}
for i, e in enumerate(s):
d[e].append(i)
lb, lw = len(d['B']),len(d['W'])
b,c=lb%2!=0,lw%2!=0
if b and c:
print(-1)
elif (lb and not lw) or (lw and not lb): ## all same
print(0)
else:
#print(d)
if not b:
B=d['B']
pos = []
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 countWhite(s):
i=0
for elem in s:
if elem == "W":
i+=1
return i
def countBlack(s):
i=0
for elem in s:
if elem == "B":
i+=1
return i
def stringToList(s):
list=[]
for elem in s:
list.append(elem)
return list
def listToString(l):
string=""
for elem in l:
string += "%s " %(elem)
return str... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
const int maxx = 210;
char s[maxx];
int ans[maxx];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s + 1);
int t = 0;
for (int i = 1; i < n; i++) {
if (s[i] == 'W') {
s[i] = 'B';
if (s[i + 1] == 'W')
s[i + 1] = 'B';
else
s[i ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=input()
a=list(s)
if (a.count("B")%2)*(a.count("W")%2):print(-1);exit()
b=[]
if a.count("B")%2:m="W"
else:m="B"
for i in range(n-1):
if a[i]==m:
b.append(i+1)
if a[i]=="W":a[i]="B"
else:a[i]="W"
if a[i+1]=="W":a[i+1]="B"
else:a[i+1]="W"
print(len(b))
if len(b):print(*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 sys import stdin
# noinspection PyShadowingBuiltins
input = lambda: stdin.readline().rstrip("\r\n")
input_a = lambda fun: map(fun, stdin.readline().split())
def read():
n = int(input())
s = input()
return n, s
def solve(n, s: str):
s = [True if x == 'B' else False for x in s]
b, w = s.coun... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
public class Main {
public static void main(final String[] args) {
final Scanner scanner = new Scanner(System.in);
final int n = scanner.nextInt();
final String input = scanner.next();
final int[] array1 = new int[n];
final int[] array2 = new int[n];
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... | #include <bits/stdc++.h>
bool notsame(char* c, int len) {
bool a = false;
for (int i = 0; i < len - 1; ++i) {
if (c[i] != c[i + 1]) a = true;
}
return a;
}
bool notpresent(int* nums, int ele, int idx) {
bool a = true;
for (int i = 0; i < idx; i++) {
if (nums[i] == ele) a = false;
}
return a;
}
i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
import java.util.*;
public class codeforce {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
char []a=scan.next().toCharArray();
int i;
int w=0;
int b=0;
for(i=0;i<n;i++)
{
if(a[i]=='W')
w++;
else if(a[i]=='B')
b++;
}
ArrayList<Integer>l=new ArrayL... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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())
t = s.copy()
ans1 = []
ans2 = []
for i in range(n-1):
if s[i] == 'W':
if s[i + 1] == 'B':
s[i + 1] = 'W'
else:
s[i + 1] = 'B'
ans1.append(i + 1)
if t[i] == 'B':
if t[i + 1] == 'B':
t[i + 1] = 'W'
else:... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
l = list(input())
f = 0
for i in range(n):
if l[i]=='B':
l[i] = 0
else:
l[i] = 1
l1 = l[:]
if f == 0:
ans = []
for i in range(n-1):
if l[i]==1:
l[i] = abs(1-l[i])
l[i+1] = abs(1-l[i+1])
ans.append(i+1)
if len(set(l))==1:... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import math
def main():
n = int(input())
s = str(input())
b = 0
w = 0
p = []
for i in range(n):
if s[i] == 'B':
p.append(1)
b += 1
else:
p.append(0)
w += 1
steps = -1
op = []
if b % 2 == 0:
steps = 0
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... | def func(ss,l,c):
if c=="W":c1="B"
else:c1="W"
for i in range(n-1):
if ss[i]==c:ss[i]=c1;ss[i+1]=c if ss[i+1]==c1 else c1;l.append(i+1)
if len(set(ss))==1:return l
else:return []
n,s=int(input()),list(input())
ans,ans1=func(list(s),[],"B"),func(list(s),[],"W")
if len(set(s))==1:print(0)
elif... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = list(input())
def solve(n,w):
b = w.copy()
sw, sb = [], []
for i in range(n-1):
if w[i]=='B':
sw.append(i+1)
w[i+1] = 'W' if(w[i+1]=='B') else 'B'
if b[i]=='W':
sb.append(i+1)
b[i+1] = 'W' if(b[i+1]=='B') else 'B'
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import time
def st(it):
return [str(ita) for ita in it]
LOCAL = False
start_time = None
if __name__ == '__main__':
if LOCAL:
start_time = time.time()
# n = int(input())
# a = list(map(lambda x: int(x), input().split(' ')))
n = int(input())
a = list(map(lambda x: 1 if x == 'B' els... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
long long t, n;
string s;
long long max(long long a, long long b, long long c) {
return max(a, max(b, c));
}
long long min(long long a, long long b, long long c) {
return min(a, min(b, c));
}
long long fspow(long long x, long long y) {
long long ans;
if (y == 0) ret... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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> v;
int n;
cin >> n;
string s;
cin >> s;
int ara[n];
for (int i = 0; i < n; i++) {
if (s[i] == 'W')
ara[i] = 1;
else
ara[i] = 0;
}
for (int i = 1; (i + 1) < n; i++) {
if (ara[i] != ara[i - 1]) {
ara[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 long long MAX_N = 2e5 + 5, inf = 1e18, mod = (int)1e9 + 7;
const double PI = 3.1415926536;
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool is_prime(long long n) {
for (long long i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return fa... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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
elem = int(input())
st = list(input())
st2 = st.copy()
ch = 0
ar = []
for x in range(len(st)):
if st[x] == 'B':
continue
if x == len(st)-1:
ch = 1
break
st[x] = 'W'
if st[x+1]=='W':
st[x+1]='B'
else:
st[x+1]='W'
ar.append(x+1)
if ch == 0:
p... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
String s = sc.next();
char a[] = s.toCharArray();
int m[] = new int[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... | # -*- coding: utf-8 -*-
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
A = [1 if x=='W' else 0 for x in list(input())]
R = []
if n==2:
if A[1]==A[0]:
print(0)
else:
print(-1)
else:
# print(A)
B= [not x for x in A]
if A[0] == 0:
A[0] = 1
A[1] = not A[1]
R.append(1)
for i in range(1,n):
if i < n-1 and 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;
const long long N = (long long)2e5 + 5;
vector<long long> ans;
string s;
void f(long long x, long long y) {
if (s[x] == 'B') {
s[x] = 'W';
} else {
s[x] = 'B';
}
if (s[y] == 'B') {
s[y] = 'W';
} else {
s[y] = 'B';
}
ans.push_back(x);
}
int32_t ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=input()
a=[]
b=[]
for i in range(n):
a.append(s[i])
b.append(s[i])
c=[]
for i in range(n-1):
if(a[i]=="W"):
continue
else:
a[i]="W"
c.append(i+1)
if(a[i+1]=="W"):
a[i+1]="B"
else:
a[i+1]="W"
if(a.count("W")==n):
pri... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
input()
ans=[]
s=input()
a=[]
for x in s:
if x=='B':
a.append(0)
else:
a.append(1)
import copy
tmp=copy.deepcopy(a)
for i in range(1,len(s)):
if a[i-1]==0:
ans.append(i)
a[i-1]=1
a[i]^=1
if a[i]==1:
print(len(ans))
print(' '.join([str(x) for x in ans]))
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... | a=int(input())
b=input()
if(b.count("B")%2==1 and b.count("W")%2==1):
print(-1)
else:
b=list(b)
if(b.count("B")%2==1):
for i in range(len(b)):
if(b[i]=="B"):
b[i]="W"
else:
b[i]="B"
b=list(b)
# print(b)
ans=[]
for i in range(len(b)-1):
# print(b)
if(b[i]=="B" and b[i+1]=="B"):
ans.append(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... | def find():
if (l[n-1]=='B'):
for i in range(0,n-2,2):
m.append(i+1)
elif (l[0]=='B'):
for i in range(n-2,0,-2):
m.append(i+1)
print(len(m))
for j in range(len(m)):
print(m[j],end=" ")
n=int(input())
s=str(input())
l=list(s)
if ('B' not in s)... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*****************************************************... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 a[n];
for (int i = 0; i < n; i++) {
if (s[i] == 'B')
a[i] = 1;
else
a[i] = 0;
}
vector<int> v;
for (int i = 1; i + 1 < n; i++) {
if (a[i] != a[i - 1]) {
a[i] = !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>
long long int gcdfun(long long int x, long long int y) {
if (y == 0)
return x;
else
return gcdfun(y, x % y);
}
using namespace std;
int power(int x, int y) {
if (y == 0)
return 1;
else if (y % 2 == 0)
return ((power(x, y / 2) % 1000000007) * (power(x, y / 2) % 1000000007... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 = list(raw_input())
tmps = list(s)
ans = []
for i in range(n-1):
if tmps[i] == 'W':
ans.append(i)
tmps[i] = 'B'
if tmps[i+1] == 'W':
tmps[i+1] = 'B'
else:
tmps[i+1] = 'W'
if tmps.count('W') == 0:
print len(ans)
for i in ans:
print i + 1,
else:
tmps = list(s)
ans = []
for i in range(n... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, w = 0, b = 0, i;
cin >> n;
char arr[n];
vector<long long> ans;
for (i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 'W')
w++;
else
b++;
}
if (w % 2 && b % 2) {
cout << "-1" << endl;
return;
} 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;
const int MAXN = 2e2 + 20;
int n;
vector<int> ans;
char s[MAXN], s1[MAXN];
char convert(char a) {
if (a == 'B')
return 'W';
else
return 'B';
}
int main() {
cin >> n;
scanf("%s", s);
for (int i = 0; i < n; ++i) {
s1[i] = s[i];
}
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 sys
from math import ceil
input = sys.stdin.readline
n = int(input())
s = [True if x == 'W' else False for x in input().strip()]
r = s[:]
store = []
for i in range(n-1):
if s[i]:
continue
else:
store.append(i+1)
s[i] = not s[i]
s[i+1] = not s[i+1]
if s[-1]:
print(len(... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
string str;
cin >> str;
vector<int> pos;
for (int k = (1); k <= (2 * n); ++k) {
for (int i = 0; i < (n - 1); ++i) {
if (k == 1) {
if (str[i] == 'W') continue;
str[i] = 'W';
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... | //package codeforces;
import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;
import java.util.Set;
public class q {
static Scanner scn ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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.Arrays;
import java.util.InputMismatchException;
/* * */
public class _608_B implements Runnable{
public static void main(String[] args) {
new Thread(null, new _608_B(),"Main",1<<27).start();
}
@Override
public void run() {
FastReader fd = new FastReader... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 getInv(x):
if x == 'W':
return 'B'
return 'W'
n = int(input())
sir = list(input())
inv = []
for x in sir:
inv.append(getInv(x))
# le fac toate B
ans = []
for i in range(0, len(sir) - 1):
if sir[i] == 'W': # fac mutare pe i
ans.append(i + 1)
sir[i] = getInv(sir[i])
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | # import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
n = int(input())
s = input()
operation = [0]*(3*n)
count = 0
arr = [0]*n
for i in range(n):
if (s[i] == "W"):
arr[i] = 1
else:
arr[i] = 0
# ODD LENGTH CASE
if (n&1==1):
x = arr[0]
for i in range(1,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... | // Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUD... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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())
nw=0
nb=0
for i in s:
if i=='W':
nw+=1
else:
nb+=1
num=0
ans=[]
if nw%2!=0 and nb%2!=0:
print(-1)
else:
if nw%2==0 and nb%2==0:
if nw>nb:
en='W'
else:
en='B'
elif nw%2==0:
en='B'
else:
en='W'
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = list(input())
b = 0
w = 0
T = []
for i in s:
if i == 'B':
b += 1
else:
w += 1
if b % 2 == 1 and w % 2 == 1:
print(-1)
elif b == 0 or w == 0:
print(0)
else:
for i in range(len(s) - 1):
if s[i] == 'B' and s[i + 1] == 'W':
s[i] = 'W'
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writa... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
# Author : raj1307 - Raj Singh
# Date : 17.12.19
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
de... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.