output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <bits/stdc++.h>
const long long INF = 1e9 + 7;
using namespace std;
int longestPalindromicPrefix(string& second) {
string kmprev = second;
std::reverse(kmprev.begin(), kmprev.end());
string kmp = second + "#" + kmprev;
vector<int> lps(kmp.size(), 0);
for (int i = 1; i < (int)lps.size(); ++i) {
in... | ### Prompt
Develop a solution in Cpp to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
long long int _xor(long long int a, long long int b) { return a ^ b; }
long long int _and(long long int a, long long int b) { return a & b; }
long long int _or(long long int a, long long int b) { return a | b; }
long long int _not(long long int a) { return ~a; }
long long i... | ### Prompt
Create a solution in Cpp for the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Eng... |
#include <bits/stdc++.h>
using namespace std;
int p(string s) {
string a = s;
s += "#";
reverse(a.begin(), a.end());
s += a;
int n = s.size();
vector<int> pi(n);
pi[0] = 0;
int j = 0;
for (int i = 1; i < n; i++) {
j = pi[i - 1];
while (j > 0 && s[i] != s[j]) j = pi[j - 1];
if (s[i] == s[j]... | ### Prompt
Generate a CPP solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Engli... |
#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
int longestPrefixSuffix(string s) {
int n = s.length();
int lps[n];
lps[0] = 0;... | ### Prompt
Please create a solution in cpp to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int t, n, d1[1000005], d2[1000005], b;
string s;
int32_t main() {
ios_base ::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> t;
while (t--) {
cin >> s;
n = s.length();
int c = 0, mxl = 0, mxr = 0, mx = 0;
int sum = 0... | ### Prompt
Please provide a cpp coded solution to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
long long len(string s) {
string rev = "";
string str = s;
long long m = s.size(), ans = 1;
if (m == 0 || m == 1) ans = m;
for (long long i = m - 1; i >= 0; i--) rev += s[i];
s += '#';
s += rev;
long long n = s.size(), z[n + 4], l = 0, r = 0;
for (long lon... | ### Prompt
Develop a solution in CPP to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
vector<int> Z_value(string s) {
vector<int> Z(s.size());
int x = 0, y = 0;
for (int i = 0; i < s.size(); i++) {
Z[i] = max(0, min(y - i + 1, Z[i - x]));
while (i + Z[i] < s.size() && s[Z[i]] == s[i + Z[i]])
x = i, y = i + Z[i], Z[i]++;
}
return Z;
}
... | ### Prompt
Please formulate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
string KMP(string s) {
string z = s + "#";
reverse(s.begin(), s.end());
z += s;
long long n = z.size();
vector<int> first(n);
first[0] = 0;
int i, j = first[0];
for (i = 1; i < (n); i++) {
while (j > 0 && z[i] != z[j]) j = first[j - 1];
if (z[i] == z... | ### Prompt
Please provide a CPP coded solution to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
int fail1[(int)2e6 + 239];
string longest_palindromicprefix(string s) {
string c = s;
reverse(c.begin(), c.end());
string prefix = s + "#" + c;
for (int i = 1, k = 0; i < prefix.size(); i++) {
while (k > 0 && prefix[i] != prefix[k]) k = fail1[k - 1];
if (pre... | ### Prompt
Please create a solution in CPP to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
template <typename T = int>
inline const T read() {
T x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
string pat;
int F[N];
int getNewLen(int len, char c) {
while (len && c != pat[len]) len = F[len - 1];
return len + (c == pat[len]);
}
void computeF() {
F[0] = 0;
for (int i = 1; pat[i]; i++) F[i] = getNewLen(F[i - 1], pat[i]);
}
string solve(s... | ### Prompt
Please provide a cpp coded solution to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
long long int add(long long int x, long long int y) {
return (x % 1000000007 + y % 1000000007) % 1000000007;
}
long long int mul(long long int x, long long int y) {
return ((x % 1000000007) * (y % 1000000007)) % 1000000007;
}
long long int sub(long long int x, long long... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
vector<int> lps(2000009);
string kmp(string pat) {
int len = 0;
int M = pat.size();
for (int i = 0; i < M; i++) {
lps[i] = 0;
}
lps[0] = 0;
int i = 1;
while (i < M) {
if (pat[i] == pat[len]) {
len++;
lps[i] = len;
i++;
} else {
... | ### Prompt
Please create a solution in CPP to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int gcd(long long int a, long long int b) {
return (b == 0) ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
template <class type>
type power(type x, long long int n) {
... | ### Prompt
Your task is to create a CPP solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of l... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 10;
int z[MAXN];
void Zvalue(const string &s) {
z[0] = s.size();
int l = 0, r = 0, x;
for (int i = 1; i < s.size(); i++) {
if (r < i || z[i - l] >= r - i + 1) {
r < i ? x = i : x = r + 1;
while (x < s.size() && s[x] == s[x - i]) ... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int tc, n, f[N];
string t, s;
int solve(string s) {
string res = s;
int len;
reverse(s.begin(), s.end());
s = res + "#" + s;
f[0] = 0;
int i = 0, j = 1;
len = s.size();
while (j < len) {
if (s[i] == s[j]) {
f[j] = i + 1;
... | ### Prompt
Please formulate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 201001;
vector<long long int> z_func(string s) {
long long int n = (long long int)(s.length());
vector<long long int> z(n);
for (long long int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r) z[i] = min(r - i + 1, z[i - l]);
while (i +... | ### Prompt
Please formulate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, MOD = 1000000007;
string s;
long long prefix[maxn], suffix[maxn], power[maxn];
long long exp(long long int base, long long exponent) {
long long res = 1;
while (exponent) {
if (exponent & 1) res = (base * res) % MOD;
exponent = exponen... | ### Prompt
In Cpp, your task is to solve the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase En... |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B, typename C>
struct triple {
A X;
B Y;
C Z;
triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {}
};
template <typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {
return triple<A, B, C>(a,... | ### Prompt
Develop a solution in CPP to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
const long long int p = 31;
const long long int MOD = 1e9 + 9;
long long int t;
string s;
long long int fpw[1000001];
long long int bpw[1000001];
long long int fsh[1000001];
long long int bsh[1000001];
long long int ix1, ix2;
long long int mx;
long long int fast_exp(long lo... | ### Prompt
Your task is to create a cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of l... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const double EPS = 1e-8;
const long double EUL = 2.71828182845904523536;
const long double PII = 3.14159265358979323846;
string longestprefixpalindrome(string s) {
string t =... | ### Prompt
In CPP, your task is to solve the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase En... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int M = 2e6 + 7;
const int lim = 2e6;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int a[M];
string fun(string s) {
string ss = s;
reverse(ss.begin(), ss.end());
ss = s + "#" + ss;
int k = 0, len = ss.size();
for (int i = 1; i ... | ### Prompt
Generate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Engli... |
#include <bits/stdc++.h>
using namespace std;
char s[5000005], t[5000005];
int pos;
int f[5000005];
int main() {
int m;
cin >> m;
while (m--) {
cin >> s;
t[0] = t[1] = '#';
int len = strlen(s);
for (int i = 0; i < len; i++) {
t[2 * i + 2] = s[i];
t[2 * i + 3] = '#';
}
t[2 * len... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
string manacher(string s) {
long long n = s.size();
vector<long long> d1(n);
for (long long i = 0, l = 0, r = -1; i < n; i++) {
long long k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1);
while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) {
k++;
... | ### Prompt
Please create a solution in cpp to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
char s[maxn], a[maxn], b[maxn];
struct Manacher {
int r[maxn << 1];
void build(string s) {
int len = s.size();
string tem = "$#";
for (long long i = 0; i <= (long long)len - 1; ++i) {
tem += s[i];
tem += '#';
}
i... | ### Prompt
Generate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Engli... |
#include <bits/stdc++.h>
using namespace std;
const int M = (int)(2e6 + 239);
int pref[M], c;
string solve_palindrome(const string& s) {
string a = s;
reverse(a.begin(), a.end());
a = s + "#" + a;
c = 0;
for (int i = 1; i < (int)a.size(); i++) {
while (c != 0 && a[c] != a[i]) c = pref[c - 1];
if (a[c]... | ### Prompt
Create a solution in Cpp for the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Eng... |
#include <bits/stdc++.h>
using namespace std;
void io_init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
vector<int> kmpFailureFunc(const string& S) {
const int n = S.size();
vector<int> F(n + 1, -1);
F[1] = 0;
for (int i = 2; i <= n; i++) {
char c = S[i - 1];
int l = F[i - 1];
while (... | ### Prompt
Generate a cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Engli... |
#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
string rev = s;
reverse(rev.begin(), rev.end());
s = s + "." + rev;
long long int l = s.size();
long long int a[l + 5];
a[0] = 0;
long long int i = 0, j = 1;
while (j < l) {
if (s[i] == s[j]) {
a[j] = i + 1;
++i;
... | ### Prompt
Please formulate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, mod = 1e9 + 7, P = 727;
int h[N], h2[N], n, pw[N];
vector<int> st[N], ft[N];
inline int get1(int l, int r) {
if (l == 0) return h[r - 1];
int ret = h[r - 1] - 1ll * h[l - 1] * pw[r - l] % mod + mod;
if (ret >= mod) ret -= mod;
return ret;
}
i... | ### Prompt
In Cpp, your task is to solve the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase En... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void __f(const char* name, T&& a) {
cerr << name << ": " << a << '\n';
}
template <class T, class... Ts>
void __f(const char* names, T&& a, Ts&&... b) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << a << " /... | ### Prompt
In Cpp, your task is to solve the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase En... |
#include <bits/stdc++.h>
using namespace std;
int t, l;
int urm[2 * 1000000 + 5];
char s[1000000 + 5], aux[2 * 1000000 + 5];
void upd_sd(int &st, int &dr) {
st = 0, dr = l - 1;
while (s[st] == s[dr] && st <= dr) st++, dr--;
st--, dr++;
}
void inverseaza(char *c, int dim) {
for (int i = 0; i < dim / 2; i++) swap... | ### Prompt
Construct a Cpp code solution to the problem outlined:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase ... |
#include <bits/stdc++.h>
using namespace std;
int manacher(string &s) {
int n = s.length();
vector<int> rad(n);
int i = 0, j = 0;
while (i < n) {
while (i - j >= 0 && i + j < n && s[i - j] == s[i + j]) j++;
rad[i] = j;
int k = 1;
while (i - k >= 0 && i + k < n && k + rad[i - k] < j)
rad[i ... | ### Prompt
In CPP, your task is to solve the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase En... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(const T niz[], const int siz) {
for (int i = 0; i < siz; i++) cout << niz[i] << " ";
cout << endl;
}
const long long p = 103;
long long add(long long x, long long y) { return (x + y) % 1000000007; }
long long mul(long long x, long long y) {... | ### Prompt
Your task is to create a cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of l... |
#include <bits/stdc++.h>
using namespace std;
typedef std::priority_queue<long long int, std::vector<long long int>,
std::greater<long long int> >
min_pq;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr << name << " : " << arg1 << "\n";
}
template <typename... | ### Prompt
Please formulate a cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
template <class T>
inline bool MX(T &l, const T &r) {
return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
return... | ### Prompt
Generate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Engli... |
#include <bits/stdc++.h>
using namespace std;
string rev(string s) {
string ret = s;
reverse(ret.begin(), ret.end());
return ret;
}
string lpp(string s) {
int kmp[3 * s.size() + 2];
memset(kmp, 0, sizeof kmp);
string now = s + '?' + rev(s);
for (int i = 1; i <= now.size(); i++) {
int k = kmp[i - 1];
... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int gcd(long long int a, long long int b) {
return (b == 0) ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
template <class type>
type power(type x, long long int n) {
... | ### Prompt
Create a solution in cpp for the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Eng... |
#include <bits/stdc++.h>
using namespace std;
char s[1000005];
long long pre1[1000005];
long long suf1[1000005];
long long pre2[1000005];
long long suf2[1000005];
long long p = 26, mod1 = 19260817, mod2 = 1e9 + 21;
string hashh(string s) {
int n = s.length();
if (n == 0) return "";
string ans = "";
int pos = 1;... | ### Prompt
Please provide a cpp coded solution to the problem described below:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting ... |
#include <bits/stdc++.h>
using namespace std;
string get_ans(const string &s) {
int n = ((int)(s).size());
vector<int> valid(n, 0);
for (int i(0); i < n; ++i) {
if (s[i] != s[n - 1 - i]) {
valid[i] = 0;
break;
}
valid[i] = 1;
}
for (int i(0); i < n; ++i) {
valid[i] = (valid[i] ? i ... | ### Prompt
Please create a solution in cpp to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowerca... |
#include <bits/stdc++.h>
using namespace std;
char s[1000005];
long long pre[1000005];
long long suf[1000005];
long long pre2[1000005];
long long suf2[1000005];
long long ksm2[1000005];
long long ksm[1000005];
long long p = 1e9 + 9, mod = 19260817, mod2 = 1e9 + 21;
void init() {
int len = strlen(s + 1);
ksm[0] = 1;... | ### Prompt
Create a solution in Cpp for the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Eng... |
#include <bits/stdc++.h>
using namespace std;
long long pow1[1000005], pow2[1000005];
inline long long binex(long long a, long long b) {
long long ans = 1, temp = a % 1000000007;
while (b != 0) {
if (b & 1) ans = (ans * temp) % 1000000007;
temp = (temp * temp) % 1000000007;
b = b >> 1;
}
return ans;... | ### Prompt
Your task is to create a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of l... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
inline int gi() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
return sum;
}
inline void chkmax(int &a, int b) {
if (a < b) a = b;
}
char... | ### Prompt
Generate a Cpp solution to the following problem:
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase Engli... |
#include <bits/stdc++.h>
using namespace std;
char mat[1005][1005];
int op[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int m, n;
int checkrow(int i) {
int flag = 0;
for (int j = 1; j <= m; j++) {
if (flag == 0) {
if (mat[i][j] == '#') flag++;
} else if (flag == 1) {
if (mat[i][j] == '.') flag++;
} e... | ### 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;
vector<string> f(1010);
int used[1010][1010];
int n, m, comp = 0;
void error() {
cout << "-1\n";
exit(0);
}
bool can(int i, int j) {
if (i >= 0 && j >= 0 && i < n && j < m)
if (used[i][j] == 0 && f[i][j] == '#') return true;
return false;
}
void DFS(int i, int j... | ### 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;
bool cmp(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return (a.second < b.second);
}
long long power(long long x, long long y) {
long long res = 1;
x = x;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x)... | ### 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;
vector<int> X = {0, 0, -1, 1};
vector<int> Y = {-1, 1, 0, 0};
bool isvalid(int x, int y, vector<vector<char> > &A) {
int n = A.size();
int m = A[0].size();
if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == '#') return true;
return false;
}
void dfs(int x, int y, ... | ### 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;
const long long mod = 1e9 + 7;
const long long inf = 5e18;
long long h, w;
vector<string> maze(1e3 + 10);
vector<vector<long long> > ans(1e3 + 10, vector<long long>(1e3 + 10));
vector<long long> idx = {1, 0, -1, 0};
vector<long long> idy = {0, 1, 0, -1};
long long dfs(long ... | ### 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;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
struct greateri {
template <class T>
bool operator()(T const &a, T const &b) const {
return a > b;
}
};
void setIO(string s) {
ios_base::sync_with_stdio(0);
cin.... | ### 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;
int _[1005][1005], x[1005], y[1005], n, m;
int vis[1005][1005], dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
void dfs(int x, int y) {
if (!_[x][y] || x < 1 || y < 1 || x > n || y > m || vis[x][y]) return;
vis[x][y] = 1;
for (int i = 0; i < 4; i++) dfs(x + dx[i], y + ... | ### 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;
char forbidden = '.';
char required = '#';
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, m;
cin >> n >> m;
vector<string> grid(n);
for (long long i = 0; i < n; i++) {
cin >> grid[i];
}
bool unusedRows = false;
for (long lon... | ### 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;
signed main() {
long long n, m;
cin >> n >> m;
vector<string> vec(n);
for (long long i = 0; i < n; ++i) cin >> vec[i];
bool ch1 = 0;
for (long long i = 0; i < n; ++i) {
bool a = 0, b = 0;
for (long long j = 0; j < m; ++j) {
if (vec[i][j] == '#') {
... | ### 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;
void dfs(vector<string> &g, int i, int j) {
g[i][j] = '.';
vector<pair<int, int> > p = {
{0, 1},
{0, -1},
{1, 0},
{-1, 0},
};
for (auto c : p)
if (i + c.first >= 0 && i + c.first < (int)g.size() && j + c.second >= 0 &&
j + c.secon... | ### 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 int n, m, x;
string ss;
string grid[1005];
long long int row_count_W[1005];
long long int col_count_W[1005];
bool vis[1005][1005];
bool hasBadSubstring(string compressed) {
if (compressed.size() >= 3)
for (long long int i = 0; i < compressed.size() - 2; i++)... | ### 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;
const int maxn = 1e6 + 10;
using namespace std;
int N, M;
char G[1010][1010];
int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
bool vis[1010][1010];
bool judge() {
bool row = 0, col = 0;
for (int i = 1; i <= N; i++) {
int st = 0, cur = 1;
for (int j = 1; j <= M; j++)... | ### 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 Maxn = 1010, inf = 0x3f3f3f3f;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
bool vis[Maxn][Maxn], a[Maxn][Maxn];
bool r[Maxn], c[Maxn], flag[Maxn][2];
int n, m, ans;
inline bool check(int x, int y) {
return (x < 1 || y < 1 || x > n || y > m || vis[x][y]... | ### 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;
char a[1010][1010];
bool x[1010], y[1010];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void dfs(int xx, int yy) {
a[xx][yy] = '.';
for (int i = 0; i < 4; i++) {
int xxx = xx + dx[i];
int yyy = yy + dy[i];
if (a[xxx][yyy] == '#') dfs(xxx, yyy);
}
... | ### 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 mod = 1e9 + 7;
const int N = 55;
int power(int a, int b, int m = mod) {
if (b == 0) return 1;
if (b == 1) return a;
int res = power(a, b / 2, m);
res = (res * res) % m;
if (b & 1) res = (res * a) % m;
return res;
}
int modinv(int a, int m = mod) { return pow... | ### 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 vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const long doubl... | ### 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;
int n, m, cc = 0;
int comp[(int)1001][(int)1001];
bool grid[(int)1001][(int)1001], visited[(int)1001][(int)1001];
void dfs(int i, int j) {
visited[i][j] = true;
comp[i][j] = cc;
if (i > 0 && !visited[i - 1][j] && grid[i - 1][j]) dfs(i - 1, j);
if (i < n - 1 && !visi... | ### 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;
void boostIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const int inf = 1e9 + 7;
const int maxn = 1e3 + 5;
const double eps = 1e-7;
bool ls(double x, double y) { return y - x > eps; }
bool eq(double x, double y) { return abs(x - y) < eps; }
int n... | ### 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;
long long mod = 998244353;
double eps = 1e-10;
long long INF = 0x3f3f3f3f;
const int MAXN = 2e3 + 10;
const int maxn = 1e5 + 10;
long long inf = 100000000000000;
char mp[1010][1010];
void dfs(int i, int j) {
mp[i][j] = '.';
if (mp[i + 1][j] == '#') dfs(i + 1, j);
if (... | ### 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 n, m;
vector<string> v;
vector<vector<bool> > vis(1002, vector<bool>(1002, false));
void fil(long long x, long long y) {
if (x < 0 or y < 0 or x == n or y == m) return;
if (vis[x][y]) return;
if (v[x][y] == '.') return;
vis[x][y] = true;
fil(x + 1, y);
... | ### 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;
const int mod = 1e9 + 7;
const int maxm = 1e3 + 10;
int fa[maxm * maxm];
string s[maxm];
char str[maxm];
int find(int x) {
if (x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x != y) {
fa[x] = y;
}... | ### 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;
int n, m;
const int maxn = 2010;
char save[maxn][maxn];
int res = 0;
int dis[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
struct node {
int x;
int y;
node(){};
node(int a, int b) { x = a, y = b; }
};
void dfs(int x, int y) {
save[x][y] = '.';
for (int i = 0; i < 4; 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;
int main() {
int n, m, x1 = 0, y1 = 0;
cin >> n >> m;
char s[n + 5][m + 5];
int vis[n + 5][m + 5];
vector<int> cnt1(n + 5, 0), cnt2(m + 5, 0);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
vis[i][j] = 0;
}
}
for (int i = 1; i <=... | ### 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;
int t, n, m;
char a[1100][1100];
void dfs(int x, int y) {
a[x][y] = '.';
if (x > 0 && a[x - 1][y] == '#') dfs(x - 1, y);
if (y > 0 && a[x][y - 1] == '#') dfs(x, y - 1);
if (x != n - 1 && a[x + 1][y] == '#') dfs(x + 1, y);
if (y != m - 1 && a[x][y + 1] == '#') dfs(... | ### 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;
inline int add(int a, int b) {
a += b;
return a >= 1000000007 ? a - 1000000007 : a;
}
inline int sub(int a, int b) {
a -= b;
return a < 0 ? a + 1000000007 : a;
}
inline int mul(int a, int b) { return (long long int)a * b % 1000000007; }
int Set(int N, int pos) { ret... | ### 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<bool> used;
int n, m;
vector<vector<char> > desk;
bool check(pair<int, int> v) {
if (v.first <= n - 1 && v.first >= 0) {
if (v.second <= m - 1 && v.second >= 0) {
return true;
}
}
return false;
}
void dfs(pair<int, int> v) {
used[v.first * m + v... | ### 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>
const int MOD = 998244353;
const int INF = 1e9 + 7;
using namespace std;
inline long long read();
int n, m;
bool col[1010], row[1010];
int pre[1010 * 1010];
bool vis[1010 * 1010];
char ch[1010][1010];
void init() {
for (int i = 0; i < 1010; i++) col[i] = 1, row[i] = 1;
memset(vis, false, si... | ### 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;
const int inf = 1000000007;
const long long INF = 1e18;
int mod = 998244353;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
... | ### 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;
const long long int N = 1e3 + 5, mod = 1e9 + 7;
int n, m, t, cr[N], cc[N];
pair<int, int> v[N * N];
char b[N][N];
bool check = true, visit[N * N];
map<pair<int, int>, int> pos;
vector<int> adj[N * N];
vector<vector<int>> cnc;
void dfs(int u) {
visit[u] = true;
cnc.back(... | ### 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;
const int maxn = 1000 + 10;
char mp[maxn][maxn];
int col[maxn], row[maxn];
int vis[maxn][maxn];
int dr[][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
int n, m, k;
int T;
bool ok(int x, int y) {
if (x >= 1 && x <= n && y >= 1 && y <= m) return true;
return false;
}
void dfs(int x, i... | ### 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;
char ch[2001][2001];
bool vis[2001][2001];
int Min[2][2001];
int Max[2][2001];
int emptyRows = 0;
int emptyCols = 0;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
int n, m;
void dfs(int x, int y) {
vis[x][y] = true;
for (int i = 0; i < 4; ++i) {
in... | ### 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;
using LL = long long int;
template <class TH>
void _dbg(const char *sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sd... | ### 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;
double pi = acos(-1);
long long power(long long a, long long b) {
long long p_res = 1;
while (b > 0) {
if (b % 2 == 1) {
p_res *= a;
b--;
}
a *= a;
b /= 2;
}
return p_res;
}
long long gcd(long long a, long long b) {
long long tmp;
whi... | ### 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 n, m;
string s[1005];
bool vis[1005][1004];
int rmst[1006][1005], lmst[1005][1005], umst[1005][1005], dmst[1004][1005];
bool rsat[1005], csat[1003];
void doit(long long i, long long j) {
if (i < 1 || i > n) return;
if (j < 1 || j > m) return;
if (vis[i][j]) ... | ### 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;
int n, m;
int a[1005][1005];
int col[1005], row[1005];
int main() {
cin >> n >> m;
bool emp = true;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == '#') {
a[i][j] = 1;
emp = false;
}
... | ### 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;
const long long N = 1e5 + 7;
long long n, m;
char g[1006][1006];
bool vis[1006][1006];
bool c[1006], r[1006];
int fix[4][2] = {1, 0, 0, 1, 0, -1, -1, 0};
bool ju(int x, int y) {
if (x < 0 || y < 0 || x >= n || y >= m || vis[x][y] == true || g[x][y] != '#')
return fals... | ### 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 long long maxn = 1010;
long long a[maxn][maxn];
char mm[maxn][maxn];
bool col[maxn], row[maxn];
bool vis[maxn][maxn];
long long nv[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
long long n, m;
void dfs(long long x, long long y) {
if (x < 1 || x > n || y < 1 || y > m) ... | ### 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;
const int N = 1e3 + 10, mo[] = {0, 1, 0, -1, 0};
int n, m, g[N][N];
int cnt[N], row, col;
char s[N];
int ans;
bool vis[N][N];
void dfs(int x, int y) {
vis[x][y] = 1;
for (int i = 0, xx, yy; i < 4; i++) {
xx = x + mo[i];
yy = y + mo[i + 1];
if (g[xx][yy] && !... | ### 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 s[1005][1005];
int main() {
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t, n, i, m, sum1, sum2, j;
cin >> n >> m;
sum1 = sum2 = 0;
char ch;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
cin >> ch;
if (ch == '#')
... | ### 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;
void print() { cout << "\n"; }
template <typename T, typename... Args>
void print(T a, Args... args) {
cout << a << " ";
print(args...);
}
long long llipowerp(long long x, long long y, long long p = LLONG_MAX) {
long long res = 1;
x = x % p;
while (y > 0) {
if... | ### 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;
const int N = 2e5 + 5;
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};
bool iS[1005];
bool jS[1005];
long long iT;
long long jT;
long long n, m, ans = 0;
string mat[1005];
bool vis[1005][1005];
void solve(int i, int j) {
if (vis[i][j]) return;
ans++;
queue<pair<... | ### 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;
long long power(long long a, long long b) {
long long res = 1;
a %= 1000000007;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007 % 1000000007;
a = a * a % 1000000007;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin... | ### 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;
char a[1001][1001];
long long int countcomp(long long int n, long long int m) {
set<pair<long long int, long long int> > s;
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < m; j++) {
if (a[i][j] == '#') s.insert(make_pair(i, j));
}
}... | ### 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;
char str[1100][1100];
long long n, m;
bool isValid() {
for (int i = 0; i < n; i++) {
bool bl = false;
for (int j = 0; j < m; j++) {
if (str[i][j] == '#' && !bl) {
bl = true;
continue;
}
if (str[i][j] == '#' && str[i][j - 1] == '.'... | ### 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;
const int MAXN = 1005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
char G[MAXN][MAXN];
int vis[MAXN][MAXN];
... | ### 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>
int n, m, t, la, ans = 0;
bool ok, hori_ok = 0, vert_ok = 0;
int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
char ch[1002][1002];
bool vis[1002][1002] = {};
template <class T>
void read(T &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') f |= (ch == '-'), ch = ... | ### 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;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int maxn = 1010;
int n, m, ans, dx[4] = {1,... | ### 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;
const long long MAXN = 1e3 + 7;
long long n, m, a[MAXN][MAXN], visited[MAXN][MAXN];
long long black_in_row[MAXN];
long long black_in_col[MAXN];
void dfs(long long i, long long j) {
if (a[i][j] == 0) return;
visited[i][j] = 1;
if (i + 1 < n && j < m && !visited[i + 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>
#pragma optimization_level 3
using namespace std;
long double TL = 1.0;
bool is_tl = 0;
long long CALLS = 0;
inline bool IS() {
if (++CALLS == 1000) {
CALLS = 0;
is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
}
return is_tl;
}
template <typename T1, typename T2>
inline void amin(... | ### 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;
int m, n;
char mp[2000][2000];
int vis[2000][2000];
int ran[2000][2000];
int r[2000];
int c[2000];
int nextx[4] = {0, 0, 1, -1};
int nexty[4] = {1, -1, 0, 0};
void dfs(int x, int y) {
vis[x][y] = 1;
mp[x][y] = '.';
for (int i = 0; i < 4; i++) {
int nx = x + nextx[... | ### 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;
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
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 = 1000000007;
void solve() {
int n, m;
cin >> n >> m;
vector<string> mat(n);
int tb = 0;
for (int i = 0; i < n; ++i) {
cin >> mat[i];
}
vector<vector<bool>> south_pos(n, vector<bool>(m, 1));
for (int r = 0; r < n; ++r) {
int st = -1... | ### 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;
void sorted(vector<int> arr) { sort(arr.begin(), arr.end()); }
void coutarr(vector<int> arr) {
int n = arr.size();
for (int i = 0; i < n; i++) cout << arr[i] << " ";
cout << endl;
}
void coutarr2(vector<vector<int>> arr) {
int n = arr.size();
for (int i = 0; i < n... | ### 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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e3 + 7;
const int inf = INT_MAX / 2;
const long long INF = LLONG_MAX / 3;
const int MOD = 998244353;
const long double eps = 1e-6;
const string cars[] = {"🚗", "🚕", "🚙"};
int n, m;
char a[... | ### 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;
const int N = 1010;
char s[N][N];
int vist[N][N], dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int judge1(int n, int m) {
int i, j, flag;
for (i = 1; i <= n; i++) {
flag = 0;
for (j = 2; j <= m; j++) {
if (s[i][j] == '.' && s[i][j - 1] == '#') flag = 1;
... | ### 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;
const int N = 2e5 + 10;
const int M = 1e9 + 7;
const int MOD = 998244353;
const double PI = 3.141592653589793238460;
long long int power(long long int a, long long int b) {
long long int res = 1;
if (a == 0) return 0;
if (a == 1) return 1;
for (; b > 0; b >>= 1) {
... | ### 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 mod(int a, int b) { return a >= 0 ? a % b : (b + a % b) % b; }
int dceil(int a, int b) { return (a + b - 1) / b; }
int n, m;
char tab[1010][1010];
int di[4] = {0, 0, -1, 1};
int dj[4] = {-1, 1, 0, 0};
bool dfs(int i, int j) {
if (i >= 0 && i < n && j >= 0 && j < m && ... | ### 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;
const long long mod = 1e9 + 7;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, -1, 1};
long long n, m;
char a[1002][1002], vis[1002][1002];
void dfs(long long x, long long y) {
vis[x][y] = 1;
for (long long i = 0; i < 4; i++) {
long long x1 = x + dx[i], y1 =... | ### 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.