output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; char a[1005][1005]; bool vis[1005][1005]; int n, m; int check(string s) { int i; for (i = 0; i < s.size(); i++) { if (i + 1 < s.size() && s[i] == '#' && s[i + 1] == '.') { break; } } i++; for (; i < s.size(); i++) { if (s[i] == '#') { cout ...
### Prompt Develop a solution in cpp to the problem described below: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> using namespace std; char g[3000][3000]; int nearC[3000], cH[3000], cC[3000], rH, rC, nearH[3000], vis[3000][3000], hang, cot; void dfs(int h, int c) { if (vis[h][c] == 1 || g[h][c] != '#' || h == 0 || c == 0 | h > hang || c > cot) { return; } vis[h][c] = 1; dfs(h + 1, c);...
### Prompt Generate a CPP solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some nort...
#include <bits/stdc++.h> using namespace std; int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } bool prime_check(long long int n) { long long int i, j; if (n == 1) { ...
### Prompt Generate a CPP solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some nort...
#include <bits/stdc++.h> using namespace std; long long a[1005][1005]; long long visited[1005][1005]; long long n, m; long long dirx[] = {1, 0, -1, 0}; long long diry[] = {0, -1, 0, 1}; long long issafe(long long i, long long j) { if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] && !visited[i][j]) return 1; return...
### Prompt Develop a solution in CPP to the problem described below: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> using namespace std; int a[1010][1010]; int con[1010][1010]; int n, m; bool isvalid(int a, int b) { return (a >= 0 && a < n && b >= 0 && b < m); } bool label(int i, int j, int col) { if (!isvalid(i, j)) return false; if (con[i][j] != 0) return false; if (a[i][j] == 0) return false; con[...
### Prompt Your task is to create a cpp solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may p...
#include <bits/stdc++.h> using namespace std; string s[1005]; long long dr[] = {0, 0, -1, 1}; long long dc[] = {1, -1, 0, 0}; long long n, m; void dfs(long long i, long long j) { s[i][j] = '.'; for (long long x = 0; x < 4; x++) { if (i + dr[x] >= 0 && i + dr[x] < n && j + dc[x] >= 0 && j + dc[x] < m && ...
### Prompt Develop a solution in CPP to the problem described below: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long dot(complex<long long> c1, complex<long long> c2) { return imag(c1 * conj(c2)); } double dot(complex<double> c1, complex<double> c2) { return imag(c1 * conj(c2)); } lon...
### Prompt Please create a solution in CPP to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000, MAX_M = 1000; int parent[MAX_N * MAX_M]; char grid[MAX_N][MAX_M + 1]; int n, m; int index(int i, int j) { return m * i + j; } int find(int index) { if (parent[index] == index) return index; return parent[index] = find(parent[index]); } void unite...
### Prompt Please provide a cpp coded solution to the problem described below: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you m...
#include <bits/stdc++.h> using namespace std; int n, m; string s[1000]; bool row[1000], column[1000]; bool sign[1000][1000]; int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1}; void dfs(int x, int y) { for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx >= 0 && nx < n && ny >= 0 && ny < m &...
### Prompt Construct a cpp code solution to the problem outlined: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some...
#include <bits/stdc++.h> using namespace std; int vis[1050][1050] = {0}; char maps[1050][1050]; int r[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; void dfs(int x, int y, int n, int m) { if (x < 0 || x >= n || y < 0 || y >= m || maps[x][y] == '.') return; if (vis[x][y] == 1) return; vis[x][y] = 1; for (int i = 0; i < 4; ...
### Prompt Develop a solution in cpp to the problem described below: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e3 + 10; string a[mxn]; bool vis[mxn][mxn]; int n, m; bool dfs(int i, int j) { if (i < 0 || i > m - 1 || j < 0 || j > n - 1) return 0; if (a[i][j] == '.' || vis[i][j]) return 0; vis[i][j] = 1; dfs(i + 1, j); dfs(i, j + 1); dfs(i - 1, j); dfs(i...
### Prompt Please formulate a cpp solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } long long kai(long long x, long long y) { long long res = 1; for (long long i = x - y + 1; i <= x; i++) { ...
### Prompt Generate a cpp solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some nort...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; char mp[N][N]; int n, m, f1, f2, ans, d[4][2] = {0, 1, 0, -1, 1, 0, -1, 0}; void dfs(int x, int y) { mp[x][y] = '.'; for (int i = 0, nx, ny; i < 4; i++) { nx = x + d[i][0], ny = y + d[i][1]; if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && ...
### Prompt Construct a Cpp code solution to the problem outlined: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some...
#include <bits/stdc++.h> using namespace std; const bool testcases = 1; void print(int a[], int n) { for (int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n"; } unsigned long long int logn(unsigned long long int n, unsigned long long int r) { return (n > r - 1) ? 1 + logn(n / r, r...
### Prompt Generate a cpp solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some nort...
#include <bits/stdc++.h> using namespace std; vector<long long> par, rnk; long long find_set(long long a) { if (a == par[a]) return a; return par[a] = find_set(par[a]); } void unite(long long a, long long b) { long long x = find_set(a); long long y = find_set(b); if (x != y) { if (rnk[x] < rnk[y]) swap(x,...
### Prompt Develop a solution in cpp to the problem described below: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> using namespace std; const long long INF = 9223372036854775807; const long long MOD = 1000000007; const long double PI = acos(-1); inline long long power(long long a, long long b, long long z = MOD) { long long res = 1; a = (a % z); while (b) { if (b & 1) res = (res * a) % z; a = ...
### Prompt In Cpp, your task is to solve the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some n...
#include <bits/stdc++.h> using namespace std; long long int mod = 998244353; long long int ceil1(long long int n, long long int k) { if (n % k) return n / k + 1; return n / k; } long long int pow1(long long int n, long long int k) { long long int ans = 1; while (k != 0) { if (k % 2) ans = (ans * n) % mod; ...
### Prompt Please formulate a CPP solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place s...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000") using namespace std; bool a[1100][1100]; bool visited[1100][1100]; bool valid(int n, int m) { for (int(i) = 0; (i) < (n); (i)++) { bool flag = false; for (int(j) = (1); (j) < (m); (j)++) { if (a[i][j - 1] && !a[i][j]) flag = true; ...
### Prompt Your task is to create a Cpp solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may p...
#include <bits/stdc++.h> const int N = 1e3 + 5; const int d[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; char _[N][N]; bool vis[N][N]; int n, m; bool dfs(int x, int y) { if (vis[x][y] || _[x][y] == '.') return 0; vis[x][y] = 1; for (const int* i : d) { int now_x = x + *i, now_y = y + *(i + 1); if (now_x <= ...
### Prompt Create a solution in CPP for the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some no...
#include <bits/stdc++.h> using namespace std; using ll = long long; mt19937 rng(1234); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; while (cin >> n >> m) { vector<string> a(n); for (auto &e : a) cin >> e; bool good = true; for (int i = 0; i < n; ++i) { int start = -1...
### Prompt Construct a cpp code solution to the problem outlined: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some...
#include <bits/stdc++.h> using namespace std; const int maxx = 1e3 + 7; int n, m, flag = 1, x, y; char s[maxx][maxx]; int vis[maxx][maxx], l[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; void bfs(int x, int y) { vis[x][y] = 1; queue<pair<int, int>> q; q.push(make_pair(x, y)); while (!q.empty()) { pair<int, in...
### Prompt Your challenge is to write a cpp solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you m...
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb...
### Prompt Construct a Cpp code solution to the problem outlined: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some...
#include <bits/stdc++.h> using namespace std; char a[1005][1005]; int h[1005], l[1005], vh[1005], vl[1005]; int n, m; void bfs(int x, int y) { a[x][y] = '.'; if (x - 1 >= 1 && a[x - 1][y] == '#') { bfs(x - 1, y); } if (x + 1 <= n && a[x + 1][y] == '#') { bfs(x + 1, y); } if (y - 1 >= 1 && a[x][y - 1...
### Prompt Your challenge is to write a cpp solution to the following problem: A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you m...
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long me(long long x, long long y, long long p) { long long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x...
### Prompt Construct a Cpp code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string a; cin >> a; vector<int> a_sum(n); a_sum[0] = (a[0] == '1'); for (int i = 1; i < n; i++) { a_sum[i] = a_sum[i - 1] + (...
### Prompt Construct a Cpp code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long INF = 1e18; const long long MAX = 100001; void solve() { long long n, k; cin >> n >> k; string s; cin >> s; long long j = -1; long long i = 0; long long count = 0; for (i = 0; i < n; i++) { if (s[i] == '1...
### Prompt Your task is to create a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of t...
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 9, inf = INT_MAX; void solve() { int n, m, k, l, r, x, y, ans = 0, a, b; cin >> n >> k; string s; cin >> s; int pre[n]; memset(pre, -1, sizeof(pre)); ; if (s[0] == '1') { pre[0] = 0; } for (int i = 1; i < n; i++) { pre[i] = p...
### Prompt Generate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t > 0) { int n, k, temp = 0, avail = 0; cin >> n >> k; int arr[n]; string s; cin >> s; if (s.find('1') == -1) { s[0] = '1'; avail++; } for (int i = 0; i < n; i++) { if (s[i] == '1')...
### Prompt Create a solution in CPP for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; long long int test, flag, n, i, p, sum, S, l, r, m, x, y, XD, j, j_1, k, k1, res, min_, flag1, max_, XD1, count_, dick_size1, s_size; char ch[200010], ch_1[2000100]; string s; char c; long long int pl, mi, a, b, suck, ans, arr_even[1000100], ajib_arr[5000500], arr[5...
### Prompt Generate a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> using namespace std; const long long int M = 1000000007; const long long int N = 998244353; inline long long int add(long long int a, long long int b, long long int MOD) { a += b; if (a >= MOD) a -= MOD; return a; } inline long long int sub(long long int a, long long int b, long long int ...
### Prompt In cpp, your task is to solve the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaura...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int last = -1, ans = 0, ps; for (int i = 0; i < n; i++) { if (s[i] - '0' == 1) { if (las...
### Prompt Your challenge is to write a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int prev = -(k + 1); int ans = 0; for (int i = 0; i < (int)s.length(); i++) { if (s[i] =...
### Prompt Create a solution in Cpp for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; int t, n, k, A[200002]; string s; void ones(int &i) { int temp = k, y = i; while (temp-- and i++ < n) { s[i] = '1'; } temp = k; while (temp-- and y--) { s[y] = '1'; } } int main() { cin >> t; while (t--) { cin >> n >> k >> s; int cnt = 0; ...
### Prompt Please formulate a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)(1e17 + 17); const long long mod = (long long)(1e9 + 7); int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long T; cin >> T; while (T--) { long long n, k; cin >> n >> k; string s; cin >...
### Prompt Your task is to create a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of t...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int check[n]; int dis1 = 0; int dis2 = 0; for (int i = 0; i < n; ++i) { check[i] = 0; } int d = k; int f = 0; for (int i = 0;...
### Prompt Construct a cpp code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int T, n, k; char op[N]; int su[N]; inline void work() { for (int i = 0; i < 10; ++i) { } } int main() { cin >> T; while (T--) { scanf("%d%d", &n, &k); scanf("%s", op); int sum = 0, pos = 0, flag = 0; for (int i = 0; i < n; ++...
### Prompt Your challenge is to write a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k, out, count; cin >> t; for (int x = 0; x < t; x++) { cin >> n >> k; string s; cin >> s; int res = 0, l, r, i = 0, j = 0; for (; i < n;) { j = i + 1; for (; j < n && s[j] != '1'; j++) ; l = s[i] == ...
### Prompt Generate a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; void min_self(long long &a, long long b) { a = min(a, b); } void max_self(long long &a, long long b) { a = max(a, b); } long long add(long long x, long long y) { return (x + y) % MOD; } long long sub(long long x, long long y) { return add(x, M...
### Prompt Please formulate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, k; string str; cin >> n >> k; cin >> str; if (n == k) { int seat = 1; for (int j = 0; j < n; j++) { if (str[j] == '1') { seat = 0; break; ...
### Prompt Generate a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long inf = 1e9 + 7; long long modexp(long long base, long long power) { if (power == 0) return 1; if (power & 1) ret...
### Prompt Your task is to create a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of t...
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { int n, k; scanf("%d %d", &n, &k); int tot = 0; int count = k; for (int i = 0; i < n; i++) { char c; while ((c = getchar()) == '\n') ; if (c == '1') { tot += (count - k) / (k + 1); ...
### Prompt Please create a solution in Cpp to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; long long int MX = 1e18; long long int MN = -MX; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int i, j, k, l, a, b, c, d, q, s, n, m, o, p, tc = 1, jj, z, aa; cin >> tc; for (jj = 0; jj < tc; jj++) { vector<long lon...
### Prompt Create a solution in cpp for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int i, j, cno = 0, k; int t, n, m, x, y; cin >> t; while (t--) { cin >> n >> m; string s; cin >> s; x = 0; y = 0; bool noone = true; for (i = 0; i < n; i++) { ...
### Prompt Please provide a CPP coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> int main() { long long a, b, c, d, e, f, g, h, i, j, k, l; scanf("%lli", &a); for (; a > 0; a--) { scanf("%lli%lli", &b, &c); char s[3]; gets(s); char t[b + 1]; gets(t); for (d = e = f = h = 0; d < b; d++) { if (t[d] == '0') e++; else { ...
### Prompt Please formulate a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> const double pi = acos(-1.0); using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { int n, k, ans = 0, count = 0; cin >> n >> k; string s; cin >> s; vector<int> a; for (int i = 0; i <...
### Prompt Create a solution in cpp for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int ans = 0; int chki = -1; for (int i = 0; i < n; i++) { if (s[i] == '1') { chki = i; ...
### Prompt Create a solution in cpp for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; while (k--) { int a, b; cin >> a >> b; int c = b; int t = 0; for (int i = 0; i < a; i++) { char k; cin >> k; if (k == '0') c++; if (k == '1') { c -= b; t += c / (b + 1); ...
### Prompt Please provide a CPP coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; string s; cin >> n >> k; cin >> s; int i = 0, left = 0, ans = 0, len = s.length(); left = left - k - 1; while (i < len) { int dist = i - left - 1; if (dist >= 2 * k + 1) { ...
### Prompt Construct a Cpp code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; long int cnt; void me(long int d, long int k, long int m) { if (d < (m * k) + 1) { return; } else if (d == (m * k) + 1) { cnt++; } else { cnt++; cnt += (d - (m * k) - 1) / (k + 1); } return; } int main() { long int j, i, d, k, t, n, m; string s...
### Prompt Your challenge is to write a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int count = 0, max = 0; for (int i = 0; i < n;) { if (s[i] == '0') { for (int j = i + 1; j <= i + k && j < n; j++) { if (s[j] == '1...
### Prompt Your challenge is to write a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 17 + 5; const int W = 1000 + 5; const int OO = 2e9; const int mod = 1e9 + 7; int t, n, k, ans, nxt[N], lst, b; string second; void init() { lst = OO; ans = b = 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin...
### Prompt Please create a solution in cpp to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int l = 0, c = 0; for (int i = 0; i < n;) { if (s[i] == '1') { i += k + 1; ...
### Prompt In CPP, your task is to solve the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaura...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t-- != 0) { long long int n, k; cin >> n >> k; string s; getline(cin >> ws, s); long long int a[n]; for (long long int i = 0; i < n;...
### Prompt Please formulate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; set<int> q; for (int i = 0; i < (int)s.size(); i++) { if (s[i] == '1') q.insert(i); } int ans = 0; for (int i = 0; i < (int)s.size(...
### Prompt Develop a solution in cpp to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; for (int t = 0; t < T; t++) { int n, k; cin >> n >> k; string str; cin >> str; vector<int> v; for (int i = 0; i < n; i++) { if (str[i] == '1') v.push_back(i); } if (v.size() == 0) { cout << 1 + ...
### Prompt Create a solution in CPP for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(NULL); int q; cin >> q; while (q--) { long long n, k; cin >> n >> k; string a; cin >> a; long long f = n + 1; long long l = -1; long long prev = -1; long long ans = 0; long long ok...
### Prompt Please formulate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } long lon...
### Prompt In CPP, your task is to solve the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaura...
#include <bits/stdc++.h> using namespace std; long long int fpow(long long int n, long long int k, long long int p = 1000000007) { long long int r = 1; n = n % p; while (k > 0) { if (k & 1) { r = (r * n) % p; } k = k >> 1; n = (n * n) % p; } return r; } bool isPrime(lo...
### Prompt Your challenge is to write a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; unordered_set<int> int_set; set<int, greater<int> > divisors; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { int n, k; long long i; string a; cin >> n >> k >> a; long long ans = 0, cnt;...
### Prompt Your challenge is to write a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long i, j, k, n, c = 0, mx, ans = 0; cin >> n >> k; string s; cin >> s; mx = k; for (long long i = 0; i < n; i++) { if (s[...
### Prompt Generate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int next = 0; int ans = 0; for (int i = 0; i < n;) { if (s[i] == '1') { next = i + k + 1; i++...
### Prompt Develop a solution in Cpp to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k, ans = 0, f = 0; char c; cin >> n >> k; for (int i = 1; i <= n + 1; i++) { if (i == n + 1) c = '1'; else cin >> c; if (c == '1' && i <= n) { if (f == 0) ...
### Prompt Create a solution in CPP for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int N = 2e5 + 5; string s; int i, n, k, a, b, t, z, c, m; int main() { cin >> t; while (t--) { cin >> n >> k; b = 0; int d = k; for (int i = 0; i < n; i++) { scanf("%1d", &a); if (a == 0) d++; else { ...
### Prompt In Cpp, your task is to solve the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaura...
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 9, inf = INT_MAX; void solve() { int n, m, k, l, r, x, y, ans = 0, a, b; cin >> n >> k; string s; cin >> s; int pre[n]; memset(pre, -1, sizeof(pre)); ; if (s[0] == '1') { pre[0] = 0; } for (int i = 1; i < n; i++) { pre[i] = p...
### Prompt Your challenge is to write a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int helper(int arr[], int no, int k) { int right[no]; int left[no]; int distance = no + 10; for (int i = no - 1; i >= 0; i--) { if (arr[i] == 0) right[i] = (++distance); else distance = 0; } int ans = 0; distance = no + 10; for (int i = 0...
### Prompt Your challenge is to write a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; int n, k, cnt = 0, p; cin >> n >> k >> s; vector<char> ans(n); vector<int> ch; for (int i = 0; i < n; i++) if (s[i] == '1') ch.push_back(i); int m = ch.size(); if (m == 0) { ...
### Prompt Please formulate a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int seats(int i, int j, int space) { if (j < i) { return 0; } int ans = 0; for (int x = i; x <= j; x += space) { ans++; } return ans; } int main(int argc, char const* argv[]) { ios_base::sync_with_stdio(false); cin.tie(nullptr); int test; cin >> ...
### Prompt Generate a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; const double PI = acos(-1.0); const int INF = 1e9; const int MOD = INF + 7; const double EPS = 1e-9; const long long BIGINF = 1e17; mt19937 rng(time(0)); uniform_int_distribution<int> uid(0, INF / 2); int main() { ios_base::sync...
### Prompt Your task is to create a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of t...
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, k; cin >> t; string s; while (t--) { set<long long> s1; cin >> n >> k; cin >> s; long long c = 0; for (long long i = 0; i < n; i++) { if (s[i] == '1') s1.insert(i); } s1.insert(-k - 1); s1.insert(n +...
### Prompt Please create a solution in cpp to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int t; scanf("%d", &t); while (t--) { int n, k, idx = 0, ans = 0; scanf("%d%d", &n, &k); string s; cin >> s; if (s[0] == '0') ans++; for (int i = 1; i < n; ++i) { if (s[i] == '0' && (i - idx) > k) ...
### Prompt Create a solution in CPP for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; s = string(k + 1, '0') + s + string(k + 1, '0'); s.front() = '1'; s.back() = '1'...
### Prompt Please provide a cpp coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; vector<int> ones; for (int l = 0; l < s.length(); l++) { if (s[l] == '1') { ones.push_back(l); } } if (ones.size() > 1) { ...
### Prompt Please provide a Cpp coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s = ""; for (int i = 0; i < k; i++) s += "0"; string temp1; temp1 = s; string temp; cin >> temp; s = s + temp + temp1; int j = 0; int ans = 0; f...
### Prompt Generate a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int t, n, k; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n >> k; cin >> s; int l = k + 1, ans = 0, r = 0; for (int i = 0; i < s.size(); i++) { if (...
### Prompt Develop a solution in Cpp to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else { if (y > 0) return x * temp * temp; else return (temp * temp) / x; } } long long GcdRecurs...
### Prompt Construct a Cpp code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { set<long long int> s1; s1.insert(-1e9); s1.insert(1e9); long long int n, k; cin >> n >> k; string s; cin >> s; long long int ans = 0; for (long long int i = 0; i < n; i++) { ...
### Prompt Please formulate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; void fastio() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed; } int main() { fastio(); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; set<int> q; for (int i = 0; i < (int)s.size(); ...
### Prompt Your task is to create a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of t...
#include <bits/stdc++.h> using namespace std; long long infint = LLONG_MAX; long long infi = INT_MAX; long infl = LONG_MAX; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 |...
### Prompt Develop a solution in Cpp to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; long long t, n, k; string s; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n >> k >> s; long long d = 1, ta = 0, f, l; for (f = 0; f < (long long)s.size() && s[f] == '0'; f++) ; for (l = (long long)s.size() - ...
### Prompt Please provide a Cpp coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; if (k >= n) { int f = 0; for (int i = 0; i < n; i++) { if (s[i] == '1') { f = 1; break; } } if (f =...
### Prompt Please provide a CPP coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int zeroes = k, res = 0; for (int i = 0; i < n; i++) { char temp; cin >> temp; if (temp == 48) { zeroes++; } else { res += (zeroes - k) / (k + ...
### Prompt Create a solution in cpp for the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restauran...
#include <bits/stdc++.h> using namespace std; int t, n, k; string process(string s) { for (int i = 0; i < n; i++) { if (s[i] == '1') { for (int j = max(0, i - k); j <= min(n - 1, i + k); j++) s[j] = '*'; } } return s; } int main() { int ans, lol; cin >> t; string s; while (t--) { cin >> ...
### Prompt Please create a solution in CPP to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int distancetoone = -1; for (int i = 0; i < n; i++) { if (s[i] == '1') { distancetoone = i; ...
### Prompt Develop a solution in cpp to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t; cin >> t; while (t != 0) { t--; int n, k, l = -1, r = -1; cin >> n >> k; int c = k + 1, z, res = 0; string x; cin >> x; ...
### Prompt Generate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant ...
#include <bits/stdc++.h> #pragma GCC optimize("O3") const int INF = 1e9; const int MOD = 1e9 + 7; const int N = 1e5; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; while (q--) { int n, k, ans = 0, a[200005] = {0}, b[200005] = {0}; string str...
### Prompt Please formulate a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k; string s; cin >> t; while (t--) { cin >> n >> k; cin.ignore(1, '\n'); cin >> s; queue<int> q; for (int i = 0; i < n; i++) { if (s[i] == '1') q.push(i); } int start = 0, ans = 0; while (!q.empty()) { ...
### Prompt In Cpp, your task is to solve the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaura...
#include <bits/stdc++.h> using namespace std; long long fast(long long base, long long expo) { long long res = 1; while (expo > 0) { if (expo % 2 == 1) res = (res * base) % 1000000007; base = (base * base) % 1000000007; expo /= 2; } return res % 1000000007; } int main() { ios_base::sync_with_stdio...
### Prompt Please formulate a cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("fast-math") int main() { { ios_base::sync_with_stdio(false); ci...
### Prompt Please provide a CPP coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k, i; cin >> n >> k; string s; cin >> s; vector<int> st; for (i = 0; i < n; i++) { if (s[i] == '1') { st.push_back(i); } } long long int len = st.size(); long long int count = 0, p = 0; for (i = 0; i < n;) { ...
### Prompt Please provide a CPP coded solution to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; void solve() { int n, k; cin >> n >> k; string s; cin >> s; int ans = 0; for (int i = 0; i < n;) { int j = i + 1; for (; j < n; ++j) if (s[j] == '1') break; int len = j - i; if (s[i] == '1') { len = max(0, ...
### Prompt Construct a Cpp code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; long long t, n, k, sum; string s; bool tidak[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; while (t--) { sum = 0; cin >> n >> k; cin >> s; memset(tidak, false, sizeof(tidak)); for (int i = 0; i...
### Prompt Please create a solution in Cpp to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { bool flag = false; int n, k, count = 0, last; string s; cin >> n >> k >> s; for (int i = 0; i < n; i++) { if (s[i] == '1') { if (!flag) { c...
### Prompt Develop a solution in cpp to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double pi = acos(-1.0); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; while (q--) { int n, k; cin >> n >> k; string t; string T; cin >> t; T = t; vector<int> pos; ...
### Prompt Please formulate a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; const long long inf64 = 1e18; const long long MOD = inf + 7; void solve() { long long n, k; cin >> n >> k; string s; cin >> s; long long ans = 0, prev = -1; for (long long i = 0; i < n + 1; i++) { if (i == n) { if (prev == -1...
### Prompt In cpp, your task is to solve the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaura...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; bool tables[200001] = {false}; for (int i = 0; i < s.size(); i++) if (s.at(i) == '1') for (int j = max(0, i - k); j <= min(n - 1, i + k); j++...
### Prompt Construct a CPP code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int min = n + 1, count = n + 1; for (int i = 0; i < n; ++i) { if (s[i] == '1') { if (count < min) min = count; count = 0; } els...
### Prompt Construct a cpp code solution to the problem outlined: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restau...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { int n, k; string s; cin >> n >> k >> s; int cnt = 0; for (int i = 0; i < n;) { int j = i + 1; for (; j < n && s[j] != '1'; j++)...
### Prompt Develop a solution in cpp to the problem described below: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { int test, cs = 1; cin >> test; while (test--) { int n, k; cin >> n >> k; string s; cin >> s; int first = 0, last = 0, flag = 0; int start = 0, End = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '1' and flag == 0) {...
### Prompt Your challenge is to write a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; string A; cin >> A; vector<int> vec; for (int i = 0; i < n; i++) { if (A[i] == '1') { vec.push_back(i + 1); } } int ans = 0; if (vec.size() == 0) { cout << (n + k) / (k + 1) << '\n'; return; }...
### Prompt Please formulate a Cpp solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the res...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; for (int t = 0; t < T; ++t) { int n, k; cin >> n >> k; string s; cin >> s; vector<int> p(n, 0); p[0] = s[0] - '0'; for (int i = 1; i < n; ++i) { p[i] = p[i - 1] + (s[i] - '0'); } int ans = 0; ...
### Prompt Your task is to create a CPP solution to the following problem: Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of t...