text
stringlengths
49
983k
#include <bits/stdc++.h> #pragma warning(disable : 4996) template <typename T> T min(T x, T y) { return x < y ? x : y; } template <typename T> T max(T x, T y) { return x > y ? x : y; }; const long long INF = 20000000050000; const long long mod = 998244353; const long long MAXN = 205; int N; char s[MAXN][MAXN]; void...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; char ch[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> ch[i][j]; int co = 0; pair<i...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int N; cin >> N; int a[N][N]; for (int i = 0; i < N; i++) { string s; cin >> s; for (int j = 0; j < s.size(); j++) a[i][j] = s[j] - '0'; } vector<pair<int, int>> targets; targets...
#include <bits/stdc++.h> using namespace std; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } char mat[201][201]; int main() { fast(); int n, t; bool p, q; cin >> t; for (int cas = 0; cas < t; cas++) { int x = 0; q = p = false; cin >> n; for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; char m[n][n]; for (long long int i = (0); i < (n); i++) { for (long long int j = (0); j < (n); j++) cin >> m[i][j]; } if (m[0][1] == '0' and m[1][0] == '0') { if (m[n - 2][n - 1] == '0' and m[n - 1][n - 2] == '0'...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; char a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } vector<pair<long...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; char a[n + 1][n + 1]; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { c...
#include <bits/stdc++.h> using namespace std; int tryFirstState(vector<vector<char> > &a, int n) { int sol = 0; vector<vector<int> > ans(5, vector<int>(2, 0)); if (a[1][0] != '0') { ans[sol][0] = 2; ans[sol][1] = 1; sol++; } if (a[0][1] != '0') { ans[sol][0] = 1; ans[sol][1] = 2; sol++...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; char g[n][n]; bool vis[n][n]; for (int i(0); i < n; i++) { for (int j(0); j < n; j++) { cin >> g[i][j]; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<string> grid(n); for (auto &it : grid) cin >> it; vector<array<int, 2>> pos = { {0, 1}, {1, 0}, {n - 1...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { int i, j, k, m, n, l, res = 0, zero = 0, one = 0, a, b, c, d; cin >> n; vector<pair<int, int> > v; string s[n + 1]; for (i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; const long long INF64 = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int chu; cin >> chu; while (chu--) { long long int n; cin >> n; string s[n]; for (long long int i = 0; i < n; i++) cin >> s[i]; ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; char g[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> g[i][j]; } int a = 0, b = 1, c = n - 1, d = n - 2; if (g[a][b] == g[b][a] && g[c][d] == g[d][c]) { if (g[a][b] != g[c][d]) { cout << 0 ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; char a[n][n]; for (long long i = 0; i < n; i++) { for (long long j = 0; j < n; j++) cin >> a[i][j]; } vector<pair<long long, long long>> v; if (a[0][1] == a[1][0]) { if (a[n - 2][n - 1] == a[0][1]) v.push_back({n -...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; char arr[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> arr[i][j]; } char temp = arr[0][1]; vector<pair<int, int>> v; if (arr[1][0] != temp) v.push_back({2, 1}); if (arr[n - 1][n - 2] == temp) v....
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; char a[n][n]; for (long long i = 0; i < n; i++) for (long long j = 0; j < n; j++) cin >> a[i][j]; long long z = 0, o = 0, z2 = 0, o2 = 0; if (a[0][1] == '0') z++; if (a[1][0] == '0') z++; if (a[0][1] == '1') o++; i...
#include <bits/stdc++.h> using namespace std; const int number = 1000000; int isprime[number + 2] = {0}; long long expo(long long x, long long y, long long m) { long long p = 1; while (y > 0) { if (y % 2 == 1) p = p * x % m; x = x * x % m; y = y / 2; } return (p % m); } void sieve() { isprime[0] =...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } void OJ() {} const lon...
#include <bits/stdc++.h> using namespace std; void sol() { long long n; cin >> n; char a; long long flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a; if (i == 0 && j == 1) { if (a == '1') flag1++; } if (i == 1 ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 40; vector<int> used(N, 0); void solve() { int n; cin >> n; char a[n + 2][n + 2]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; } } int b1; b1 = (a[n - 1][n] == '1') + (a[n][n - 1] == '1'); in...
#include <bits/stdc++.h> using namespace std; char _grid[300][300], grid[300][300]; long long vis[300][300]; long long n, m; long long di[] = {0, 0, -1, 1}; long long dj[] = {-1, 1, 0, 0}; bool isPos(long long i, long long j) { return (i >= 0 and j >= 0 and i < n and j < n and !vis[i][j]); } void dfs(long long i, lon...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long t; cin >> t; long long n; long long ans = 0; long long f1 = 0, f2 = 0; while (t--) { f1 = f2 = 0; ans = 0; cin >> n; string s = ""; string t = ""; for (long long i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; char mp[205][205]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> mp[i][j]; } } queue<pair<int, int>> q; if (mp[2][1] == mp[1][2]) { if...
#include <bits/stdc++.h> using namespace std; const long long N = 205; char a[N][N]; void Main() { long long n; cin >> n; for (long long i = 1; i <= n; i++) for (long long j = 1; j <= n; j++) { cin >> a[i][j]; } vector<pair<long long, long long> > res; if (a[1][2] == a[2][1]) { char c = a[1]...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> foo(string table[], int n, char character) { vector<pair<int, int>> result(0); char ch = character; if (table[n - 1][n - 3] != ch) result.push_back({n - 1, n - 3}); if (table[n - 2][n - 2] != ch) result.push_back({n - 2, n - 2}); if (table[n...
#include <bits/stdc++.h> using namespace std; bool isprime(int64_t n) { for (int64_t i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } int64_t factorial(int64_t n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } int64_t gcd(int64_t a, int64_t b) { if (a == 0)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, n; cin >> t; while (t--) { cin >> n; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } if (s[0][1] == s[1][0]) { if (s[n - 1][n - 2] == s[n - 2...
#include <bits/stdc++.h> const long long INF = 1e18; const long long mod = 1e9 + 7; using namespace std; void solve() { long long n; cin >> n; vector<vector<char>> vec(n, vector<char>(n)); for (long long i = 0; i < n; i++) { for (long long j = 0; j < n; j++) { cin >> vec[i][j]; } } long long a...
#include <bits/stdc++.h> using namespace std; inline int rd() { int x = 0; bool f = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c ^ 48); c = getchar(); } return f ? -x : x; } int a[307][307]; inline void work() { ...
#include <bits/stdc++.h> using namespace std; long long i, i1, j, k, k1, t, n, m, res, flag[10], a, b, mt[210][210], f[210]; char x; vector<array<long long, 2>> sl; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n; sl.clear(); for (i = 1; i <= n; i++) { for (j...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 2e9 + 5; double PI = 3.14159265358979323846; void solve() { int n; cin >> n; char c[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> c[i][j]; } } vector<pair<int,...
#include <bits/stdc++.h> using namespace std; const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; template <typename T_n> void read(T_n &n) { cin >> n; } template <typename T_n, typename T_a> void read(T_a a[], T_n n...
#include <bits/stdc++.h> using namespace std; long long int mod(long long int x) { if (x >= 0) { return x; } return -x; } vector<int> decToBinary(int n) { vector<int> binaryNum(32, 0); int i = 0; while (n > 0) { binaryNum[i] = n % 2; n = n / 2; i++; } return binaryNum; } void solve(vecto...
#include <bits/stdc++.h> using namespace std; bool db = false; const long long INF = 1e18 + 100; const long long MOD = 1e9 + 7; const long long maxn = 2 * 1e6 + 1; long long t, n, m, x, k, q; long long a, b, c, d; pair<long long, long long> pa, pb, pc, pd; long long ans = 0; string s[200]; vector<pair<long long, long l...
#include <bits/stdc++.h> using namespace std; bool check(vector<vector<int>> &a, int n, int x) { deque<pair<int, int>> q; map<pair<int, int>, bool> was; q.push_back({1, 1}); was[{1, 1}] = true; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; while (!q.empty()) { auto u = q.front(); q.pop_front...
#include <bits/stdc++.h> using namespace std; const long long int INF = 2e18; const long long int N = 2e5 + 5; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j, c; char chr; cin >> t; bool first_diag, second_diag; while (t--) { cin >> n; string arr[n]; vector<int> v; c = 0; for (i = 0; i < n; i++) cin >> arr[i]; first_diag = (arr[0][1] == arr[1][0]); second_diag = (...
#include <bits/stdc++.h> using namespace std; long long int n; vector<string> a; void input() { a.clear(); cin >> n; for (int i = 0; i < n; i++) { string k; cin >> k; a.push_back(k); } } void solve() { long long int z = 0, o = 0; if (a[0][1] == '0') z++; else o++; if (a[1][0] == '0')...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double pii = 2 * pi; const double eps = 1e-6; const long long MOD = 1e9 + 7; vector<pair<int, int>> del{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; bool dfsf(int n, vector<string>& g) { vector<vector<bool>> v(n, vector<bool>(n, true)); queue<p...
#include <bits/stdc++.h> using namespace std; long long maxi = LLONG_MAX; long long mini = LLONG_MIN; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { fast(); long long t; cin >> t; while (t--) { long long n; cin >> n; char a[n][n]; for (long long i = 0; i < n; i...
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e18; const long long minN = -1e18; const int INF = 2e9; const long long MOD = 1e9 + 7; const long long MOD1 = 998244353; const int baseHash = 331; const int bigNumLength = 5000; const long double PI = acos(-1); const long long limit = 2e5 + 5; const ...
#include <bits/stdc++.h> using namespace std; int t, n; char s[207][207]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> s[i][j]; } } int cnt0 = 0, cnt1 = 0; if (s[1][2] == '0') { cnt0++; } else { ...
#include <bits/stdc++.h> using namespace std; char s[205][205]; int main() { long long a, b, t, n, m, i, j; cin >> t; while (t--) { cin >> n; cin.get(); for (i = 0; i <= n; i++) for (j = 0; j <= n; j++) s[i][j] = '0'; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) cin >> s[i][j]; ...
#include <bits/stdc++.h> using namespace std; template <class A> void read(vector<A>& v); template <class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d = stod(t); } void read(long double& d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H& h, ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100001; const int MAX_D = 17; const long long MOD = 1000000007; const int INF32 = 0x3f3f3f3f; const long long INF = 1e18; void solve() { int n; cin >> n; char grid[n][n]; for (int i = (0); i < (n); i++) for (int j = (0); j < (n); j++) cin >> gr...
#include <bits/stdc++.h> using namespace std; using LL = long long; inline void solve() { int n; cin >> n; char A[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> A[i][j]; } } bool top = false; bool bottom = false; if (A[1][0] == A[0][1]) { top = true; } if...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char s[n + 1][n + 1]; for (int i = 1; i <= n; ++i) cin >> s[i] + 1; vector<pair<int, int>> ans; if (s[1][2] == s[2][1]) { if (s[n][n - 1] == s[1][2]) ans.push_back(pair<int, int...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char fi[n][n]; for (int i = 0; i < (n); ++i) { for (int j = 0; j < (n); ++j) { cin >> fi[i][j]; } } int a = fi[0][1] - '0'; int b =...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long T = 1; cin >> T; while (T--) { long long n; cin >> n; char a[n][n]; for (long long i = 0; i < n; i++) for (long long j = 0; j < n; j++) cin >> a[i][j];...
#include <bits/stdc++.h> using namespace std; void solve() { long long n = 0; cin >> n; vector<vector<long long>> arr(n, vector<long long>(n)); for (long long i = 0; i < n; i++) { string s; cin >> s; for (long long j = 0; j < n; j++) { for (long long j = 0; j < n; j++) arr[i][j] = s[j] - '0'; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char arr[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> arr[i][j]; } } vector<pair<int, int>> vec; if (arr[0][1] == arr[1][0]) { ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int T; int n, i, j; char num[300][300]; cin >> T; while (T--) { cin >> n; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { cin >> num[i][j]; } } int cnt = 0; cnt = num[2][1] + num[1][2...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000002; const int MOD2 = 998244353; const int MOD = 1000000007; const int INF = 1e8; const long double EPS = 1e-7; long long int mul(long long int x, long long int y) { return (x * 1ll * y) % MOD; } long long int fastpow(long long int x, long long int y)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) { int n, m, i, x = 0, y, z; cin >> n; string s[n + 1]; for (int i = 0; i < n; i++) cin >> s[i]; vector<pair<int, int>> v; if (s...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; ll fac[1000001]; void pre() { fac[0] = fac[1] = 1; for (int i = 2; i <= 1000001; i++) { fac[i] = (fac[i - 1] * 1LL * i) % mod; } } ll binpower(ll a, ll n) { ll res = 1; while (n) { if (n % 2) res = (res * 1LL *...
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") using namespace std; using ll = long long; using ld = long double; const int N = 2e5 + 7, mod = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t, n, i, j, y, ans; string s; char ch; cin >> t; while (t--) { cin >> n; vector<int> a(4); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { c...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n, p, i, c, d, e, f, q = 0, r = 0, l = 0, m = 0; cin >> n; p = n * n; for (i = 0; i < p; i++) { char s; cin >> ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tests; cin >> tests; while (tests--) { int n; cin >> n; vector<vector<char>> t(n); char c; for (auto& i : t) { for (int j = 0; j < n; ++j) { cin >> c; ...
#include <bits/stdc++.h> using namespace std; int main() { int testcase; cin >> testcase; for (int i = 0; i < testcase; i++) { int size; cin >> size; char map[size][size]; for (int j = 0; j < size; j++) { for (int k = 0; k < size; k++) { cin >> map[j][k]; } } char start...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6 + 9; const int INF = (int)1e9 + 7; int mod = (int)1e9 + 7; string tab[209]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> tab[i]; char a0 = tab[0][1], a1 = tab[1][0]; char b0 = tab[n - 1][n - 2], b1 = tab[n - 2][n - 1...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; string s[n]; for (long long i = 0; i < n; i++) { cin >> s[i]; } vector<pair<long long, long...
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } const long long M = 210; long long n,...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; char a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> a[i][j]; } int w, x, y, z, cnt = 0, ans[4]; w = a[0][1]; x = a[1][0]; y = a[n - 1][n - 2]; z = a[n - 2][n - 1]; if (w == x) { if (y =...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 205; int n, ans, T; char a[maxn][maxn]; int main() { cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cin >> a[i][j]; } int p1 = a[1]...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T a) { return a * a; } template <class T> T abs(T x) { if (x < 0) return -x; return x; } const double eps = 1e-8; const double pi = acos(-1.0); struct node { int x, y, val; }; char str[210][210]; vector<node> vec; int main() { int tks, ks ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<string> arr(n); for (long long i = 0; i < n; i++) cin >> arr[i]; char sa = arr[0][1], sb = arr[1][0], fa = arr[n - 1][n - 2], fb = arr[n - 2][n - 1]; v...
#include <bits/stdc++.h> using namespace std; int solve() { int n; cin >> n; vector<vector<char>> gr(n, vector<char>(n)); vector<vector<int>> g(n, vector<int>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> gr[i][j]; } } for (int i = 0; i < n; i++) { for (int j = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, i, j, count = 0; cin >> n; char ch[n + 1][n + 1]; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { cin >> ch[...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long int ceil(long long int a, long long int b) { if ((a >= 0 && b >= 0) || (a < 0 && b < 0)) return (a / b) + ((a % b) != 0); return a / b; } long long int floor(long long int a, long long int b) { if ((a >= 0 && b >= 0) || (a < 0 && b <...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); } long long int Modular_Exponentiation(long long int x, long long int n, long long int M) { if (n == 0) return 1; if (n % 2) return ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; for (int p = 1; p <= t; p++) { int n, z; cin >> n; vector<vector<int>> grid(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string arr[n]; for (long long int i = 0; i < n; i++) cin >> arr[i]; char s1 = arr[0][1]; char s2 = arr[1][0]; char e1 = arr[n - 2][n - 1]; char e2 = arr[n - 1][n - 2]; if ...
#include <bits/stdc++.h> using namespace std; bool isrange(int second, int first, int n, int m) { if (0 <= second && second < n && 0 <= first && first < m) return true; return false; } int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1}, ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int i, n, t, j = 0, p, x, a = 0, b, l = 0, r = 0, y, k, c, sum = 0, m, d, cnts = 0; cin >> t; while (t--) { cin >> n; char s[n][n]; for (i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; void testCase() { long long n; cin >> n; vector<string> grid(n); vector<pair<long long, long long>> ans; for (string &s : grid) cin >> s; if (grid[0][1] == grid[1][0]) { if (grid[n - 1][n - 2] == grid[0][1]) ans.push_back({n - 1, n - 2}); if (grid[n - 2]...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << " " << a.second; return out; } t...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long ll_scan() { long long x; cin >> x; return x; } string str_scan() { string x; cin >> x; return x; } int main() { long long t = 1, T = 1; t = ll_scan(), T = t; while (t--) { long long n = ll_scan(); vector<str...
#include <bits/stdc++.h> using namespace std; void testcase() { int n, chng = 0; cin >> n; vector<string> a(n); vector<pair<int, int>> b; for (int i = 0; i < n; i++) cin >> a[i]; if (a[0][1] == a[1][0]) { if (a[n - 1][n - 2] == a[n - 2][n - 1]) { if (a[n - 1][n - 2] != a[0][1]) { cout << 0...
#include <bits/stdc++.h> using namespace std; const long long oo = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; vector<vector<long long> > grid; long long n; void doTest() { cin >> n; grid = vector<vector<long long> >(n, vector<long long>(n, 0)); for (long long i = (0); i < (n); i++) { string s; cin >> s;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 208; int n, mat[MAXN][MAXN]; vector<pair<int, int> > changes; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc; cin >> tc; while (tc--) { cin >> n; changes.clear(); for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; int t, n; vector<pair<int, int> > ho1, ho2; char a[207][207]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] + 1; } ho1.clear(); ho2.clear(); if (a[1][2] == '0') { ho1.push_back({1, 2}); ...
#include <bits/stdc++.h> using namespace std; template <class T> using TMatrix = vector<vector<T>>; template <class T> using TVector = vector<T>; using TString = string; template <class T1, class T2> using THashMap = unordered_map<T1, T2>; void read(int& x) { scanf("%i", &x); } void write(const int x) { printf("%i", x)...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { T data = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { data = (data << 3) + (data << 1) + ch - '0'; ch = getchar(); } x = f * ...
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; for (long long i = 0; i < a; i++) { long long b; cin >> b; string s[b + 1]; for (long long j = 0; j < b; j++) { cin >> s[j]; } vector<pair<long long, long long>> ans; if (s[0][1] == s[1][0]) { ...
#include <bits/stdc++.h> using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); } int main() { long long int t; cin >> t; while (t--) { int n; cin >> n; char a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a...
#include <bits/stdc++.h> using namespace std; pair<int, int> pos[10] = {make_pair(1, 2), make_pair(2, 1), make_pair(-1, 0), make_pair(0, -1)}; int main() { cin.tie(0); ios::sync_with_stdio(0); int t; cin >> t; while (t--) { int n; cin >> n; char c; int up = 0, down = ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; vector<vector<char>> a(n, vector<char>(n)); vector<int> ans1; vector<int> ans2; int res = 0; for (int x = 0; x < n; x++) for (int y = 0; y < n; y++) cin >> a...
#include <bits/stdc++.h> using namespace std; bool cmp(const pair<int, int> &left, const pair<int, int> &right) { return left.first > right.first || (left.first == right.first && left.second < right.second); } int main() { int t, cs = 1; cin >> t; while (t--) { int n, m, a, b, c, i, j, k, mx = 0, m...
#include <bits/stdc++.h> using namespace std; int T, n, res, a1, a2, a3, a4; char s[210][210]; bool check(char x, char y) { res = (s[1][2] == y) + (s[2][1] == y) + (s[n][n - 1] == x) + (s[n - 1][n] == x); if (res <= 2) { printf("%d\n", res); if (s[1][2] == y) printf("1 2\n"); if (s[2][1] == y) pri...
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int t = 1; cin >> t; while (t--) { int n; cin >> n; char a[n][n]; for (int i = 0; i < n; i...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string m[n]; for (int i = 0; i < n; i++) cin >> m[i]; char a = m[1][0], b = m[0][1], c = m[n - 1][n - 2], d = m[n - 2][n - 1]; if (a == b && c == d) { if (a == c) cout <...
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b) { long long res = 1; while (b != 0) { if (1 & b) res *= a; b >>= 1; a *= a; } return res; } void solve() { long long n, m; cin >> n; long long a, b, c, d, temp; string s; for (long long i = 1; i < n + ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n; cin >> n; char arr[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> arr[i][j]; } vector<pair<int, int>> ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double Pi = acos(-1); namespace { template <typename T> inline void read(T &x) { x = 0; T f = 1; char s = getchar(); for (; !isdigit(s); s = getchar()) if (s == '-') f = -1; for (; isdigit(s); s = getchar()) x = (x << 3) + (x ...
#include <bits/stdc++.h> using namespace std; int main() { long long int tc; cin >> tc; while (tc--) { long long int n; cin >> n; char ar[n + 1][n + 1]; for (long long int i = 0; i < n; i++) for (long long int j = 0; j < n; j++) cin >> ar[i][j]; long long int a, b, c, d; a = ar[0][1]...
#include <bits/stdc++.h> using namespace std; void solve() { int n; scanf("%d", &n); char ch[n + 1][n + 1], a, b, c, d, x; for (int i = 0; i < n; i++) { for (int j = 0; j < n; ++j) cin >> ch[i][j]; } a = ch[0][1]; b = ch[1][0]; c = ch[n - 1][n - 2]; d = ch[n - 2][n - 1]; if (a == b && c != d) { ...
#include <bits/stdc++.h> using namespace std; int vis[301][300]; char str[300][300]; int main() { int t; cin >> t; while (t--) { int n, x, y, k = 1, sum = 0; bool sign = false; memset(vis, 0, sizeof(vis)); scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; char mat[201][201]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> mat[i][j]; int a = mat[0][1] - '0'; int...
#include <bits/stdc++.h> #pragma GCC optimize "trapv" using namespace std; const int N = 1e5 + 5; const unsigned int M = 1000000007; long long a[N], b[N]; char invert(char x) { if (x == '0') return '1'; else return '0'; } void solve() { int n; cin >> n; char a[n][n]; vector<pair<int, int>> ans; fo...