output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; struct A { char a[500005]; int n, m; char& at(const int& x, const int& y) { return a[x * m + y]; } } ma; int main() { int i, j, n, m; scanf("%d%d", &n, &m); ma.n = n; ma.m = m; char str[500005]; for (i = 0; i < n; ++i) { scanf(...
### Prompt Construct a cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; const int N = 500100, mod = 1e6 + 3; inline int read() { int x = 0, c = getchar(), f = 0; for (; c > '9' || c < '0'; f = c == '-', c = getchar()) ; for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0'; return f ? -x : x; } char a[N]; int...
### Prompt Please create a solution in cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const bool debug_output = false; const int module = 1000003; vector<vector<char> > data; vector<int> hor, vert; int n, m; int main() { scanf("%d %d\n", &n, &m); data.resize(n); hor.assign(n, -1); vert.assign(m, -1); for (int i = 0; i < n; i++, scanf("\n")) { d...
### Prompt Please provide a cpp coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return {i, j}; } struct printer { ~printer() { cerr << endl; } template <class c> printer& operator,(c x) { cerr << boolalpha << x; return *this; } printer& operator...
### Prompt Please create a solution in Cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; int n, m; char s[MAXN + 1]; vector<int> v[MAXN]; bool hasLeft(int c) { return c == 1 || c == 2; } bool hasRight(int c) { return c == 3 || c == 4; } bool hasUp(int c) { return c == 1 || c == 4; } bool hasDown(int c) { return c == 2 || c == 3; } int g...
### Prompt Construct a CPP code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; void mytimer(string task) {} void ext(int c) {} bool was[2][510000][2]; char line[510000]; const int mod = 1000003; int main() { int n, m; cin >> n >> m; gets(line); for (int i = 0; i < (n); ++i) { gets(line); for (int j = 0; j < (m); ++j) { char c = l...
### Prompt Your challenge is to write a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; string a[510000]; int x1[510000]; int x2[510000]; bool z = true; int mod(int x1, int x2) { if (x1 == 0) return x2 + 1; if (x1 != x2 + 1) z = false; return x1; } int main() { cin.sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i <...
### Prompt Construct a Cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500000; char d[2 * MAXN + 10]; char *c[MAXN + 10]; int left(char x) { return x == '1' || x == '2'; } int up(char x) { return x == '1' || x == '4'; } const int MOD = 1000003; int main(void) { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < (n); ++...
### Prompt In Cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; int col[600000], row[600000]; int main() { int i, s = 0, in, j, l, n, m, h, v; long long sum; bool sw = true; string str; cin >> n >> m; memset(col, 0, sizeof col); memset(row, 0, sizeof row); for (i = 0; i < n; i++) { cin >> str; for (j = 0; j < m; ...
### Prompt Please formulate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; int htop[500010]; int hleft[500010]; string A[500010]; long long pw(long long a, long long p) { if (p == 0) return 1; long long x = pw(a, p / 2); long long ans = x * x; ans %= 1000003; if (p % 2 == 1) ans *= a; ans %= 1000003; return ans; } int main() { int ...
### Prompt Develop a solution in CPP to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> char graph[500010]; bool up[500010]; bool down[500010]; bool left[500010]; bool right[500010]; int main() { int n, m; scanf("%d %d", &n, &m); memset(up, false, sizeof(up)); memset(down, false, sizeof(down)); memset(left, false, sizeof(left)); memset(right, false, sizeof(right)); f...
### Prompt Generate a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...
#include <bits/stdc++.h> int n, m; char s[5 << 17], h[5 << 17][2], v[5 << 17][2]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n && scanf("%s", s); ++i) for (int j = 0; j < m; ++j) if (s[j] != '.') { int x = s[j] - '1'; v[i][(x < 2) ^ (j & 1)] = 1; h[j][(x > 0 && x < 3) ...
### Prompt Generate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...
#include <bits/stdc++.h> using namespace std; char BUF[500010]; int n, m; int up[500010], down[500010], LE[500010], RI[500010]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%s", &BUF); for (int j = 0; j < m; ++j) switch (BUF[j]) { case '1': if (j & 1) ...
### Prompt Generate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; struct A { char a[500005]; int n, m; char& at(const int& x, const int& y) { return a[x * m + y]; } } ma; int main() { int i, j, n, m; scanf("%d%d", &n, &m); ma.n = n; ma.m = m; char str[500005]; for (i = 0; i < n; ++i) { scanf(...
### Prompt Please create a solution in cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int mod = 1e6 + 3; int n, m; int main() { ios::sync_with_stdio(false); vector<string> a; string s; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s; a.push_back(s); } long long res = 1; for (int i = 0; i < n; i++) { int p = 0, q = 0; ...
### Prompt Please create a solution in cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int p = 1000003; int h[500001][2], v[500001][2]; char s[500005]; int main(void) { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%s", s + 1); for (int j = 1; j <= m; ++j) { if (s[j] == '.') continue; h[i][(j % 2) ^ (s...
### Prompt In cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000003; const int K = 5 * 1e5; const int M = 708; char maze[K + 10]; bool fnm; bool changNum(char ch[], int m) { int i, x = 0; for (i = 0; i < m; i++) { if (ch[i] != '.') { ch[i]--; ch[i] -= '0'; x++; } } return x == 0; } b...
### Prompt In CPP, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; const int MAXN = -1, MOD = 1000003; long long n, m; vector<string> board; long long Ans; int main() { while (cin >> n >> m) { Ans = 1; board.resize(n); for (int i = (0); i < (int)(n); i++) cin >> board[i]; for (int i = (0); i < (int)(n); i++) { bool ...
### Prompt Develop a solution in cpp to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; int n, m; vector<string> mat; vector<int> mkRow; vector<int> mkCol; int main() { cin >> n >> m; string t; int ans = 1; mkRow = vector<int>(n, 3); mkCol = vector<int>(m, 3); for (int i = 0; i < n; i++) { cin >> t; mat.push_back(t)...
### Prompt Please provide a Cpp coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000 + 3; int mypow(int n) { int ans = 1; for (int i = 0; i < n; ++i) { ans = (long long)ans * 2 % MOD; } return ans; } int main() { int n, m; cin >> n >> m; vector<string> grid(n); for (int i = 0; i < n; ++i) cin >> grid[i]; int cnt...
### Prompt Please create a solution in Cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> data; string str; for (int i = 0; i < n; ++i) { cin >> str; data.push_back(str); } int pw = m + n; for (int j = 0; j < m; ++j) { int flag = -1; for (int i = 0; i < n; ++i) { if (data[...
### Prompt Your challenge is to write a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000 + 3; int mypow(int n) { int ans = 1; for (int i = 0; i < n; ++i) { ans = (long long)ans * 2 % MOD; } return ans; } int main() { int n, m; cin >> n >> m; vector<string> grid(n); for (int i = 0; i < n; ++i) cin >> grid[i]; int cnt...
### Prompt Please provide a Cpp coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; vector<bool> a[600000]; vector<bool> b[600000]; int main() { memset(a, false, sizeof(a)); memset(b, false, sizeof(b)); char c; int n, m; scanf("%d%d\n", &n, &m); for (int i = 0; i <= n; i++) { for (int j = 0; j <= m + 1; j++) { a[i].push_back(false); ...
### Prompt Your task is to create a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, i...
#include <bits/stdc++.h> using namespace std; const int LIM = 710; vector<vector<int> > hor, ver; int n, m; void bye() { cout << 0 << endl; exit(0); } void fill_hor(int i, int j0, int t) { for (int j = 0; j < int(m); ++j) { int s = t * (abs(j0 - j) & 1 ? -1 : 1); if (hor[i][j] == 0) hor[i][j] = s; ...
### Prompt Create a solution in Cpp for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10, P = 1e6 + 3; int n, m; string s[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> s[i]; int ans = 1; for (int i = 0; i < n; ++i) { int tp = -1; for (int j = 0; j < m; ++j) { ...
### Prompt Construct a Cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; const int mod = 1e6 + 3; const int N = 600000; int a[N], ans = 1, n, m, x, y; char s[N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n + m; i++) a[i] = -1; bool pd = true; for (int i = 0; i < n; i++) { scanf("%s", s); for (int j = 0; j < m; j++) ...
### Prompt In cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; int rend[MAXN], cend[MAXN]; bool hasPipe[MAXN]; int PowerMod(int a, int n, int m) { int c = 1, d = a; while (n) { if (n & 1) c = (1LL * c * d) % m; d = (1LL * d * d) % m; n >>= 1; } return c; } bool Checkr(int r, int c, char ch) ...
### Prompt Please create a solution in cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; long long mod = 1000003; bool up(int k) { if (k == 0 || k == 1 || k == 4) return true; return false; } bool down(int k) { if (k == 0 || k == 2 || k == 3) return true; return false; } bool Right(int k) { if (k == 0 || k == 3 || k == 4) return true; return false; ...
### Prompt Construct a CPP code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<string> a(N); for (int i = 0; i < N; ++i) cin >> a[i]; vector<int> markh(N, 0), markv(M, 0); for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) { if (a[i][j] == '1' || a[i][j] == '2') markh[i] |...
### Prompt Generate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...
#include <bits/stdc++.h> using namespace std; int f[2][500005][2]; int main() { int n, m, i, j; char c; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { getchar(); for (j = 0; j < m; j++) { scanf("%c", &c); switch (c) { case '.': break; case '1': f[0][i][1...
### Prompt Please formulate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> const int Mod = 1000003; int n, m, fixed, prefix[500005], prerow[500005], fail; char pipe; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) { getchar(); int curtp, pretp, precol = 0; for (int j = 1; j <= m; ++j) { pipe = getchar(); if (!fail && pipe ...
### Prompt Please provide a Cpp coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; vector<string> A; string S; int main() { int M, N; cin >> M >> N; for (int i = 0; i < M; i++) { cin >> S; A.push_back(S); } int Ans = 1; for (int i = 0; i < M; i++) { bool Flag = true, T; for (int j = 0; j < N; j++) if (A[i][j] != '.') { ...
### Prompt Create a solution in CPP for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:255000000") bool firstout = 1; template <class T> void minn(T &a, T b) { if (b < a) a = b; } template <class T> void maxx(T &a, T b) { if (a < b) a = b; } int n, m; int A[501234]; char S[501234]; int main() { int i, j, k; char c; in...
### Prompt Please provide a CPP coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; const int max_size = 5E5; const int mod = 1E6 + 3; char *str[max_size + 1]; int res = 1; void cal(int n, int m, int type) { for (unsigned i = 0; i < n; i++) { int sign = 0; for (unsigned j = 0; j < m; j++) { int t; if (type == 0) { t = str[i][j...
### Prompt Please formulate a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e6 + 3; inline bool check(vector<int> &v, int st) { for (auto x : v) { if (x != -1 && x != st) return false; st ^= 1; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(32); int n, m; ...
### Prompt Create a solution in Cpp for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> char c[500010]; int a[500010][2], b[500010][2]; int main() { int n, m, i, j, mod = 1000003, ans; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%s", c); for (j = 0; j < m; j++) { if (c[j] == '1') { a[j][i % 2] = 1; b[i][j % 2] = 1; } else if (c...
### Prompt In CPP, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; vector<string> A; string S; int main() { int M, N; cin >> M >> N; for (int i = 0; i < M; i++) { cin >> S; A.push_back(S); } int Ans = 1; for (int i = 0; i < M; i++) { bool Flag = true, T; for (int j = 0; j < N; j++) if (A[i][j] != '.') { ...
### Prompt Your challenge is to write a Cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; int n, m, wyk, res, a; bool is[2]; int f2(int a) { if (a == 0 || a == 3) return 1; return 0; } int main() { scanf("%d %d", &n, &m); char s[n + 2][m + 2]; for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1); for (int i = 1; i <= n; i++) { is[0] = is[1] = false...
### Prompt Generate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...
#include <bits/stdc++.h> const int MOD = 1000003; bool A[2][500000][2]; int n, m, i, j, ans = 1; int main() { scanf("%d%d", &n, &m); for (char c; i < n; ++i) for (j = 0, getchar(); j < m; ++j) if ((c = getchar()) != '.') A[1][j][(i & 1) ^ (c == '1' || c == '4')] = true, ...
### Prompt Create a solution in CPP for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; const int MOD = 1000003; int n, m, c[MAXN] = {}, r[MAXN] = {}, fr, res = 1; int main() { cin >> n >> m; fr = m + n; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) { if (s[j] == '.') continue; ...
### Prompt Create a solution in Cpp for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& out, const vector<T>& data) { out << "["; for (int i = 0; i < data.size(); ++i) out << data[i] << " "; out << "]"; return out; } int moder = 1000003; int N, M; char a[1000000]; char& getc(int x, int y) { return a[x * M...
### Prompt Please formulate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int MaxN = 500000 + 5, MaxM = MaxN; const int Mod = 1000003; int N, M; int tx[MaxN], ty[MaxM]; const int tmpx[4] = {1, 0, 0, 1}; const int tmpy[4] = {1, 1, 0, 0}; int main() { memset(tx, -1, sizeof(tx)); memset(ty, -1, sizeof(ty)); scanf("%d%d ", &N, &M); char...
### Prompt Your task is to create a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, i...
#include <bits/stdc++.h> char s[500005]; int r[500005], c[500005], f[4][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", s + i * m); memset(r, -1, sizeof(r)); memset(c, -1, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0;...
### Prompt Please create a solution in CPP to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int MAXL = 500050; const int MOD = 1000003; char buf[MAXL]; bool f[2][MAXL][2]; void solved(int nT) { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%s", buf); for (int j = 0; j < m; ++j) { if (buf[j] == '.') continue; ...
### Prompt Construct a CPP code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> int n, m, ok = 1; int h[500010], v[500010]; void work(int line, int tip, int x, int y) { if (line == 0) { if (x % 2 == 0) tip = 1 - tip; if (h[y] == -1 || h[y] == tip) h[y] = tip; else ok = 0; } if (line == 1) { if (y % 2 == 0) tip = 1 - tip; if (v[x] == -1...
### Prompt Your task is to create a Cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, i...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:10000000") const long double LDINF = 9128739847123.00; const long double eps = 1e-9; const int inf = 1 << 28; const long double pi = fabsl(atan2l(0.0, -1.0)); using namespace std; int n, m; char **a; void load() { cin >> n >> m; a = new char *[n]; for (int ...
### Prompt Develop a solution in Cpp to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int M = 500000 + 10; char board[M]; int n, m; int MOD = 1000000 + 3; bool rowcheck(int row, string pattern) { bool rowcheck1 = true; for (int col = 0; col < m; col += 2) { char c = board[row * m + col]; if (c != '.' && c != pattern[0] && c != pattern[1]) {...
### Prompt In Cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> const int MAXN = 5 * 1e5 + 1; const int MOD = 1000003; int n, m; char *g[MAXN]; bool H[MAXN][5]; bool V[MAXN][5]; long long memof[MAXN][5]; long long memoh[MAXN][5]; long long f(int i, int prev) { if (i == m) return 1; long long &res = memof[i][prev]; if (res != -1) return res; res = 0;...
### Prompt Your challenge is to write a Cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; int n, m, result; string c[500005]; long long pw(long long a, long long b, long long d) { if (b == 0) return 1; if (b == 1) return a % d; long long temp = pw(a, b / 2, d); if (b % 2 == 0) return (temp * temp % d); else return (temp * temp * a % d); } inlin...
### Prompt Please provide a CPP coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, ans, f[500010], flag1, flag2; char s[500010], c[500010]; int o(int i, int j) { return (i - 1) * m + j; } int main() { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { scanf("%s", &s); for (j = 1; j <= m; j++) c[o(i, j)] = s[j - 1]; } ans = 1...
### Prompt Construct a cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500010; const int MO = 1000003; char g[MAXN]; int n, m; void init() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%s", g + m * i); } void ans_cal(int n) { int ans = 1, jie = 2; for (; n; n >>= 1) { if (n & 1) { ans = ((long l...
### Prompt Please formulate a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; vector<string> vs; int n, m; int calc(int x, int n) { if (n == 1) return x % 1000003; if (n == 0) return 1; int t = calc(x, n / 2); t = 1ll * t * t % 1000003; if (n & 1) return (t * x) % 1000003; return t; } int check() { for (int i = 0; i < (vs.size()); ++i) ...
### Prompt Construct a Cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> const int P = 1000003; bool f[2][500010][2]; int main() { char c; int i, j, m, n; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) for (getchar(), j = 1; j <= m; j++) if ((c = getchar()) != '.') { f[0][j][i % 2 ^ (c == '1' || c == '4')] = true; f[1][i][j % 2 ^ (...
### Prompt Create a solution in cpp for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; const int _N = 500010; const int MOD = 1000003; int n, m, row[_N], col[_N]; int main() { ios::sync_with_stdio(false); cin >> n >> m; memset(row, -1, sizeof(row)); memset(col, -1, sizeof(col)); bool flag = true; for (int i = 0; i < n; i++) for (int j = 0; j <...
### Prompt Construct a cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; char s[500010]; int n, m, ver[500010], hor[500010]; bool b; void calc(int i, int j, int k) { if (!b) return; int x = (k < 3) ? 1 : 2; if (j % 2) x = 3 - x; if (hor[i] == 0) hor[i] = x; else if (hor[i] != x) { b = false; return; } x = (k == 1 || k =...
### Prompt Please provide a cpp coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const int MOD = 1000003; int R, C; char *grid[600000]; int main() { scanf("%d%d", &R, &C); for (int i = (0); i < (R); i++) { grid[i] = new char[C + 5]; scanf("%s", grid[i]); } int res = 1; for (int i = (0...
### Prompt Construct a Cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; int detectX(char a) { if (a == '1' || a == '2') return 0; return 1; } int detectY(char a) { if (a == '1' || a == '4') return 1; return 0; } int n, m; char **state; int dp[1111111][4], achieve[1111111][4]; int main() { cin >> n >> m; state = new char *[m]; for ...
### Prompt Please formulate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> const int p = 1000003; int d[1000000][2], e[1000000][2]; int i, j, m, n, s; char c; int main() { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { getchar(); for (j = 1; j <= m; j++) { c = getchar(); if (c == '.') continue; d[i][((c == '1') || (c == '2')) ^ (j & 1)...
### Prompt Please formulate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); vector<vector<char>> a(n + 2, vector<char>(m + 2)); for (int i = 1; i <= n; i++) { scanf("%s", &a[i][1]); for (int j = 1; j <= m; j++) if (a[i][j] == '.') a[i][j] -= '.'; else a[i][j] ...
### Prompt Construct a CPP code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; char in[1000010]; int r[1000010]; int c[1000010]; int R[1000010][2]; int C[1000010][2]; int tp(int b) { int ret = 1; int M = 1000003; int i; for (i = 1; i <= b; i++) { ret = (ret * 2) % M; } return ret; } int main() { int i, n, m, j, I, II, J, JJ; scanf(...
### Prompt Your task is to create a Cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, i...
#include <bits/stdc++.h> using namespace std; const int MaxN = 500050; int g[MaxN]; char s[MaxN]; const int mod = 1000003; int T1(int x) { if (x == 1 || x == 2) return 0; return 1; } int T2(int x) { if (x == 1 || x == 4) return 0; return 1; } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i...
### Prompt In cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; char mp[501000]; int main() { int N, M; while (~scanf("%d%d", &N, &M)) { for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) scanf(" %c", &mp[i * M + j]); bool flag = true; int S = N + M; for (int i = 0; i < N; i++) { int p = -1; fo...
### Prompt Please formulate a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 10, Mod = 1e6 + 3; string s[MAXN]; int main() { ios::sync_with_stdio(false); int n, m, ans = 1; cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) { int odd = -1, even = -1; for (int j = 0; j < m; j++...
### Prompt Please provide a CPP coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; int countbit(int n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); } int lowbit(int n) { return (n ^ (n - 1)) & n; } const double pi = acos(-1.0); const double eps = 1e-11; template <class T> T sqr(T x) { return x * x; } template <class T> void checkmin(T &a, T b) {...
### Prompt In CPP, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; const long long M = 1000003, M2 = 500002; int n, m, poz_nr; long long wynik; char slowo[500005]; int nr[500005]; int dzialaj() { for (int i = 0; i < n; i++) { scanf("%s", slowo); poz_nr = 0; for (int j = 0; j < m; j++) { if (slowo[j] != '.') { if...
### Prompt Please provide a cpp coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; int m, n; vector<string> vs; int r, c; int f() { for (int i = 0; i < m; i++) { int leftOdd = 0, leftEven = 0, rightOdd = 0, rightEven = 0; bool found = false; for (int j = 0; j < n; j++) { if (isdigit(vs[i][j])) { found = true; if (j % 2)...
### Prompt Create a solution in Cpp for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; const int mod = 1E6 + 3; const int size = 5E5 + 1; char *str[size]; int main() { int n, m; cin >> n >> m; for (unsigned i = 0; i < n; i++) { str[i] = (char *)malloc(m + 1); cin >> str[i]; } int res = 1; for (unsigned i = 0; i < n; i++) { int sign = 0...
### Prompt Your task is to create a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, i...
#include <bits/stdc++.h> const int N = 5e5, mo = 1e6 + 3; int n, m, i, j, ans; bool h[N][2], l[N][2]; char s[N]; int main() { scanf("%d%d", &n, &m); ans = 1; for (i = 0; i < n; i++) for (scanf("%s", s), j = 0; j < m; j++) if (s[j] != '.') { int x = s[j] - 48; h[i][(x <= 2) ^ (j & 1)] = 1...
### Prompt Please create a solution in Cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; int n, m; int a[(1000 * 1000 + 1000)]; int b[(1000 * 1000 + 1000)]; int main() { cin >> n >> m; int valid = 1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { char x; cin >> x; if (x == '.') continue; if (...
### Prompt Your challenge is to write a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; const int mod = 1E6 + 3; const int size = 5E5 + 1; char *str[size]; int main() { int n, m; cin >> n >> m; for (unsigned i = 0; i < n; i++) { str[i] = (char *)malloc(m + 1); cin >> str[i]; } int res = 1; for (unsigned i = 0; i < n; i++) { int sign = 0...
### Prompt Please create a solution in cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int INF = 1001001001; const ll mod = 1000003; const ll INFL = 1001001001001001000; int main() { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < (h); i++) cin >> s[i]; int ans = 1; for (int i = 0; i < (h); i++) { ...
### Prompt Please formulate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int Mod = 1000003; bool check(const vector<vector<int> > &v, int n, int m) { for (int i = 0; i < n; ++i) { int x = -1, t; for (int j = 0; j < m; ++j) { t = v[i][j]; if (x == -1 && t < 0) continue; if (x == -1) x = (t & 2); if (t >= 0 ...
### Prompt Develop a solution in Cpp to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int> > a, used1, used2; set<int> q, w; int main() { scanf("%d%d", &n, &m); a.resize(n); used1.resize(n); used2.resize(n); int f = 0; for (int i = 0; i < n; ++i) q.insert(i); for (int i = 0; i < m; ++i) w.insert(i); for (int i = 0; i <...
### Prompt Your challenge is to write a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; vector<string> mat1; vector<string> mat2; int main() { int n, m; cin >> n >> m; string aux = ""; mat1.push_back(aux); for (int i = 1; i <= n; i++) { cin >> aux; aux = '#' + aux; mat1.push_back(aux); } for (int i = 1; i <= n; i++) for (int j = 1...
### Prompt In CPP, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> char state[500005]; int fix_point[500005]; int fix_cnt, cnt; int N, M, NM; bool func(int p, int a, int b, int f, bool is_first) { if (state[p] & (1 << (a + (f ^ 2)))) { printf("0\n"); return false; } else if (state[p] & (1 << (a + f))) { state[p] |= (1 << b); } else { if (...
### Prompt Generate a Cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...
#include <bits/stdc++.h> using namespace std; const int mod = 1E6 + 3; const int size = 5E5 + 1; char *str[size]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < (int)n; i++) { str[i] = (char *)malloc(m + 1); cin >> str[i]; } int res = 1; for (int i = 0; i < (int)n; i++) { int sign = 0...
### Prompt Your challenge is to write a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; int n, m, u, l, U[500005], L[500005]; string g[500005]; int x[] = {1, 1, 0, 0}; int y[] = {1, 0, 0, 1}; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> g[i]; memset(U, -1, sizeof U); memset(L, -1, sizeof L); for (int i = 0; i < n; i++) for (int ...
### Prompt Please formulate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; vector<int> a, b; int n, m, sol = 1; void read() { int i, j; char c; scanf("%d%d\n", &n, &m); for (i = 1; i <= n + 1; ++i) a.push_back(-1); for (i = 1; i <= m + 1; ++i) b.push_back(-1); for (i = 1; i <= n; ++i) { for (j = 1; j <= m; ++j) { scanf("%c", ...
### Prompt Please formulate a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; int H, W; int field[500001]; int line1[500001]; int line2[500001]; int M = 1000003; pair<int, int> f(int y, int d, int *line, int *next) { int ans = 0; int dec = 0; pair<int, int> ill(-1, 0); for (int x = 0; x < W; x++) { if (d == 0) { if (line[x] == 1) { ...
### Prompt Create a solution in cpp for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; const int inf(1010101010); int h, w; vector<string> a; inline int hsgn(int i, int j) { int r; if (a[i][j] == '1') r = 0; if (a[i][j] == '2') r = 0; if (a[i][j] == '3') r = 1; if (a[i][j] == '4') r = 1; return (r + j) % 2; } inline int vsgn(int i, int j) { int ...
### Prompt In Cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; const int dx44[5] = {0, -1, -1, 1, 1}; const int dy44[5] = {0, -1, 1, -1, 1}; const int dx4[5] = {0, -1, 0, 1, 0}; const int dy4[5] = {0, 0, 1, 0, -1}; const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1}; const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1}; const int maxn = 5e5...
### Prompt Create a solution in cpp for the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated a...
#include <bits/stdc++.h> using namespace std; char **ma; int ty[2][4] = {{1, 1, 0, 0}, {1, 0, 0, 1}}; int pow_mod(long long a, int p, int mod) { long long ret = 1; while (p) { if (p & 1) ret = ret * a % mod; a = a * a % mod, p >>= 1; } return ret; } int main() { int n, m, cnt; while (scanf("%d%d", &...
### Prompt Please formulate a Cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; int R, C; string grid[500090]; const long long mod = 1000003; bool mark[500090]; long long checkRow(int r) { for (int c = 0; c < (C + 1); ++c) mark[c] = 0; int cnt = 0; for (int c = 0; c < (C); ++c) { if (grid[r][c] != '.') ++cnt; if (grid[r][c] == '1' || grid...
### Prompt In CPP, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; int n, m; char s[500005]; bool row[500005], col[500005]; int main() { while (scanf("%d%d", &n, &m) == 2) { int i, j; for (i = 0; i < n; i++) scanf("%s", s + i * m); int tmp, st, turn; bool flag = true; for (i = 0; flag && i < n...
### Prompt Construct a Cpp code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; const int N = 500005; const int MOD = 1000003; int main() { int n, m, i, j, D; cin >> n >> m; D = m > n ? m : n; vector<string> s(D + 4); vector<int> ROW(D + 4, 0), COLUMN(D + 4, 0); for (i = 0; i < n; ++i) cin >> s[i]; for (i = 0; i < n; ++i) for (j = 0; ...
### Prompt In Cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:667772160") using namespace std; struct __isoff { __isoff() { if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); srand('C' + 'T' + 'A' + 'C' + 'Y' + 'M' + 'B' + 'A'); } ~__isoff() {} } __osafwf; const unsigned long long p1 ...
### Prompt Generate a cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...
#include <bits/stdc++.h> using namespace std; int n, m, data[500010], ans = 1, num; int f[500010][5]; int get(int a, int b) { return (a - 1) * b + b; } void end() { printf("0\n"); exit(0); } int main() { scanf("%d%d", &n, &m); char a; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { scanf...
### Prompt In Cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> #pragma comment(linker, "/stack=64000000") using namespace std; const int MOD = 1000003; int n, m; vector<string> a; vector<int> top, noname; long long powmod(long long a, long long b) { long long res = 1, d = a; while (b) if (b & 1) { res = (res * d) % MOD; b--; } else ...
### Prompt Please create a solution in Cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int N = 500005; const int MOD = 1000003; string s[N]; int n, m; int row[N][2], col[N][2]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < m; j++) { if (s[i][j] == '.') continue; row[i][(j & 1) ^ (s[i][...
### Prompt Your task is to create a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, i...
#include <bits/stdc++.h> using namespace std; vector<vector<char> > mm; vector<vector<int> > rr, cc; int n, m; const long long MOD = 1000003; long long powMod(long long a, long long b) { if (b == 0) return 1; else { long long tmp = powMod(a, b / 2); if (b % 2 == 0) return tmp * tmp % MOD; else...
### Prompt Develop a solution in CPP to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point(double x, double y) : x(x), y(y) {} point() { x = y = 0.0; } point operator+(point q) { return point(x + q.x, y + q.y); } point operator-(point q) { return point(x - q.x, y - q.y); } point operator*(double t) { return point(x * ...
### Prompt Please create a solution in cpp to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> char *a[500005] = {NULL}; int main() { long n, m, i, j; long ans = 1; long flag = 0; scanf("%ld%ld", &n, &m); for (i = 1; i <= n; i++) { a[i] = (char *)malloc(sizeof(char) * (m + 5)); a[i][0] = 0; } for (i = 1; i <= n; i++) scanf("%s", a[i] + 1); for (i = 1; i <= n; i++)...
### Prompt In cpp, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> const long long MOD = 1000003; long long vbar[500005]; long long hbar[500005]; int main() { long long N, M; std::cin >> N >> M; for (long long i = 0; i < N; i++) { for (long long j = 0; j < M; j++) { while (true) { char c = std::cin.get(); switch (c) { ...
### Prompt Your challenge is to write a Cpp solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; const int mod = int(1e6 + 3); vector<vector<int> > v; char second[600000]; int n, m; int main() { scanf("%d%d\n", &n, &m); v.resize(n); for (int i = 0; i < n; ++i) { gets(second); v[i].resize(m); for (int j = 0; j < m; ++j) { v[i][j] = (second[j] == ...
### Prompt Construct a CPP code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> using namespace std; int n, m, p1[555555][2], p2[555555][2], ans = 1; int main() { scanf("%d%d\n", &n, &m); char a[n + 3][m + 3]; for (int i = 0; i < n; i++) gets(a[i]); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (a[i][j] != '.') { int x = (a[i][j] < '2...
### Prompt Develop a solution in cpp to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> using namespace std; const int md = 1000000 + 3; char a[500010]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { char ch; while ((ch = getchar()) && ch != '.' && (ch < '0' || ch > '9')) ; a[i * m + j] = ...
### Prompt Construct a CPP code solution to the problem outlined: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrate...
#include <bits/stdc++.h> bool f[500010][2][2]; char str[500010]; int main() { int n, m; memset(f, 0x00, sizeof(f)); scanf("%d%d", &n, &m); getchar(); for (int i = 0; i < n; i++) { gets(str); for (int j = 0; j < m; j++) { switch (str[j]) { case '1': f[i][0][j & 1 ^ 1] = f[j][1][...
### Prompt Please provide a CPP coded solution to the problem described below: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to ...
#include <bits/stdc++.h> using namespace std; const int MX = 1000000; const int delta = 1000000 + 3; int row[MX], col[MX], n, m; char c; long long ans; void otp() { cout << 0 << endl; exit(0); } int main() { cin >> n >> m; memset(row, -1, sizeof(row)); memset(col, -1, sizeof(col)); for (int i = 0; i < n; i+...
### Prompt Please create a solution in CPP to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustr...
#include <bits/stdc++.h> char s[500005]; int r[500005]; int c[500005]; int f[4][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", s + i * m); memset(r, -1, sizeof(r)); memset(c, -1, sizeof(c)); for (int i = 0; i < n; i++) for (in...
### Prompt In CPP, your task is to solve the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated ...
#include <bits/stdc++.h> using namespace std; vector<string> mapa; string s; int main() { ios::sync_with_stdio(0); long long int n, m, fn = 0, fm = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s; mapa.push_back(s); } for (int i = 0; i < n; i++) { bool flag = false, left = true; for...
### Prompt Generate a CPP solution to the following problem: Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as ...