output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; bool check(long long mid, int cnt, long long total) { int i, c = 0, c1 = 0; long long sum = 0; vector<long long> tmp; for (i = 0; i < v.size(); i++) { if (v[i].second < mid) sum += v[i].first; else if (mid <= v[i].first) { ...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary...
#include <bits/stdc++.h> using namespace std; int amount; long long total; pair<int, int> salary[1000005]; bool is_good(int median_sal) { int need = (amount + 1) / 2; long long total_need = 0; for (int i = amount; i >= 1; i--) if (salary[i].first >= median_sal) { need--; total_need += salary[i].fi...
### Prompt Construct a cpp code solution to the problem outlined: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to ...
#include <bits/stdc++.h> using namespace std; long long l[500005], r[500005], n, s; bool check(long long x) { long long k = n + 1 >> 1; vector<long long> vec; for (long long i = 1, v; i <= n; i++) { v = max(l[i], x); if (r[i] < v) continue; vec.push_back(v - l[i]); } if (vec.size() < k) return 0; ...
### Prompt Create a solution in Cpp for the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; struct Node { int L, R; bool operator<(const Node &other) const { return L < other.L; } }; int N, H; long long S; vector<Node> v; bool possible(int median) { long long sum = 0; for (Node &s : v) sum += s.L; int count = 0; for (int i = N ...
### Prompt In cpp, your task is to solve the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> t; while (t--) { long long s; cin >> n >> s; vector<int> l(n), r(n); for (i = 0; i < n; i++) { cin >> l[i] >> r[i]; } vector<int> ord(n); iota(...
### Prompt In cpp, your task is to solve the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_...
#include <bits/stdc++.h> using namespace std; const long long mx = 200005; bool comparator(pair<long long, long long> A, pair<long long, long long> B) { return A.first < B.first; } int main() { ios::sync_with_stdio(0); long long q; cin >> q; while (q--) { long long n, s; long long l; long long r; ...
### Prompt Please provide a Cpp coded solution to the problem described below: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const long long N = 2e5 + 10; long long T, n, s, mx, ts; struct node { long long l, r; } t[N]; long long cmp(node a, node b) { return a.l < b.l; } inline long long check(long long mid) { long long cnt = 0; s = ts; for (long long i = n; i >= 1...
### Prompt Develop a solution in cpp to the problem described below: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i ...
#include <bits/stdc++.h> using namespace std; int t; int n; long long s; struct salary { long long l, r; }; salary a[200001]; bool cmp(salary a, salary b) { return a.l > b.l; } void nhap() { scanf("%d%lld", &n, &s); for (int i = 1; i <= n; i++) { scanf("%lld%lld", &a[i].l, &a[i].r); } sort(a + 1, a + n + ...
### Prompt Generate a cpp solution to the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i d...
#include <bits/stdc++.h> using namespace std; long long read() { char x = getchar(); long long ans = 0, flag = 1; while (!isdigit(x)) if (x == '-') flag = -1, x = getchar(); else x = getchar(); while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar(); return ans * flag; } long long n, s;...
### Prompt Create a solution in Cpp for the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > d; long long s; int f(int cost) { int cnt = 0; long long sum = 0; vector<int> vec; for (int i = 0; i < (int)d.size(); i++) if (cost <= d[i].first) { cnt++; sum += d[i].first; } else if (d[i].second < cost) sum += d[i...
### Prompt Please create a solution in Cpp to the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > v; vector<long long int> v1; long long n, s, lef; bool check(long long x) { long long t = lower_bound((v1).begin(), (v1).end(), x) - v1.begin(); if (t <= n / 2) return 1; long long needed = t; long long left = lef; for (...
### Prompt Create a solution in cpp for the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i...
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; void solve() { int n; LL s; scanf("%d%lld", &n, &s); vector<int> lb(n), ub(n); for (int i = 0; i < n; ++i) scanf("%d%d", &lb[i], &ub[i]); auto check = [&](int mid) -> int { multiset<LL> se; LL tot = 0; ...
### Prompt Develop a solution in cpp to the problem described below: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i ...
#include <bits/stdc++.h> long long int paixu(long long int shuzu[][2], long long int daxiao) { long long int i, j, k, l; l = daxiao; if (l >= 1000) { l = 1000; } for (l = l; l >= 1; l /= 2) { for (i = l; i <= daxiao; i++) { for (j = i; ((shuzu[j][1] < shuzu[j - l][1]) & (j > l)); j -= l) { ...
### Prompt Please provide a Cpp coded solution to the problem described below: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary...
#include <bits/stdc++.h> using namespace std; long long mo(const long long input, const long long ceil) { return input >= ceil ? input % ceil : input; } long long n, s, ans, l, r, i, mid, cnt, sum; pair<long long, long long> a[400000]; void solve(long long tt) { cin >> n >> s; for (i = 1; i <= n; i++) { cin >...
### Prompt Please create a solution in Cpp to the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i ...
#include <bits/stdc++.h> using namespace std; int n; long long s; long long l[200010], r[200010], b[200010]; long long res; bool ok(long long x) { long long tmp = 0; int dem; dem = 0; vector<int> mi; mi.clear(); for (int i = 1; i <= n; i++) { if (r[i] < x) { tmp += l[i]; continue; } ...
### Prompt Create a solution in Cpp for the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_i...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int man = 2e5 + 10; template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T exgcd(T a, T b, T &g, T &x, T &y) { if (!b) { g = a, x = 1, y = 0; } else { exgcd(b, a % b, g, y, x); y -...
### Prompt Please formulate a CPP solution to the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i ...
#include <bits/stdc++.h> using namespace std; bool check(pair<long long int, long long int> arr[], long long int mid, long long int n, long long int s) { vector<pair<long long int, long long int>> both; long long int l = 0, r = 0; for (long long int i = 0; i < n; i++) { if (arr[i].second < mid) { ...
### Prompt Your challenge is to write a CPP solution to the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary...
#include <bits/stdc++.h> using namespace std; const long long M = 3 * (1e5) + 7, mod = 1e9 + 7; long long n, s; vector<pair<long long, long long>> v; bool ok(long long mid) { vector<pair<long long, long long>> d; for (auto u : v) { if (u.second >= mid) { d.push_back({u.first, u.second}); } } sort(...
### Prompt Please create a solution in CPP to the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i ...
#include <bits/stdc++.h> using namespace std; const int o = 1 << 17; const int maxn = 200005; const int mod = 1000000007; const int inf = 0x3f3f3f3f; const long long huge = 100000000000000000LL; long long s; int n, t; int l[maxn], r[maxn]; int tmp[maxn]; long long price(int med) { long long ret = 0; int cnt = 0; ...
### Prompt In Cpp, your task is to solve the following problem: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from l_i to r_...
#include <bits/stdc++.h> using namespace std; bool besarDulu(const int &a, const int &b) { return a > b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s, sOri; cin >> sOri; s = sOri; int B_count = 0, W_count = 0; bool W_ada = false, B_ada = false; for (int i...
### Prompt Please provide a CPP coded solution to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; char s[200005]; vector<int> ans; int main() { int T = 1; while (T--) { int n; cin >> n; scanf("%s", s + 1); int cnt1 = 0, cnt2 = 0; for (int i = 1; i <= n; i++) s[i] == 'B' ? cnt1++ : cnt2++; if (cnt1 % 2 && cnt2 % 2) { puts("-1"); co...
### Prompt Construct a Cpp code solution to the problem outlined: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int c1 = 0, c2 = 0; vector<bool> a(n); for (int i = 0; i < n; i++) { char tmp; cin >> tmp; if (tmp == 'B') { c1++; a[i] = 0; } else { c2++; a[i] = 1; } } if (c1 % 2 == 1 && c2 % 2 == 1...
### Prompt Develop a solution in CPP to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; int b = 0, c = 0; int k = 0; int n; void solve(void) { cin >> n; string x; cin >> x; vector<int> indexB; vector<int> indexW; for (int i = 0; i < n; i++) { if (x[i] == 'B') { b++; indexB.push_back(i + 1); } else { c++; indexW.push_...
### Prompt In cpp, your task is to solve the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block be...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int count_b = 0, count_w = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') count_w++; else count_b++; } if (count_b % 2 != 0 && count_w % 2 != 0) { cout << -1 << endl; return 0; ...
### Prompt Please create a solution in CPP to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; vector<int> ans; char s[100001]; int main() { int n; scanf("%d %s", &n, s); for (int i = 0; i < n - 1; ++i) { if (s[i] == 'W') { s[i] = 'B'; s[i + 1] = (s[i + 1] == 'W') ? 'B' : 'W'; ans.push_back(i + 1); } } if (s[n - 1] == 'B') { pr...
### Prompt Your task is to create a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; vector<int> v; int numOfBlocks, j; string block; void invert(char s) { for (int i = 0; i < numOfBlocks; i++) { if (block[i] == s) { j = i + 1; while (block[j] != s) { v.push_back(j); block[j - 1] = block[j - 1] == 'B' ? 'W' : 'B'; b...
### Prompt Your task is to create a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> int va = 10e8 + 7; long long val[200007] = {0}; using namespace std; long long getmul(long long n) { long long int k{0}; while (n > 0) { k += n % 10; n = n / 10; } return k; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t{1}; while (t--) { int n...
### Prompt Develop a solution in cpp to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c, d, e, t, max_cost, ans = 0; string s; string original; cin >> n; if (n == 0) { cout << "0"; return 0; } cin >> s; original = s; int arr[n]; int j = 0, f = 0; for (long long int i = 0; i < n; i++) { arr...
### Prompt Please create a solution in Cpp to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; void speed() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long N = 1e5 + 5; const long long NN = 105; const long long MAX = 2e5 + 123; const long long MOD = 1e9 + 7; const long long INF = 1e18; vector<pair<long long, long long> > vb, vw; ...
### Prompt In cpp, your task is to solve the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block be...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string s; cin >> s; char arr[N + 1]; strcpy(arr, s.c_str()); vector<int> v; unordered_map<char, int> um; for (int i = 0; i < N; i++) { um[arr[i]]++; } if (um['B'] % 2 == 1 && um['W'] % 2 == 1) { cout << "-1\n"; }...
### Prompt Please formulate a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; char s[300010]; vector<int> ans; int main() { ios::sync_with_stdio(false); int n; cin >> n; cin >> s + 1; for (int i = 1; i < n; i++) { if (s[i] == 'B') { s[i] = 'W'; if (s[i + 1] == 'W') s[i + 1] = 'B'; else s[i + 1] = 'W'; ...
### Prompt Please create a solution in CPP to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; int l[n]; int wh = 0; int bl = 0; for (int i = 0; i < n; i++) { l[i] = s.at(i) == 'W' ? 1 : 0; if (l[i] == 0) { bl++; } else { wh++; } } ...
### Prompt In CPP, your task is to solve the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block be...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long power(long long x, long long n) { if (n == 0) return 1; if (n == 1) return x % mod; if (n % 2 == 0) { long long y = power(x, n / 2) % mod; return (y * y) % mod; } if (n & 1) { long long y = power(x, n - 1); return...
### Prompt Construct a Cpp code solution to the problem outlined: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; char ar[n]; for (int i = 0; i < n; ++i) { cin >> ar[i]; } int co = 0; vector<int> po; for (int i = 0; i < n - 1; ++i) { if (ar[i] == 'W') { ar[i] = 'B'; co...
### Prompt Please create a solution in Cpp to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { file(); fast(); int n; cin >> n; string str; cin >> str; int flib = 0; map<char,...
### Prompt Please formulate a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long ans, sum, tot, cnt, mx, mn, idx, chk, rem, ret, tmp, mid, lft, rgt, pos; long long tc, n, m, a, b, c, d, g, h, l, r, x, y, i, j, k; cin >> n; string s; cin >> s; long long ...
### Prompt Create a solution in CPP for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1...
### Prompt Generate a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becom...
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int a[1000]; int cnt = 0; for (int i = 1; i <= n - 2; i++) { if (s[i] != s[i - 1]) { if (s[i] == 'B') s[i] = 'W'; else s[i] = 'B'; if (s[i + 1] == 'B') s[i + 1] = 'W'; ...
### Prompt Generate a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becom...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; string s; cin >> n >> s; int nb = 0, nw = 0; for (auto ai : s) { if (ai == 'B') { nb++; } else { nw++; } } if (nb & 1 && nw & 1) { cout << -1; return 0; } ...
### Prompt Develop a solution in CPP to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; void solve() { int n; string s; cin >> n >> s; int white = count(s.begin(), s.end(), 'W'); int black = count(s.begin(), s.end(), 'B'); if (white % 2 && black % 2) { cout << "-1" << endl; return; } if (white == s.size() || black == s.size()) { cou...
### Prompt Your task is to create a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; string str; cin >> str; int cw = 0, cb = 0; for (int i = 0; i < n; i++) { if (str[i] == 'B') { cb++; } else { cw++; } } if (cb % 2 != 0 && ...
### Prompt Please create a solution in cpp to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; void fragmentarA() { long long h1, h2, h3, h4, h5, h6, h7, h8, h9; h1 = h2 + h3 + h4; h2 = h1 + h3 + h5 + 9; h3 = h4 + h1 + h6; h3 = h5 + h6; h5 = h6 + h2; h1 = h2 + h5 + h6; h6 = h1 + h2; h5 = h2 + h3; h9 = h2 + h6; h5 = h6 + h7; h2 = h6 + h7 + h5; ...
### Prompt Please provide a CPP coded solution to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; string s; cin >> s; string p = s; long long ans1 = 0, ans2 = 0; vector<long long> v1, v2; for (int i = 0; i < n - 1; i++) { if (s[i] == 'W') { s[i] = 'B'; ...
### Prompt Generate a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becom...
#include <bits/stdc++.h> using namespace std; int main() { int n; string z; cin >> n >> z; int c1 = 0, c2 = 0; for (int i = 0; i < n; i++) { if (z[i] == 'W') c1++; else c2++; } if (c1 % 2 != 0 && c2 % 2 != 0) { cout << -1; return 0; } if (c1 % 2 == 0) { vector<int> ans;...
### Prompt In Cpp, your task is to solve the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block be...
#include <bits/stdc++.h> using namespace std; const int N = 10010; int pos[N]; int main() { int n; cin >> n; string s; cin >> s; s = " " + s; string b = s; int cnt = 0; int i; int s1 = 0, s2 = 0; for (i = 1; i <= s.size(); i++) { if (s[i] == 'W') s1++; } if (s1 == n || s1 == 0) { cout <<...
### Prompt Your challenge is to write a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; vector<char> z; long long x, y, dl, mi, ma, b, s, m, k, w, a[1000], ko; char p; int main() { cin >> dl; for (int i = 0; i < dl; i++) { cin >> p; z.push_back(p); if (p == 'W') w++; else b++; } if (w % 2 != 0 && b % 2 != 0) { cout << -1...
### Prompt Create a solution in Cpp for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; int c = 0; unordered_map<string, bool> memo; bool sb(int i, string s, vector<int> moves, vector<int>& sol, int mreset) { string rem = s; if (memo.find(rem) != memo.end()) return memo.at(rem); if (s.find('W') == string::npos || s.find('B') == string::npos) { sol = ...
### Prompt Your task is to create a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); string s, s1; cin >> s; s1 = s; int i, j, k, l; vector<int> v; for (i = 0; i < n; i++) { if (i + 1 < n && s[i] == 'B') { v.push_back(i + 1); s[i] = 'W'; if (s[i + 1] == 'B') s[i + 1] = 'W'; ...
### Prompt Construct a cpp code solution to the problem outlined: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arrp[n]; int arrn[n]; char t; int b = 0, w = 0; for (int i = 0; i < n; i++) { cin >> t; if (t == 'B') { b++; arrp[i] = -1; arrn[i] = -1; } else { w++; arrp[i] = 1; arrn[i] = 1; ...
### Prompt Your task is to create a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> int main() { int n; std::cin >> n; std::vector<char> str(n); int cnt[2] = {0, 0}; for (int i = 0; i < n; i++) { std::cin >> str[i]; str[i] = str[i] == 'B' ? 0 : 1; cnt[str[i]]++; } if (cnt[0] % 2 && cnt[1] % 2) { printf("-1\n"); return 0; } bool need = (cnt...
### Prompt Please provide a Cpp coded solution to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; int ans[1000]; int ans2[1000]; int main() { int n; scanf("%d", &n); string a; cin >> a; string b = a; int flag1 = 1; int flag2 = 1; int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < a.length() - 1; i++) { if (a[i] == 'B') { ans[++cnt1] = i + 1; ...
### Prompt In CPP, your task is to solve the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block be...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; int cw = 0, cb = 0; for (int i = 0; i < n; i++) { if (str[i] == 'W') cw++; else cb++; } if (cb % 2 != 0 && cw % 2 != 0) { cout << "-1" << endl; return 0; } vector<int> ans;...
### Prompt Please provide a CPP coded solution to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; bool a[n]; char c; for (int i = 0; i < n; ++i) { cin >> c; a[i] = (c == 'W'); } bool b[2][n]; for (int i = 0; i < n; ++i) { b[0][i] = 0; b[1][i] = 1; } vector<int> ans...
### Prompt Create a solution in Cpp for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long T = 1; while (T--) { long long n, b = 0, w = 0; cin >> n; string s; cin >> s; for (long long i = 0; i < n; i++) { if (s[i] == 'B') b++; ...
### Prompt Create a solution in CPP for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string str; cin >> str; vector<char> sv, sb; for (long long i = 0; i < n; i++) { sv.push_back(str[i]); sb.push_back(str[i]); } vector<long long> ans; for (long long i = 0; i < n - 1; i++) { if (sv[i] == 'B'...
### Prompt Your task is to create a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string c; cin >> c; int cntb = 0, cntw = 0; for (int i = 0; i < n; i++) { if (c[i] == 'B') cntb++; else cntw++; } if (cntb % 2 == 1 && cntw % 2 == 1) { ...
### Prompt Your task is to create a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; unsigned long long gcd(unsigned long long n, unsigned long long m) { if (m == 0) return n; else return gcd(m, n % m); } int longestsub(string x, string y, int n, int m) { int lcs[n + 1][m + 1]; int result = 0; for (int i = 0; i < n + 1; i++) { for (int...
### Prompt Create a solution in CPP for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; void IO() {} template <class T> void unisort(vector<T>& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } long long gcd(long ...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } v...
### Prompt Your task is to create a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j = 0, cnt = 0, w = 0, b = 0, sam = 1; cin >> n; int ans[100000]; string s; cin >> s; for (i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) sam++; } for (i = 0; i < n - 1; i++) { if (s[i] == 'B' && s[i + 1] == 'W') { swap(s...
### Prompt Create a solution in CPP for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; string s; cin >> s; long long int w = 0, b = 0; for (long long int i = 0; i < n; i++) { if (s[i] == 'W') w++; else b++; } v...
### Prompt Your challenge is to write a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; string st, st1; cin >> st; st1 = st; vector<long long int> ve, ve1; for (int i = 1; i < n; i++) { if (st[i] == 'W') { if (st[i - 1] != st[i]) { ve.push_back(i); swap(st[i], st[i - 1]); } ...
### Prompt Develop a solution in CPP to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; int N; string s; vector<int> res; bool Solve() { res.clear(); string t = s; for (int i = 0; i < (int)t.size() - 1; i++) { if (t[i] == 'W') { res.push_back(i + 1); t[i] = 'B'; if (t[i + 1] == 'W') t[i + 1] = 'B'; else t[i + 1...
### Prompt Please create a solution in CPP to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> q; string s; cin >> s; for (int i = 0; i < n - 1; i++) { if (s[i] == 'W') { s[i] = 'B'; s[i + 1] = s[i + 1] == 'W' ? 'B' : 'W'; q.push_back(i); } } if (s[n - 1] == 'B') { cout << q.size(...
### Prompt Please provide a cpp coded solution to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; int main(void) { long long n; cin >> n; vector<int> v; string a; cin >> a; int w = 0, b = 0; for (int i = 0; i < n; ++i) { if (a[i] == 'W') w++; else b++; } if (b % 2 == 1 && w % 2 == 1) { cout << -1; exit(0); } else if (b == ...
### Prompt Develop a solution in Cpp to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 1e5 + 6; const long long int MOD = 1e9 + 7; vector<int> prim(1000005, 1); int fact[maxn]; long long int binomialCoeff(long long int n, long long int k) { long long int res = 1; if (k > n - k) k = n - k; for (long long int i = 0; i < k; ++i) ...
### Prompt Construct a cpp code solution to the problem outlined: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, s1; cin >> s; s1 = s; vector<int> v; int coun = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') { coun++; continue; } else if (i < n - 1) { v.push_back(i + 1); s[i] = 'W'; coun++...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; using ll = long long; ll fast_pow(ll a, ll b, ll m) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b = b / 2; } return res; } template <typename T, typename U> std::pair<T, U> operator-(const std::pair<T, U>& l, const std:...
### Prompt In Cpp, your task is to solve the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block be...
#include <bits/stdc++.h> using namespace std; vector<int> ans; char s[221]; int main() { int n; scanf("%d %s", &n, s); for (int i = 0; i < n - 1; ++i) { if (s[i] == 'W') { s[i] = 'B'; s[i + 1] = (s[i + 1] == 'W') ? 'B' : 'W'; ans.push_back(i + 1); } } if (s[n - 1] == 'B') { print...
### Prompt Please formulate a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; vector<int> v; bool slove(string s, char co, char nc) { v.clear(); for (int i = 0; i < s.length() - 1; ++i) { if (s[i] != co) { s[i] = co; if (s[i + 1] != co) s[i + 1] = co; else s[i + 1] = nc; v.push_back(i + 1); } } ...
### Prompt Create a solution in Cpp for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; int main() { int c = 0; vector<int> v; int n; cin >> n; string s; cin >> s; int b = 0, w = 0; for (int i = 0; i < n; i++) { if (s[i] == 'B') b++; else w++; } if (b == 0 && w == n) cout << "0"; else if (w == 0 && b == n) cout...
### Prompt Please formulate a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; const int q = 2e5 + 5; const int INF = 1e9; void done() { int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> pos; int ok = 0; for (int i = 2; i < n; i++) ...
### Prompt Generate a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becom...
#include <bits/stdc++.h> using namespace std; int main() { vector<long long int> ans; long long int n, cw, i; char re; string s; cin >> n; cin >> s; cw = count(s.begin(), s.end(), 'W'); if (cw == 0 || cw == n) cout << "0"; else { re = s[n - 1]; for (i = n - 2; i > 0; i--) { if (s[i] ...
### Prompt Your task is to create a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i = 0, b = 0, w = 0; vector<long long int> v; cin >> n; char s[230]; cin >> s; for (i = 0; i < n; i++) { if (s[i] == 'W') w++; else b++; } if (b % 2 == 1 && w % 2 == 1) cout << "-1" << endl; else { ...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 2e5 + 7; int a[N]; void solve() { int n; cin >> n; string s; cin >> s; int b = 0, w = 0; for (int i = 0; i < n; i++) { if (s[i] == 'B') b++; else w++; } vector<int> v; if (w % 2 && b % 2) { c...
### Prompt Generate a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becom...
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; string s; cin >> s; string t = s; long long o = 0; vector<long long> v; for (long long i = 0; i < s.size() - 1; i++) { if (s[i] == 'B') { o++; v.push_back(i); s[i] = 'W'; if (s[i + 1] == 'W')...
### Prompt Your task is to create a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, c = 0, c1 = 0; cin >> n; string s, s1; cin >> s; s1 = s; vector<long long> v, v1; for (long long i = 0; i < n - 1; i++) { if (s[i] == 'B') { s[i] = 'W...
### Prompt Create a solution in cpp for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int countb = 0; int countw = 0; for (int i = 0; i < s.length(); ++i) { if (s[i] == 'B') countb++; else if (s[i] == 'W') countw++; } ...
### Prompt Create a solution in cpp for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#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++)...
### Prompt Please create a solution in Cpp to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#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...
### Prompt Create a solution in cpp for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#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...
### Prompt Create a solution in CPP for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#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) ...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#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'; }...
### Prompt Construct a cpp code solution to the problem outlined: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block ...
#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 << " "; ...
### Prompt Your task is to create a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#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) %...
### Prompt Please formulate a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#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...
### Prompt Develop a solution in CPP to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#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 +...
### Prompt Your task is to create a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#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); ...
### Prompt Create a solution in cpp for the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block bec...
#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...
### Prompt Please provide a Cpp coded solution to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#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'; }...
### Prompt Your challenge is to write a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#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'; ...
### Prompt Develop a solution in cpp to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#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]...
### Prompt Your challenge is to write a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#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 %...
### Prompt Your challenge is to write a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#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 ...
### Prompt Develop a solution in cpp to the problem described below: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#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 <=...
### Prompt Your task is to create a Cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (whi...
#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...
### Prompt In cpp, your task is to solve the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block be...
#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 +...
### Prompt Please create a solution in Cpp to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#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...
### Prompt Your challenge is to write a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...
#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'; ...
### Prompt Please formulate a cpp solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white blo...
#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...
### Prompt Your challenge is to write a CPP solution to the following problem: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors ...