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(int(input()))
s=input()
a1=b1=0
k1=0
l=list(s)
l1=[]
for i in s:
if i=='W':
a1+=1
else:
b1+=1
if a1%2==0:
k1='W'
k2='B'
elif b1%2==0:
k1='B'
k2='W'
if k1==0:
print(-1)
else:
for i in range(n-1):
if l[i]==k1:
l[i]=k2
l1.append(i+1)
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> nums;
int a = 0;
for (int i = (0); i < (n); i++) {
if (s[i] == 'B') a++;
}
if (a & 1 and !(n & 1)) {
cout << -1 << endl;
return 0;
}
if (a & 1) {
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... | x=int(input())
y=input()
c=0
s=[]
lis=y[0]
t=True
for i in range (x-1):
if y[i]=="W":
c+=1
else:
c-=1
if y[i]!=lis and t==True:
s=s+[str(i+1)]
t=False
elif y[i]==lis and t==False:
s=s+[str(i+1)]
t=False
else:
t=True
if y[x-1]=="W" :
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... | from collections import Counter,deque,defaultdict,OrderedDict,namedtuple
from bisect import bisect_left,bisect_right,insort
from math import sqrt,ceil,floor,factorial,gcd
from sys import stdin
a=int(input())
s=input()
c=Counter(s)
if c['B']==0 or c['W']==0:
print(0)
elif c['B']&1 and c['W']&1:
print(-1)
e... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import org.w3c.dom.ls.LSOutput;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
String s = scan.nextLine();
int counterW = 0;
for (int i = 0; i < n; i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class compete608b {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLin... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = input()
w = s.count("W")
b = s.count("B")
r = []
if b%2!=0 and w%2!=0:
exit(print(-1))
elif b%2!=0:
s = [1 if x == "B" else 0 for x in s]
elif w%2!=0:
s = [1 if x =="W" else 0 for x in s]
else:
if w<b:
s = [1 if x == "B" else 0 for x in s]
else:
s = [1 if x == "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... | a=int(input())
b=list(input())
n=0
n1=[]
z=b[:]
while b.count('W')!=a and b.count('B')!=a:
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(e==b):
while b.count('W')!=a and b.count('B')!=a:
e=b[:]
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;
int n;
string s;
vector<int> v[2];
bool f(char c, int ind) {
int last = -1;
for (int i = 1; i <= n; i++) {
if (s[i - 1] == c) {
if (last == -1) {
last = i;
v[ind].push_back(i);
} else {
last = -1;
}
} else if (last != -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()
x=raw_input()
cb=0
cw=0
for i in x:
if i=='W':
cw+=1
else:
cb+=1
a=[i for i in x]
if cw%2!=0 and cb%2!=0:
print -1
else:
c=0
arr=[]
if cw%2!=0:
for i in range(n-1):
if a[i]=='B':
c+=1
if a[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... | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
/*
HashMap<> map=new HashMap<>();
TreeMap<> map=new TreeMap<>();
map.put(p,map.getOrDefault(p,0)+1);
for(Map.Entry<> mx:map.entrySet()){
int v=mx.getValue(),k=mx.getKey();
}for (int i = 1; i <= 1000; 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 = str(input())
b = []
rz = []
for i in range(n):
if s[i] == 'W':
b += [0]
else:
b += [1]
for i in range(n - 2):
if b[i] != b[i + 1]:
b[i + 1] = (b[i + 1] + 1) % 2
b[i + 2] = (b[i + 2] + 1) % 2
rz += [i + 1]
if b[n - 1] != b[n - 2]:
if n % 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>
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long MOD1 = 998244353;
using namespace std;
long long power(unsigned long long x, unsigned long long y) {
unsigned long long res = 1;
while (y > 0) {
if (y & 1) res = (unsigned long long)(res * x);
y = y >> 1;
if (x <= 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 sys import stdin
from collections import deque
mod = 10**9 + 7
# def rl():
# return [int(w) for w in stdin.readline().split()]
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt,factorial,gcd,log2,inf,ceil
# map(int,input().split())
# # l = ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int64_t n;
string s;
cin >> n >> s;
vector<int64_t> ans, ans2;
string s2 = s;
bool ok = false, ok2 = false;
map<char, char> m = {{'B', 'W'}, {'W', 'B'}};
for (int64_t 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... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main {
static void solve() {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String s = scan.next();
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... | // javac b.java && java _
import java.io.*;
import java.util.*;
public class b {
public static void main(String[] args) { new b(); }
FS in = new FS();
PrintWriter out = new PrintWriter(System.out);
int n, pdn, pdb;
char[] bloc;
b() {
n = in.nextInt();
bloc = in.next().toCharArray();
pdn = (n & 1);
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | def main():
n = int(input())
s = list(input())
ans = []
for i in range(1, n):
if s[i-1] == 'W':
ans.append(i)
s[i-1] = 'B' if s[i-1] == 'W' else 'W'
s[i] = 'B' if s[i] == 'W' else 'W'
if 'W' in s:
for i in range(1, n):
if s[i-1] == '... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int cnt[2] = {0};
for (auto &v : s) {
if (v == 'B')
cnt[0]++;
else
cnt[1]++;
}
if (cnt[0] % 2 && cnt[1] % 2) {
cout << -1 << '\n';
}... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* @author Rohini Chandra
*/
import java.util.*;
import java.io.*;
public class rough{
public static void main(String args[]) ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import sys
import collections
from collections import Counter
import itertools
import math
import timeit
#input = sys.stdin.readline
#########################
# imgur.com/Pkt7iIf.png #
#########################
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p *... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
long long int xpow(long long int a, long long int b) {
if (b == 0) return 1;
if (b % 2 == 0) {
long long int k = xpow(a, b / 2);
return k * k;
}
if (b % 2 != 0) return a * xpow(a, b - 1);
}
void display(vector<int> v) {
for (auto k : v) cout << 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... | x=int(input())
y=input()
c=0
s=[]
q=y[0]
t=True
for i in range (x-1):
if y[i]=="W":
c+=1
else:
c-=1
if y[i]!=q and t==True:
s=s+[str(i+1)]
t=False
elif y[i]==q and t==False:
s=s+[str(i+1)]
t=False
else:
t=True
if y[x-1]=="W" :
c+=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... | n = int(input())
s = input()
z = [i for i in s]
if len(set(z)) == 1:
print(0)
exit()
ans = []
i = 0
while i < n-1:
if z[i] == 'B':
i+=1
else:
if z[i+1] == 'W':
z[i] = 'B'
z[i+1] = 'B'
ans.append(i+1)
i+=2
else:
z[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... | """609C"""
# import math
# import sys
def main():
# n ,m= map(int,input().split())
# a = list(map(int,input().split()))
n = int(input())
string = str(input())
list1 = list(string)
list2 = list(string)
# flag = True
arr = []
for i in range(n-1):
if list1[i]=='B':
list1[i]='W'
arr.append(i+1)
if list1... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | z = int(input())
a = list(input())
l = []
for i in range(z-1):
if a[i]=="B":
if a[i+1]=="B":
a[i]=a[i+1]="W"
else:
a[i]="W"
a[i+1]="B"
l.append(i+1)
if len(set(a))==2:
for i in range(z - 1):
if a[i] == "W":
if a[i + 1] == "W":
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Cf131 implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private 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... | #include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
const int inf = (int)1e9 + 99999, mod = (int)1e9 + 7;
const long long linf = (long long)2e18 + 99999;
int kob(int x, int y) { return ((long long)x * 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... | # n, m, r = (int(x) for x in input().split())
# buy = min(int(x) for x in input().split())
# sell = max(int(x) for x in input().split())
# if sell <= buy:
# print(r)
# else:
# shares_nr = r // buy
# print(shares_nr * (sell - buy) + r)
def solvea():
ties_nr = int(input())
scarfs_nr = int(input())
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*;
public class Main {
static char[] change(char[] c, int i) {... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | fast=lambda:stdin.readline().strip()
zzz=lambda:[int(i) for i in fast().split()]
z,zz=input,lambda:list(map(int,z().split()))
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *
from 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;
using namespace std::chrono;
char change(char c) {
if (c == 'B')
return 'W';
else
return 'B';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
string s;
cin >> s;
vector<long long> op;
for (long lo... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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())
cubs = input()
if cubs.count('W') % 2 + cubs.count('B') % 2 != n % 2:
print(-1)
else:
count, s = 0, []
cubs = list(cubs)
for i in range(n - 1):
if cubs[i] == 'W':
cubs[i] = 'B'
if cubs[i + 1] == 'W':
cubs[i + 1] = 'B'
else:
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
string s, t;
cin >> n >> t;
s = t;
long long f = 1;
std::vector<long long> v;
for (long long i = 0; i < n - 1; i++) {
if (s[i] == 'B')
continue;
else {
v.push_back(i + 1);
if (s[i + 1] == 'B')
s[i +... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
import java.io.BufferedReader;
import java.io.Console;
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;
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 i, j, k, l, n, m, flag = 0;
string s, ss;
vector<long long> res;
long long a[1000009], b[1000009];
void check(long long num) {
res.clear();
for (i = 2; i <= n; i++) {
if (a[i - 1] != num) {
a[i - 1] ^= 1;
a[i] ^= 1;
res.push_back(i - 1);
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int n = nextInt();
int a[] = new int[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... | from collections import deque
n=int(input())
s=input()
d=deque()
if((n&1)==0):
w=0
b=0
for j,i in enumerate(s):
if i=='W':
d.append(j)
w+=1
else:
b+=1
if(w&1)==0 and (b&1)==0:
c=0
ans=[]
while(len(d)!=0):
c+=1
t=d.popleft()
if s[t+1]=='W':
d.popleft()
else:
d.appendleft(t+1)
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | t = int(input())
s = input();w =s.count('W');b=s.count('B')
if w % 2 == 1 and b % 2 == 1:print(-1);exit()
else:
c = 0
p = 0
ans =[]
x = 'W' if w % 2 ==0 else 'B'
for i in range(t):
if s[i]==x and p == 0 or s[i]!=x and p==1:
p = 1
c+=1
ans.append(i+1)
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
string str2;
str2 = str;
int ans = 0;
vector<int> a;
int ans2 = 0;
vector<int> a2;
for (int i = 0; i < n - 1; i++) {
if (str[i] == 'B') {
ans++;
a.push_back(i + 1);
str[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 java.util.ArrayList;
import java.util.Scanner;
public class B608 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner obj=new Scanner(System.in);
int n=obj.nextInt();
char[] ch=obj.next().toCharArray();
int k=0,m=0;
ArrayList<Integer> arr=new ArrayList<>();
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... | n=int(input())
s1=str(input())
x1=s1.count('W')
x2=s1.count('B')
if(x1==0 or x2==0):
print(0)
elif(x1%2!=0 and x2%2!=0):
print(-1)
else:
k=0
l=[]
s=list(s1)
if(True):
i=0
if(x1%2!=0):
ch='W'
else:
ch='B'
if(True):
while(i<n-1):
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int c = 0;
vector<int> a;
for (int i = 0; i < n - 1; i++) {
if (s.at(i) != 'W') {
s.at(i) = 'W';
a.push_back(i + 1);
c++;
if (s.at(i + 1) == 'W') {
s.at(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())
a=input()
w=a.count('W')
b=n-w
if w%2==1 and b%2==1:
print(-1)
else:
x='W' if w%2==0 else 'B'
c=0
p=0
ans=[]
for i in range(n):
if (a[i]==x and p==0) or (a[i]!=x and p==1):
c+=1
p=1
ans.append(i+1)
else:
p=0
print... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | k = int(input())
s = input()
if s.count('W') == k or s.count('B') == k:
print(0)
elif s.count('W') % 2 == 1 and s.count('B') % 2 == 1:
print(-1)
else:
ans1 = 9999999999999
l1 = []
if s.count('W') % 2 == 0:
t = 0
s1 = list(s)
if s[0] == 'W':
prev = 1
else:
prev = -1
for i in range(1, k):
if prev ... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | '''input
3
BWB
'''
import sys
debug = 1
readln = sys.stdin.readline
#sys.setrecursionlimit(1000000)
def write(s):
sys.stdout.write(str(s))
def writeln(s):
sys.stdout.write(str(s))
sys.stdout.write('\n')
def readint():
return int(readln().strip())
def readints():
return map(int, readln().split()... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | number = int(input())
words = input()
word = []
for i in range(0,number):
if(words[i]=='B'):
word.append(0)
elif(words[i]=='W'):
word.append(1)
arr = []
kim = word[0]
for i in range(1,number-1):
if(word[i]!=kim):
word[i]=1-word[i]
word[i+1]=1-word[i+1]
arr.append(i+1)... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = input()
Num_B = s.count('B')
Num_W = s.count('W')
Num_index = []
test = 0
if Num_B % 2 == 1 and Num_W % 2 == 1:
print(-1)
test = -1
elif Num_B % 2 == 0 and Num_W % 2 == 0:
if Num_B >= Num_W:
for x in range(len(s)):
if s[x] == 'W':
Num_index.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;
signed main() {
long long n;
cin >> n;
long long flag = 0;
string str;
cin >> str;
string s = str;
vector<long long> vec;
for (long long i = 0; i < n - 1; i++) {
if (s[i] == 'B') {
s[i] = 'W';
if (s[i + 1] == 'W')
s[i + 1] = 'B';
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.*;
import java.util.*;
public class Question2 {
public static void solve(List<Character> s, int n) {
List<Integer> ret = new ArrayList<>();
List<Character> s1 = new ArrayList<>(s);
for(int i=0; i<n-1; i++) {
if (s1.get(i) == 'W') {
s1.set(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 java.util.*;
public class KosyaReshaetZadachi {
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String str = scan.next();
int[] arr = new int[n];
int Bcount = 0;
int Wcount = 0;
for(int 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() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
string second;
cin >> n >> second;
string t = second;
bool ok = 1;
vector<int> vec;
for (int i = 0; i < n; i++) {
if (second[i] == 'W') continue;
if (i + 1 < n && second[i + 1]... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import sys
N = int(input())
s = [x == 'W' for x in input()]
ans = []
flip = False
for i in range(N-1):
if not s[i]:
ans.append(i+1)
s[i] = not s[i]
s[i+1] = not s[i+1]
if not s[-1]:
if N % 2 == 0:
print(-1)
sys.exit(0)
for i in range(0, N-1, 2):
ans.append(i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Problem1271B {
public static void main(String[] args) {
Problem1271B instance = new Problem1271B();
BufferedReader bfr = null;
try {
bfr = new Buffered... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
import java.math.*;
public class B608{
public static void main(String args[]){
FastReader sc = new FastReader();
int n,i;
n=sc.nextInt();
char s[]=sc.next().toCharArray();
int b=0,w=0;
for(i=0;i<n;i++){
if(s[i]=='B')
b++;
else
w++;
}
if(b==0||w==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.*;
public class Main {
static FastReader f = new FastReader();
public static void main(String[] args) {
int n = f.nextInt();
char[] s = f.next().toCharArray();
int b = 0;
for(int i=0;i<n;i++) {
if(s[i] == 'B') {
b+... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, w = 0, b = 0;
cin >> n;
string s;
cin >> s;
queue<long long> q;
for (long long i = 0; i < n; i++) {
if (s[i] == 'W')
w++;
else
b++;
}
if (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;
const int N = (int)3e5 + 5;
const int mod = (int)1e9 + 7;
int n, b, w;
char a[300];
vector<int> v;
inline void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 'B')
b++;
else
w++;
}
if (b == 0 || w == 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())
num = list(input())
tnum = num.copy()
ans = 0
anss = []
for i in range(n-1):
if (tnum[i] == 'W'):
tnum[i] = 'B'
if (tnum[i+1] == 'B'):
tnum[i+1] = 'W'
else:
tnum[i+1] = 'B'
ans += 1
anss.append(i+1)
if (tnum[n-1] == 'B'):
print(ans... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import javafx.util.Pair;
public class CodeChef {
public static boolean inside(int a, ArrayList<Pair<Integer, Integer>> pairs) {
for (int i = 0; i < pairs.size(); i++) {
if (a >= pairs.get(i).getKey() && a <= 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;
long double pi = 3.14159265358979323846;
vector<long long> al[500005];
long long vis[500005], color[500005], I[101][101];
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
bool isPrime(int n) {
if (n <= 1) return false;
if (n <=... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Solution implements Runnable
{
public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}
public void run()
{
InputReader i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
#q = int(input())
#x, y = map(int,input().split(' '))
#print (' '.join(list(map(str, s))))
n = int(input())
s = list(input())
cnt = 0
lst = []
for i in range(1,n-1):
if s[i] != s[i-1]:
cnt = cnt + 1
lst.append(i+1)
if s[i] == 'W':
s[i] = 'B'
else:
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 java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;
public class Main {
static class Pair
{
int x;
int y;
public Pair(int x, int y)
{
this.x=x;
this.y=y;
}
}
static class Comp implements Comparator<Pair>
{
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.io.*;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | def flip(x):
if x == 'B':
return 'W'
return 'B'
def B():
input()
S = input()
for ocz in 'BW':
cop = [x for x in S]
uz = 0
roz = []
for i in range(len(cop) - 1):
if cop[i] != ocz:
uz += 1
roz.append(i+1)
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<int> v;
string s;
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
if (s[i] == 'B') {
s[i] = 'W';
if (s[i + 1] == 'B')
s[i + 1] = 'W';
else
s[i + 1] = 'B';
v.push_back(i + 1);
}
}
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... | n = int(input())
c = list(input())
a = c.count('W')
b = n - a
if a%2 == 0: f = 'B'
elif b%2 == 0: f = 'W'
else: f = -1
if f == -1:
print(-1)
else:
m = []
for i in range(n-1):
if c[i] != f:
c[i] = 'W' if c[i] == 'B' else 'B'
c[i+1] = 'W' if c[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... | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long int> v[3];
long long int n, i, r = 0;
cin >> n;
string s, ss;
cin >> s;
char rev = ('B' ^ 'W');
ss = s;
for (i = 0; i < n - 1; ++i) {
if (s[i] == 'B') {
v[1].push_back(i);
s[i] = 'W';
s[i + 1] = rev ^ 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;
using ll = long long;
using pii = pair<long long, long long>;
template <class T>
void cmax(T& x, T y) {
(x < y) && (x = y);
}
template <class T>
void cmin(T& x, T y) {
(x > y) && (x = y);
}
string s;
long long n, b;
vector<long long> ans;
signed main() {
ios ::sync_wi... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i;
cin >> n;
string s;
cin >> s;
long long int c = 0;
vector<long long int> ans;
string s1 = s;
for (i = 0; i < n - 1; i++) {
if (s1[i] != 'W') {
s1[i] = 'W';
if (s1[i + 1] == 'W') {
s1[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... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[])
{
FastReader input=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int T=1;
while(T-->0)
{
int n=input.nextInt();
String s=input.next();... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class tr0 {
static PrintWriter out;
static StringBuilder sb;
static final double EPS = 1e-9;
static long mod = (int) 998244353;
static int inf = (int) 1e9 + 2;
static long[] fac;
static int[] a;
static int[] si;
static ArrayList<Integer... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
import java.io.BufferedReader;
import java.io.Console;
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;
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
import java.lang.Math.*;
public class KickStart2020{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
//When I wrote this code, only God & I understood what it did. Now only God knows !!
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
static class FastReader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;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... | n, s, b, w = int(input()), list(input()), 0, 0
for c in s:
if c == 'B':
b += 1
else:
w += 1
if w % 2 and b % 2:
print(-1)
else:
if w % 2 == 0 and b % 2 == 0:
c = 'B' if b < w else 'W'
else:
c = 'B' if b % 2 else 'W'
a = []
for i in range(n - 1):
if s[i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | def sol():
n = int(input())
s = list(input())
b = s.count('B')
w = s.count('W')
if w % 2 == 1 and b % 2 == 1:
print(-1)
return
ans = []
s = list(s)
if w % 2 == 1:
odd = 'W'
even = 'B'
else:
odd = 'B'
even = 'W'
for i in range(n-1):
if s[i] != odd:
ans.append(i + 1)
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = list(input())
prev=s[0]
i=1
ans=[]
while i<n and s[i]==prev:
i+=1
j=i
while i<n-1:
if s[i]==prev:
i+=1
continue
else:
ans.append(i+1)
if s[i]!=s[i+1]:
s[i],s[i+1]=s[i+1],s[i]
i+=1
else:
s[i]=s[i+1]=prev
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
import java.io.*;
import java.lang.*;
public class Codeforces{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
PrintWriter out =new PrintWriter(System.out);
StringTokenizer st =new StringTokenizer("");
String next(){
if(!st.hasMoreTokens()){
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 valid(int x, int n) { return 0 <= x && x < n; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
template <typename T>
inline T pop(queue<T>& q) {
T front = q.front();
q.pop();
return front;
}
template <typename T>
inline T gcd(T a, T b) {
for (; b; 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())
a = [0 if c=='W' else 1 for c in input()]
if a.count(0) == 0 or a.count(1) == 0:
print(0)
exit()
t = 0
if a.count(1) % 2 == 0:
t = 1
ans = []
for i in range(n-1):
if a[i] == t:
ans.append(i+1)
a[i] ^= 1
a[i+1] ^= 1
if a.count(t) > 0:
print(-1)
else:
pr... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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 = 5e6 + 5;
char a[205];
const int mod = 1e9 + 7;
vector<int> ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
cin >> (a + 1);
int cnt = 0;
for (int i = 1; i <= n; i++)
if (a[i] == 'B') cnt++;
if (cnt % 2 == 1 && (n - cn... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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()
t1, t2 = s.count('B'), s.count('W')
a = list(s)
if t1 % 2 == 1 and t2 % 2 == 1:
print(-1)
else:
count, result = 0, list()
b = "#"
b = "W" if t2 % 2 == 0 else 'B'
for i in range(n - 1):
if a[i] == b:
count += 1
a[i + 1] = 'B' if a[i + 1] ==... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
vector<long long> divisor(long long n) {
vector<long long> v;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i)
v.push_back(i);
else {
v.push_back(i);
v.push_back(n / i);
}
}
}
return v;
}
bool i... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
s = input()
w=s.count("W")
b = n-w
s=list(s)
x=0
if b==0 or w==0:
print(0)
elif w%2==1 and w%2 == b%2:
print(-1)
else:
t=s[0]
an=[]
i=0
while i<n-1:
p = s[i]+s[i+1]
if p[0]==p[1] and p[0]!=t:
x+=1
an.append(i+1)
i+=1
s[i-1],s[i]=t,t
else:
if p[0]!=t:
x+=1
an.append(i+... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import java.util.*;
public class CodeforcesA {
public static void main(String args[]) {
Scanner s= new Scanner(System.in);
int n=s.nextInt();
String str=s.next();
int countb=0;
int countw=0;
int ans[]= new int [str.length()];
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='B') {
cou... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n = int(input())
a = list(input())
ans = []
if 'W' not in a or 'B' not in a:
print(len(ans))
print(*ans)
else:
for i in range(n - 1):
if a[i] == 'W':
a[i] = 'B'
ans.append(i + 1)
if a[i + 1] == 'B':
a[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... | import java.util.ArrayList;
import java.util.Scanner;
public class Blocks {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int n=s.nextInt();
String str=s.next();
int[] arr1=new int[n];
int[] arr2=new int[n];
int count1=0;
int count2=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 i64 = int_fast64_t;
void solve() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
std::vector<int> ans;
for (int i = (0); (i) < (n - 1); ++(i)) {
if (s[i] == 'W' and s[i + 1] == 'W') {
ans.emplace_back(i);
s[i] = 'B', s[i + 1] = 'B';
} else if (s[i] ==... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
vector<int> v;
int main() {
cin >> n >> s;
string t = s;
int x = count(s.begin(), s.end(), 'B');
int y = count(s.begin(), s.end(), 'W');
if (x % 2 == y % 2 && x % 2 == 1) {
return cout << -1, 0;
}
if (x == n || y == n) {
cout << "0";
... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStre... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
n = int(input())
s = input()
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.awt.Desktop;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | import sys
input = sys.stdin.readline
n = int(input())
s = list(input())[:n]
res = []
#sonomama
flag = True
for i in range(1,n-1):
if flag:
if s[i] == s[0]:
flag = True
else:
res.append(i+1)
flag = False
else:
if s[i] != s[0]:
flag = True... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more 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);
long long int n;
cin >> n;
string s;
cin >> s;
vector<long long int> a1(n, 0);
vector<long long int> a2(n, 0);
for (long long int i = 0; i < n; i++) {
if (s[i] == 'B')
a1[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 = list(input())
if s.count("B")%2 == 1 and s.count("W")%2 == 1:
print(-1)
else:
ans = []
for j in (0,1):
for i in range(len(s)-1):
if s[i] != 'WB'[j]:
ans.append(i)
s[i] = 'W' if s[i] == 'B' else 'B'
s[i+1] = 'W' if s[i+1] ==... |
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of ope... | n=int(input())
s=input()
q=list(s)
b,w=s.count("B"),s.count("W")
l=[]
if b==n or w==n:
print(0)
elif b%2 and w%2:
print(-1)
else:
if b%2==0:
for i in range(len(q)-1):
if q[i]=="B" and q[i+1]=="W":
q[i],q[i+1]=q[i+1],q[i]
l.append(i+1)
elif q[... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.