text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q = 1, i, j, test;
cin >> q;
for (test = 1; test < (q + 1); test++) {
long long n;
cin >> n;
char a[n][n];
for (i = 0; i < (n); i++)
for (j = 0; j < (n); j++) cin >> a[i][j];
vector<pair<int, int> > v;
int ans = 0;
if (a[0][1] == a[1][0]) {
if (a[n - 1][n - 2] == a[0][1]) ans++, v.push_back({n, n - 1});
if (a[n - 2][n - 1] == a[0][1]) ans++, v.push_back({n - 1, n});
} else if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[n - 1][n - 2] == a[0][1]) ans++, v.push_back({1, 2});
if (a[n - 2][n - 1] == a[1][0]) ans++, v.push_back({2, 1});
} else {
if (a[n - 1][n - 2] == '0') ans++, v.push_back({n, n - 1});
if (a[n - 2][n - 1] == '0') ans++, v.push_back({n - 1, n});
if ('1' == a[0][1]) ans++, v.push_back({1, 2});
if ('1' == a[1][0]) ans++, v.push_back({2, 1});
}
cout << ans << '\n';
for (i = 0; i < (ans); i++)
cout << v[i].first << " " << v[i].second << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long c = 0;
long long p1 = a[0][1] - '0', p2 = a[1][0] - '0';
long long q1 = a[n - 1][n - 2] - '0', q2 = a[n - 2][n - 1] - '0';
long long cnt1, cnt2;
cnt1 = abs(0ll - p1) + abs(0ll - p2) + abs(1ll - q1) + abs(1ll - q2);
cnt2 = abs(0ll - q1) + abs(0ll - q2) + abs(1ll - p1) + abs(1ll - p2);
if (cnt1 <= 2) {
cout << cnt1 << "\n";
if (p1 != 0) cout << "1 2\n";
if (p2 != 0) cout << "2 1\n";
if (q1 != 1) cout << n << " " << n - 1 << "\n";
if (q2 != 1) cout << n - 1 << " " << n << "\n";
} else {
cout << cnt2 << "\n";
if (p1 != 1) cout << "1 2\n";
if (p2 != 1) cout << "2 1\n";
if (q1 != 0) cout << n << " " << n - 1 << "\n";
if (q2 != 0) cout << n - 1 << " " << n << "\n";
}
}
}
|
#include <bits/stdc++.h>
char s[210][210];
int T, n;
int ansx[3], ansy[3], tot;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
tot = 0;
for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
if (s[1][2] == s[2][1]) {
if (s[1][2] == s[n - 1][n]) ansx[++tot] = n - 1, ansy[tot] = n;
if (s[1][2] == s[n][n - 1]) ansx[++tot] = n, ansy[tot] = n - 1;
} else if (s[n - 1][n] == s[n][n - 1]) {
if (s[1][2] == s[n - 1][n]) ansx[++tot] = 1, ansy[tot] = 2;
if (s[2][1] == s[n][n - 1]) ansx[++tot] = 2, ansy[tot] = 1;
} else {
ansx[++tot] = 1, ansy[tot] = 2;
if (s[n - 1][n] == s[2][1])
ansx[++tot] = n - 1, ansy[tot] = n;
else if (s[n][n - 1] == s[2][1])
ansx[++tot] = n, ansy[tot] = n - 1;
}
printf("%d\n", tot);
for (int i = 1; i <= tot; ++i) printf("%d %d \n", ansx[i], ansy[i]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 5;
int t, n;
char arr[N][N];
vector<pair<int, int>> ans;
void solve() {
ans.clear();
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> arr[i][j];
}
}
int zerocnt = 0, onecnt = 0, zerocnt2 = 0, onecnt2 = 0;
if (arr[1][3] == '0')
zerocnt++;
else
onecnt++;
if (arr[2][2] == '0')
zerocnt++;
else
onecnt++;
if (arr[3][1] == '0')
zerocnt++;
else
onecnt++;
if (arr[1][2] == '0')
zerocnt2++;
else
onecnt2++;
if (arr[2][1] == '0')
zerocnt2++;
else
onecnt2++;
if ((zerocnt == 3 || onecnt == 3) && (zerocnt2 == 2 || onecnt2 == 2)) {
if ((zerocnt == 3 && onecnt2 == 2) || (onecnt == 3 && zerocnt2 == 2)) {
cout << 0 << "\n";
return;
} else {
if (zerocnt == 3 && zerocnt2 == 2) {
ans.push_back({1, 2});
ans.push_back({2, 1});
} else if (onecnt == 3 && onecnt2 == 2) {
ans.push_back({1, 2});
ans.push_back({2, 1});
}
}
} else {
if (zerocnt > onecnt) {
if (zerocnt2 == 2) {
if (arr[1][3] == '0') ans.push_back({1, 3});
if (arr[2][2] == '0') ans.push_back({2, 2});
if (arr[3][1] == '0') ans.push_back({3, 1});
} else {
if (arr[1][3] == '1') ans.push_back({1, 3});
if (arr[2][2] == '1') ans.push_back({2, 2});
if (arr[3][1] == '1') ans.push_back({3, 1});
if (arr[1][2] == '0') ans.push_back({1, 2});
if (arr[2][1] == '0') ans.push_back({2, 1});
}
} else if (onecnt > zerocnt) {
if (onecnt2 == 2) {
if (arr[1][3] == '1') ans.push_back({1, 3});
if (arr[2][2] == '1') ans.push_back({2, 2});
if (arr[3][1] == '1') ans.push_back({3, 1});
} else {
if (arr[1][3] == '0') ans.push_back({1, 3});
if (arr[2][2] == '0') ans.push_back({2, 2});
if (arr[3][1] == '0') ans.push_back({3, 1});
if (arr[1][2] == '1') ans.push_back({1, 2});
if (arr[2][1] == '1') ans.push_back({2, 1});
}
}
}
cout << ans.size() << "\n";
for (auto p : ans) cout << p.first << " " << p.second << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
long long modPow(long long a, long long b);
long long modInv(long long a);
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> > x;
if (a[0][1] == a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] != a[n - 2][n - 1]) {
cout << 0 << "\n";
return;
} else {
cout << 2 << "\n";
cout << "1 2"
<< "\n"
<< "2 1"
<< "\n";
return;
}
}
if (a[0][1] == a[1][0]) {
if (a[n - 1][n - 2] == a[0][1])
x.push_back({n, n - 1});
else
x.push_back({n - 1, n});
cout << 1 << "\n";
cout << x[0].first << " " << x[0].second << "\n";
return;
}
if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[n - 1][n - 2] == a[0][1])
x.push_back({1, 2});
else
x.push_back({2, 1});
cout << 1 << "\n";
cout << x[0].first << " " << x[0].second << "\n";
return;
}
cout << 2 << "\n";
if (a[0][1] == '0')
cout << "1 2"
<< "\n";
if (a[1][0] == '0')
cout << "2 1"
<< "\n";
if (a[n - 1][n - 2] == '1')
cout << n << " " << n - 1 << "\n";
else
cout << n - 1 << " " << n << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long test = 1;
cin >> test;
while (test--) solve();
}
long long modPow(long long a, long long b) {
if (b == 0) return 1;
if (b % 2 == 0) {
long long x = a * a;
x %= 1000000007;
return modPow(x, b / 2);
}
return (a * modPow(a, b - 1)) % 1000000007;
}
long long modInv(long long a) { return modPow(a, 1000000007 - 2); }
|
#include <bits/stdc++.h>
namespace FastIO {
bool IOerror = 0;
inline char nc() {
static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
if (p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, 100000, stdin);
if (pend == p1) {
IOerror = 1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline bool read(T& x) {
bool sign = 0;
char ch = nc();
x = 0;
for (; blank(ch); ch = nc())
;
if (IOerror) return false;
if (ch == '-') sign = 1, ch = nc();
for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
if (sign) x = -x;
return true;
}
template <class T, class... U>
bool read(T& h, U&... t) {
return read(h) && read(t...);
}
}; // namespace FastIO
using namespace std;
using namespace FastIO;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a;
swap(a, m);
u -= t * v;
swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T>
class Modular {
public:
using Type = typename decay<decltype(T::value)>::type;
constexpr Modular() : value() {}
template <typename U>
Modular(const U& x) {
value = normalize(x);
}
template <typename U>
static Type normalize(const U& x) {
Type v;
if (-mod() <= x && x < mod())
v = static_cast<Type>(x);
else
v = static_cast<Type>(x % mod());
if (v < 0) v += mod();
return v;
}
const Type& operator()() const { return value; }
template <typename U>
explicit operator U() const {
return static_cast<U>(value);
}
constexpr static Type mod() { return T::value; }
Modular& operator+=(const Modular& other) {
if ((value += other.value) >= mod()) value -= mod();
return *this;
}
Modular& operator-=(const Modular& other) {
if ((value -= other.value) < 0) value += mod();
return *this;
}
template <typename U>
Modular& operator+=(const U& other) {
return *this += Modular(other);
}
template <typename U>
Modular& operator-=(const U& other) {
return *this -= Modular(other);
}
Modular& operator++() { return *this += 1; }
Modular& operator--() { return *this -= 1; }
Modular operator++(int) {
Modular result(*this);
*this += 1;
return result;
}
Modular operator--(int) {
Modular result(*this);
*this -= 1;
return result;
}
Modular operator-() const { return Modular(-value); }
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int>::value,
Modular>::type&
operator*=(const Modular& rhs) {
value = normalize(static_cast<int64_t>(value) *
static_cast<int64_t>(rhs.value));
return *this;
}
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
Modular>::type&
operator*=(const Modular& rhs) {
int64_t q = static_cast<int64_t>(static_cast<long double>(value) *
rhs.value / mod());
value = normalize(value * rhs.value - q * mod());
return *this;
}
template <typename U = T>
typename enable_if<!is_integral<typename Modular<U>::Type>::value,
Modular>::type&
operator*=(const Modular& rhs) {
value = normalize(value * rhs.value);
return *this;
}
Modular& operator/=(const Modular& other) {
return *this *= Modular(inverse(other.value, mod()));
}
template <typename U>
friend const Modular<U>& abs(const Modular<U>& v) {
return v;
}
template <typename U>
friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename U>
friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename U>
friend std::istream& operator>>(std::istream& stream, Modular<U>& number);
private:
Type value;
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long INF = 0x3f3f3f3f;
const long long N = 333;
char a[N][N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, i, j;
cin >> n;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) cin >> a[i][j];
long long ans = 0;
vector<pair<long long, long long> > res;
if (a[1][2] == a[2][1] && a[1][2] == a[n][n - 1] &&
a[1][2] == a[n - 1][n]) {
ans = 2;
res.push_back(make_pair(1, 2));
res.push_back(make_pair(2, 1));
}
if (a[1][2] != a[2][1]) {
ans++;
if (a[n - 1][n] == a[n][n - 1] && a[2][1] == a[n][n - 1]) {
res.push_back(make_pair(2, 1));
a[2][1] = a[1][2];
} else {
res.push_back(make_pair(1, 2));
a[1][2] = a[2][1];
}
}
if (a[n - 1][n] != a[n][n - 1]) {
ans++;
if (a[n][n - 1] == a[1][2])
res.push_back(make_pair(n, n - 1));
else
res.push_back(make_pair(n - 1, n));
}
cout << ans << endl;
for (i = 0; i < ans; i++)
cout << res[i].first << " " << res[i].second << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maax = 300001;
const long long mod = 998244353;
long long prime[maax];
long long fact[maax];
long long inv[maax];
long long nCr(long long n, long long r) {
return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
void make() {
prime[1] = 1;
for (long long i = 2; i < (long long)maax; i++) {
if (!prime[i]) {
for (int j = i + i; j < maax; j += i) prime[j] = 1;
}
}
fact[0] = 1;
for (long long i = 0; i < (long long)maax; i++) {
fact[i] *= fact[i - 1];
if (fact[i] > mod) fact[i] %= mod;
}
}
long long power(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % mod;
y >>= 1;
x = (x * x) % mod;
}
return res;
}
long long inverse(long long a) { return power(a, mod - 2); }
bool findpath(vector<vector<char> > &v, int a, int b, vector<vector<int> > vis,
char c) {
if (a < 0 || b < 0 || a >= v.size() || b >= v.size() || vis[a][b]) return 0;
if (v[a][b] == 'F') {
return 1;
}
if (v[a][b] != c) return 0;
vis[a][b] = 1;
int ans = 0;
ans |= findpath(v, a - 1, b, vis, c);
if (ans) return ans;
ans |= findpath(v, a + 1, b, vis, c);
if (ans) return ans;
ans |= findpath(v, a, b - 1, vis, c);
if (ans) return ans;
ans |= findpath(v, a, b + 1, vis, c);
vis[a][b] = 0;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<vector<char> > v(n, vector<char>(n));
for (long long i = 0; i < (long long)n; i++) {
for (long long j = 0; j < (long long)n; j++) cin >> v[i][j];
}
int z1 = 0;
int z2 = 0;
if (v[0][1] == '0') z1++;
if (v[1][0] == '0') z1++;
if (v[n - 1][n - 2] == '0') z2++;
if (v[n - 2][n - 1] == '0') z2++;
vector<pair<long long, long long> > ans;
if (z1 == 2) {
if (z2 == 2) {
ans.push_back({n - 1, n - 2});
ans.push_back({n - 2, n - 1});
} else if (z2 == 1) {
if (v[n - 1][n - 2] == '0')
ans.push_back({n - 1, n - 2});
else
ans.push_back({n - 2, n - 1});
}
} else if (z1 == 1) {
if (z2 == 2) {
if (v[0][1] == '0')
ans.push_back({0, 1});
else
ans.push_back({1, 0});
} else if (z2 == 1) {
if (v[0][1] == '0')
ans.push_back({0, 1});
else
ans.push_back({1, 0});
if (v[n - 1][n - 2] == '1')
ans.push_back({n - 1, n - 2});
else
ans.push_back({n - 2, n - 1});
} else {
if (v[0][1] == '1')
ans.push_back({0, 1});
else
ans.push_back({1, 0});
}
} else {
if (z2 == 0) {
ans.push_back({n - 1, n - 2});
ans.push_back({n - 2, n - 1});
} else if (z2 == 1) {
if (v[n - 1][n - 2] == '1')
ans.push_back({n - 1, n - 2});
else
ans.push_back({n - 2, n - 1});
}
}
cout << ans.size() << "\n";
for (int i = 0; i < ans.size(); i++)
cout << ans[i].first + 1 << " " << ans[i].second + 1 << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const bool multi_test = true;
bool solve() {
int n;
cin >> n;
vector<string> t(n);
for (int(i) = 0; (i) < (n); (i)++) cin >> t[i];
char a, b, c, d;
a = t[0][1];
b = t[1][0];
c = t[n - 1][n - 2];
d = t[n - 2][n - 1];
if (a == b) {
if (c == d) {
if (a != c) {
cout << 0;
} else {
cout << 2 << '\n';
cout << 2 << ' ' << 1 << '\n';
cout << 1 << ' ' << 2;
}
} else {
if (a == c) {
cout << 1 << '\n';
cout << n << ' ' << n - 1;
} else {
cout << 1 << '\n';
cout << n - 1 << ' ' << n;
}
}
} else {
if (c == d) {
if (a == c) {
cout << 1 << '\n';
cout << 1 << ' ' << 2;
} else {
cout << 1 << '\n';
cout << 2 << ' ' << 1;
}
} else {
if (a == c) {
cout << 2 << '\n';
cout << 2 << ' ' << 1 << '\n';
cout << n << ' ' << n - 1;
} else {
cout << 2 << '\n';
cout << 2 << ' ' << 1 << '\n';
cout << n - 1 << ' ' << n;
}
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
if (!multi_test) {
solve();
return 0;
}
int t;
cin >> t;
for (int(i) = 0; (i) < (t); (i)++) {
cin.ignore();
if (!solve()) return 0;
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string s[n];
long long int cntU = 0, cntD = 0;
for (long long int i = 0; i < n; i++) {
cin >> s[i];
}
if (s[0][1] == '0' && s[1][0] == '0') {
if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "0" << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "2" << endl
<< n - 1 << " " << n << endl
<< n << " " << n - 1 << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "1" << endl << n - 1 << " " << n << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "1" << endl << n << " " << n - 1 << endl;
}
} else if (s[0][1] == '1' && s[1][0] == '1') {
if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "0" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "2" << endl
<< n - 1 << " " << n << endl
<< n << " " << n - 1 << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "1" << endl << n - 1 << " " << n << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "1" << endl << n << " " << n - 1 << endl;
}
} else if (s[0][1] == '0' && s[1][0] == '1') {
if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "1" << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "1" << endl
<< "2"
<< " "
<< "1" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "2" << endl
<< n - 1 << " " << n << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "2" << endl
<< n << " " << n - 1 << endl
<< "1"
<< " "
<< "2" << endl;
}
} else if (s[0][1] == '1' && s[1][0] == '0') {
if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
cout << "1" << endl
<< "2"
<< " "
<< "1" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
cout << "1" << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
cout << "2" << endl
<< n << " " << n - 1 << endl
<< "1"
<< " "
<< "2" << endl;
} else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
cout << "2" << endl
<< n << " " << n - 1 << endl
<< "2"
<< " "
<< "1" << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long MAX = 100100;
void pre() {}
void solve() {
long long n;
cin >> n;
vector<string> v(n);
for (long long i = 0; i < n; ++i) cin >> v[i];
vector<pair<long long, long long> > rm;
long long up = 0, dn = 0;
if (v[0][1] == '1') up++;
if (v[1][0] == '1') up++;
if (v[n - 1][n - 2] == '1') dn++;
if (v[n - 2][n - 1] == '1') dn++;
if (up == 0) {
if (v[n - 1][n - 2] != '1') rm.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] != '1') rm.push_back({n - 2, n - 1});
} else if (dn == 0) {
if (v[1][0] != '1') rm.push_back({1, 0});
if (v[0][1] != '1') rm.push_back({0, 1});
} else if (up + dn == 4) {
rm.push_back({1, 0});
rm.push_back({0, 1});
} else if (up + dn == 0) {
rm.push_back({1, 0});
rm.push_back({0, 1});
} else if (up == 1 && dn == 1) {
if (v[n - 1][n - 2] != '1') rm.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] != '1') rm.push_back({n - 2, n - 1});
if (v[1][0] != '0') rm.push_back({1, 0});
if (v[0][1] != '0') rm.push_back({0, 1});
} else if (up == 2) {
if (v[n - 1][n - 2] != '0') rm.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] != '0') rm.push_back({n - 2, n - 1});
} else if (dn == 2) {
if (v[1][0] != '0') rm.push_back({1, 0});
if (v[0][1] != '0') rm.push_back({0, 1});
}
cout << ((long long)(rm).size()) << "\n";
for (auto p : rm) cout << p.first + 1 << " " << p.second + 1 << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
pre();
long long t = 1;
cin >> t;
for (long long CASE = 1; CASE <= t; ++CASE) {
solve();
}
{};
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int dim;
cin >> dim;
vector<vector<int> > vec;
vector<int> load;
string a;
for (int i = 0; i < dim; i++) {
cin >> a;
for (int j = 0; j < dim; j++) {
load.push_back(a[j] - 48);
}
vec.push_back(load);
load.clear();
}
if (vec[0][1] == vec[1][0]) {
if ((vec[dim - 1][dim - 2] == vec[dim - 2][dim - 1]) &&
(vec[0][1] == vec[dim - 1][dim - 2])) {
cout << "2\n";
cout << "1"
<< " "
<< "2\n";
cout << "2"
<< " "
<< "1\n";
} else if (vec[0][1] == vec[dim - 1][dim - 2]) {
cout << "1" << endl;
cout << dim << " " << dim - 1 << endl;
} else if (vec[0][1] == vec[dim - 2][dim - 1]) {
cout << "1" << endl;
cout << dim - 1 << " " << dim << endl;
} else {
cout << "0" << endl;
}
} else {
if ((vec[dim - 1][dim - 2] == vec[dim - 2][dim - 1]) &&
(vec[0][1] == vec[dim - 1][dim - 2])) {
cout << "1" << endl;
cout << "1"
<< " "
<< "2" << endl;
} else if ((vec[dim - 1][dim - 2] == vec[dim - 2][dim - 1]) &&
(vec[1][0] == vec[dim - 1][dim - 2])) {
cout << "1" << endl;
cout << "2"
<< " "
<< "1" << endl;
} else {
if (vec[1][0] == vec[dim - 1][dim - 2]) {
cout << "2" << endl;
cout << "2"
<< " "
<< "1" << endl;
cout << dim - 1 << " " << dim << endl;
} else if (vec[1][0] == vec[dim - 2][dim - 1]) {
cout << "2" << endl;
cout << "1"
<< " "
<< "2" << endl;
cout << dim - 1 << " " << dim << endl;
}
}
}
vec.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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];
}
}
char k = a[0][1];
char u = a[n - 1][n - 2];
char l = a[1][0];
char v = a[n - 2][n - 1];
if (k == l) {
if (u == v) {
if (k == u) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << 2 << " " << 1 << endl;
} else
cout << 0 << endl;
} else {
if (k == u) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
} else {
if (u == v) {
if (k == u) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (k == u) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << n - 1 << " " << n << endl;
} else {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int up = (v[0][1] - 48) + (v[1][0] - 48);
int down = (v[n - 1][n - 2] - 48) + (v[n - 2][n - 1] - 48);
if (up == down) {
if (up == 1) {
cout << 2 << "\n";
if (v[0][1] == '1')
cout << "1 2"
<< "\n";
if (v[1][0] == '1')
cout << "2 1"
<< "\n";
if (v[n - 1][n - 2] == '0') cout << n << " " << n - 1 << "\n";
if (v[n - 2][n - 1] == '0') cout << n - 1 << " " << n << "\n";
} else {
cout << 2 << "\n";
cout << "1 2"
<< "\n";
cout << "2 1"
<< "\n";
}
} else {
if (abs(up - down) == 2) {
cout << 0 << "\n";
} else {
cout << 1 << "\n";
if (up == 1) {
if (down == 0) {
if (v[0][1] == '0')
cout << "1 2"
<< "\n";
if (v[1][0] == '0')
cout << "2 1"
<< "\n";
} else {
if (v[0][1] == '1')
cout << "1 2"
<< "\n";
if (v[1][0] == '1')
cout << "2 1"
<< "\n";
}
} else {
if (up == 0) {
if (v[n - 1][n - 2] == '0') cout << n << " " << n - 1 << "\n";
if (v[n - 2][n - 1] == '0') cout << n - 1 << " " << n << "\n";
} else {
if (v[n - 1][n - 2] == '1') cout << n << " " << n - 1 << "\n";
if (v[n - 2][n - 1] == '1') cout << n - 1 << " " << n << "\n";
}
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using pii = pair<int, int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int N = 210;
int T, n;
char s[N][N];
vector<pii> ans;
void add(char ch, int x, int y) {
if (s[x][y] == ch) ans.emplace_back(x, y);
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = (1); i < (n + 1); ++i) scanf("%s", s[i] + 1);
ans.clear();
if (s[1][2] == s[2][1]) {
add(s[1][2], n - 1, n);
add(s[2][1], n, n - 1);
} else if (s[n - 1][n] == s[n][n - 1]) {
add(s[n][n - 1], 1, 2);
add(s[n][n - 1], 2, 1);
} else {
add(s[2][1], 2, 1);
add(s[1][2], n - 1, n);
add(s[1][2], n, n - 1);
}
printf("%d\n", (int)ans.size());
for (auto p : ans) printf("%d %d\n", p.first, p.second);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000005;
const long long mod = 1e18;
const long long N = 1e5 + 5;
long long T = 0;
const string alphabet = {"abcdefghijklmnopqrstuvwxyz"};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
long long n = 0, i, a, b;
cin >> n;
string s[n];
for (i = 0; i < n; i++) cin >> s[i];
long long cnt = 0;
vector<pair<long long, long long> > ans;
if (s[0][1] == s[1][0]) {
if (s[0][1] == '0') {
if (s[n - 1][n - 2] == '0') {
cnt++;
ans.push_back({n, n - 1});
}
if (s[n - 2][n - 1] == '0') {
cnt++;
ans.push_back({n - 1, n});
}
} else {
if (s[n - 1][n - 2] == '1') {
cnt++;
ans.push_back({n, n - 1});
}
if (s[n - 2][n - 1] == '1') {
cnt++;
ans.push_back({n - 1, n});
}
}
} else {
long long k = (s[n - 1][n - 2] - '0') + (s[n - 2][n - 1] - '0');
if (k == 0) {
cout << 1 << endl;
cout << (s[0][1] == '1' ? "2 1" : "1 2") << endl;
} else if (k == 1) {
cout << 2 << endl;
if (s[n - 1][n - 2] == '0')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
cout << (s[0][1] == '0' ? "2 1" : "1 2") << endl;
} else {
cout << 1 << endl;
cout << (s[0][1] == '0' ? "2 1" : "1 2") << endl;
}
return;
}
cout << cnt << endl;
for (auto z : ans) cout << z.first << " " << z.second << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
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 arr[n][n];
long long i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
long long ud = arr[1][0] - '0';
long long ur = arr[0][1] - '0';
long long dl = arr[n - 1][n - 2] - '0';
long long du = arr[n - 2][n - 1] - '0';
long long ans;
if (ud == ur && dl == du && ud != dl) {
cout << 0 << endl;
} else if (ud == ur && ur == dl && dl == du) {
cout << 2 << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
} else if (ud != ur && dl != du) {
cout << 2 << endl;
if (ud == 1) {
cout << "2 1" << endl;
} else if (ur == 1) {
cout << "1 2" << endl;
}
if (dl == 0) {
cout << n << " " << n - 1 << endl;
} else if (du == 0) {
cout << n - 1 << " " << n << endl;
}
} else if (ud == ur && ur == dl && dl != du) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else if (ud == ur && ur == du && dl != du) {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
} else if (dl == du && du == ur && ur != ud) {
cout << 1 << endl;
cout << "1 2" << endl;
} else if (dl == du && du == ud && ud != ur) {
cout << 1 << endl;
cout << "2 1" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline void sol() {
long long n;
cin >> n;
vector<vector<char>> grid(n, vector<char>(n));
for (auto &i : grid)
for (auto &j : i) cin >> j;
long long s1 = grid[0][1] + grid[1][0] - 2 * '0';
long long s2 = grid[n - 1][n - 2] + grid[n - 2][n - 1] - 2 * '0';
if (s1 == s2 and (s1 == 2 or s1 == 0)) {
cout << 2 << endl;
cout << "1 2\n2 1\n";
return;
}
if ((s1 == 2 and s2 == 0) or (s1 == 0 and s2 == 2)) {
cout << 0 << endl;
return;
}
if ((s1 == 0 or s2 == 0) and (s1 == 1 or s2 == 1)) {
cout << 1 << endl;
if (s1 == 0) {
if (grid[n - 1][n - 2] == '0')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
} else {
if (grid[0][1] == '0')
cout << "1 2\n";
else
cout << "2 1\n";
}
return;
}
if ((s1 == 2 or s2 == 2) and (s1 == 1 or s2 == 1)) {
cout << 1 << endl;
if (s1 == 2) {
if (grid[n - 1][n - 2] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
} else {
if (grid[0][1] == '1')
cout << "1 2\n";
else
cout << "2 1\n";
}
return;
}
cout << 2 << endl;
if (grid[0][1] == '1')
cout << "1 2\n";
else
cout << "2 1\n";
if (grid[n - 1][n - 2] == '0')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long t;
cin >> t;
while (t--) sol();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> graph(n);
for (auto &i : graph) cin >> i;
int a = graph[0][1], b = graph[1][0], c = graph[n - 2][n - 1],
d = graph[n - 1][n - 2];
if (a == b and b == c and c == d)
cout << "2\n1 2\n2 1\n";
else if (a == b and c == d)
cout << "0\n";
else if (a != b and c == d) {
if (a == c)
cout << "1\n1 2\n";
else
cout << "1\n2 1\n";
} else if (a == b and c != d) {
if (a == c)
cout << "1\n" << n - 1 << " " << n << endl;
else
cout << "1\n" << n << " " << n - 1 << endl;
} else {
if (a == c)
cout << "2\n1 2\n" << n << " " << n - 1 << endl;
else
cout << "2\n1 2\n" << n - 1 << " " << n << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<vector<char> > mat;
for (int i = 0; i < n; i++) {
vector<char> v(n);
for (int j = 0; j < n; j++) cin >> v[j];
mat.push_back(v);
}
bool c1 = (mat[0][2] == mat[2][0] and mat[2][0] == mat[1][1]);
bool c2 = mat[0][1] == mat[1][0];
if (c2) {
if (c1) {
if (mat[0][1] == mat[1][1])
cout << 2 << "\n" << 1 << " " << 2 << "\n" << 2 << " " << 1 << "\n";
else
cout << 0 << "\n";
} else {
cout << ((mat[2][0] == mat[1][0]) + (mat[1][1] == mat[1][0]) +
(mat[0][2] == mat[1][0]))
<< "\n";
if (mat[0][2] == mat[1][0]) cout << 1 << " " << 3 << "\n";
if (mat[1][1] == mat[1][0]) cout << 2 << " " << 2 << "\n";
if (mat[2][0] == mat[1][0]) cout << 3 << " " << 1 << "\n";
}
} else {
if (c1) {
cout << 1 << "\n";
(mat[1][0] == mat[1][1]) ? (cout << 2 << " " << 1 << "\n")
: (cout << 1 << " " << 2 << "\n");
} else {
cout << 2 << "\n";
(mat[2][0] == mat[1][1])
? (cout << 1 << " " << 3 << "\n")
: ((mat[0][2] == mat[2][0]) ? (cout << 2 << " " << 2 << "\n")
: (cout << 3 << " " << 1 << "\n"));
(mat[2][0] == mat[1][1])
? (mat[0][2] = mat[2][0])
: ((mat[0][2] == mat[2][0]) ? (mat[1][1] = mat[2][0])
: (mat[2][0] = mat[1][1]));
(mat[1][0] == mat[1][1]) ? (cout << 2 << " " << 1 << "\n")
: (cout << 1 << " " << 2 << "\n");
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
const int INF = 1 << 29;
const double PI = acos(-1.0);
using namespace std;
void solve() {
int n;
cin >> n;
vector<string> v(n);
vector<pair<int, int>> ans;
for (string &it : v) cin >> it;
char a = v[0][1], b = v[1][0], c = v[n - 1][n - 2], d = v[n - 2][n - 1];
if (a == '1' && b == '1') {
if (c != '0') ans.push_back(make_pair(n, n - 1));
if (d != '0') ans.push_back(make_pair(n - 1, n));
} else if (a == '0' && b == '0') {
if (c != '1') ans.push_back(make_pair(n, n - 1));
if (d != '1') ans.push_back(make_pair(n - 1, n));
} else if (c == d) {
if (c == '0') {
if (a == '0')
ans.push_back(make_pair(1, 2));
else if (b == '0')
ans.push_back(make_pair(2, 1));
} else {
if (a == '1')
ans.push_back(make_pair(1, 2));
else if (b == '1')
ans.push_back(make_pair(2, 1));
}
} else {
if (a == '0')
ans.push_back(make_pair(1, 2));
else if (b == '0')
ans.push_back(make_pair(2, 1));
if (c == '1')
ans.push_back(make_pair(n, n - 1));
else if (d == '1')
ans.push_back(make_pair(n - 1, n));
}
cout << ans.size() << endl;
for (auto it : ans) cout << it.first << ' ' << it.second << endl;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
;
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
char a[N][N];
int n;
void pp(void) {
if (a[1][2] == '1')
cout << 1 << endl << ' ' << 1 << ' ' << 2 << endl;
else
cout << 1 << endl << ' ' << 2 << ' ' << 1 << endl;
}
void pp1(void) {
if (a[n - 1][n] == '0')
cout << 1 << endl << ' ' << n - 1 << ' ' << n << endl;
else
cout << 1 << endl << ' ' << n << ' ' << n - 1 << endl;
}
void pp2(void) {
if (a[1][2] == '0')
cout << 1 << endl << ' ' << 1 << ' ' << 2 << endl;
else
cout << 1 << endl << ' ' << 2 << ' ' << 1 << endl;
}
void pp3(void) {
if (a[n - 1][n] == '1')
cout << 1 << endl << ' ' << n - 1 << ' ' << n << endl;
else
cout << 1 << endl << ' ' << n << ' ' << n - 1 << endl;
}
void pp4(void) {
if (a[1][2] == '0') {
cout << 2 << endl << ' ' << 1 << ' ' << 2 << endl;
if (a[n - 1][n] == '1')
cout << n - 1 << ' ' << n << endl;
else
cout << n << ' ' << n - 1 << endl;
} else {
cout << 2 << endl << ' ' << 2 << ' ' << 1 << endl;
if (a[n - 1][n] == '1')
cout << n - 1 << ' ' << n << endl;
else
cout << n << ' ' << n - 1 << endl;
}
}
int main(void) {
int t;
cin >> t;
while (t--) {
cin >> n;
int s1 = 0, s0 = 0, f1 = 0, f0 = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin >> a[i][j];
if (a[2][1] == '0')
s0++;
else
s1++;
if (a[1][2] == '1')
s1++;
else
s0++;
if (a[n][n - 1] == '0')
f0++;
else
f1++;
if (a[n - 1][n] == '1')
f1++;
else
f0++;
if ((f1 == 2 && s1 == 2) || (s1 == 0 && f1 == 0))
cout << 2 << endl << 1 << ' ' << 2 << endl << 2 << ' ' << 1 << endl;
else if (s1 == 1 && f1 == 2)
pp();
else if (s1 == 0 && f1 == 1)
pp1();
else if (s1 == 0 && f1 == 2)
cout << 0 << endl;
else if (s1 == 2 && f1 == 0)
cout << 0 << endl;
else if (s1 == 1 && f1 == 0)
pp2();
else if (s1 == 2 && f1 == 1)
pp3();
else if (s1 == 1 && f1 == 1) {
pp4();
}
}
}
|
#include <bits/stdc++.h>
const unsigned long long int M = 1000000007;
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = x * res;
y = y >> 1;
x = x * x;
}
return res;
}
long long power(long long x, long long y, long long mod) {
long long res = 1;
while (y > 0) {
if (y & 1) res = x * res % mod;
y = y >> 1;
x = x * x % mod;
}
return res;
}
void nik() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
signed main() {
nik();
long long test = 1;
cin >> test;
while (test--) {
long long n;
cin >> n;
string s[n];
for (long long i = 0; i < n; i++) cin >> s[i];
long long a, b, c, d;
a = s[1][0] - '0';
b = s[0][1] - '0';
c = s[n - 1][n - 2] - '0';
d = s[n - 2][n - 1] - '0';
std::vector<pair<long long, long long>> v;
if (a == b) {
if (c == a) v.push_back({n - 1, n - 2});
if (d == a) v.push_back({n - 2, n - 1});
} else if (c == d) {
if (c == a) v.push_back({1, 0});
if (d == b) v.push_back({0, 1});
} else if (a == c) {
v.push_back({1, 0});
v.push_back({n - 2, n - 1});
} else if (a == d) {
v.push_back({0, 1});
v.push_back({n - 2, n - 1});
}
cout << v.size() << "\n";
for (auto it : v) {
cout << it.first + 1 << " " << it.second + 1 << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 212;
char s[N];
void print(vector<pair<int, int>> &resp) {
printf("%d\n", (int)resp.size());
for (auto a : resp) {
printf("%d %d\n", a.first, a.second);
}
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a1, a2, b1, b2;
for (int i = 0; i < n; i++) {
scanf("%s", s);
if (i == 0) a1 = s[1] - '0';
if (i == 1) a2 = s[0] - '0';
if (i == n - 2) b1 = s[n - 1] - '0';
if (i == n - 1) b2 = s[n - 2] - '0';
}
vector<pair<int, int>> resp;
if (a1 == a2) {
int o = 1 - a1;
if (b1 != o) resp.push_back({n - 1, n});
if (b2 != o) resp.push_back({n, n - 1});
} else if (b1 == b2) {
int o = 1 - b1;
if (a1 != o) resp.push_back({1, 2});
if (a2 != o) resp.push_back({2, 1});
} else {
if (a1 != 0) resp.push_back({1, 2});
if (a2 != 0) resp.push_back({2, 1});
if (b1 != 1) resp.push_back({n - 1, n});
if (b2 != 1) resp.push_back({n, n - 1});
}
print(resp);
}
}
|
#include <bits/stdc++.h>
using namespace std;
namespace chino {
const int maxn = 0x3f3f3f3f;
const int inf = 0x7fffffff;
} // namespace chino
inline int read() {
char ch;
int f = 1, x = 0;
do {
ch = getchar();
if (ch == '-') f = -1;
} while (!isdigit(ch));
do {
x = x * 10 + ch - '0';
ch = getchar();
} while (isdigit(ch));
return f * x;
}
inline void print(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
const int mod = 1e9 + 7;
string s[220];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
char a, b, c, d;
a = s[0][1];
b = s[1][0];
c = s[n - 2][n - 1];
d = s[n - 1][n - 2];
if (a == b) {
if (c == d) {
if (a == c) {
cout << 2 << endl;
cout << n << ' ' << n - 1 << endl;
cout << n - 1 << ' ' << n << endl;
} else {
cout << 0 << endl;
}
} else {
if (a == c) {
cout << 1 << endl;
cout << n - 1 << ' ' << n << endl;
} else {
cout << 1 << endl;
cout << n << ' ' << n - 1 << endl;
}
}
} else {
if (c == d) {
if (a == c) {
cout << 1 << endl;
cout << 1 << ' ' << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << ' ' << 1 << endl;
}
} else {
if (a == c) {
cout << 2 << endl;
cout << n - 1 << ' ' << n << endl;
cout << 2 << ' ' << 1 << endl;
} else {
cout << 2 << endl;
cout << 1 << ' ' << 2 << endl;
cout << n - 1 << ' ' << n << endl;
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
char a[n + 1][n + 1];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) cin >> a[i][j];
int a12 = a[1][2] - '0', a21 = a[2][1] - '0', anl = a[n][n - 1] - '0',
anu = a[n - 1][n] - '0';
if (a12 == a21 && anl == anu) {
if (a12 == anl)
cout << "2\n1 2\n2 1\n";
else
cout << "0\n";
} else if (a12 == a21) {
if (anl == a12)
cout << "1\n" << n << ' ' << n - 1 << '\n';
else
cout << "1\n" << n - 1 << ' ' << n << '\n';
} else if (anl == anu) {
if (anl == a12)
cout << "1\n" << 1 << ' ' << 2 << '\n';
else
cout << "1\n" << 2 << ' ' << 1 << '\n';
} else {
cout << 2 << '\n';
if (a12 == 0)
cout << "1 2\n";
else
cout << "2 1\n";
if (anl == 1)
cout << n << ' ' << n - 1 << '\n';
else
cout << n - 1 << ' ' << n << '\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
void fastio() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void one();
int main() {
fastio();
int t = 1;
cin >> t;
for (int i = 0; i < t; ++i) {
one();
}
return 0;
}
void one() {
int n;
cin >> n;
vector<string> s;
for (int i = 0; i < n; ++i) {
string ss;
cin >> ss;
s.push_back(ss);
}
vector<pair<int, int>> ans;
if (s[0][1] == s[1][0]) {
auto c = s[0][1];
if (s[n - 1][n - 2] == c) ans.push_back({n - 1, n - 2});
if (s[n - 2][n - 1] == c) ans.push_back({n - 2, n - 1});
} else if (s[0][1] != s[1][0]) {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
char c = s[n - 1][n - 2];
if (s[0][1] == c) {
ans.push_back({0, 1});
} else {
ans.push_back({1, 0});
}
} else {
ans.push_back({0, 1});
if (s[0][1] != s[n - 1][n - 2]) {
ans.push_back({n - 1, n - 2});
} else {
ans.push_back({n - 2, n - 1});
}
}
}
cout << ans.size() << "\n";
for (auto p : ans) {
cout << p.first + 1 << " " << p.second + 1 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<vector<int> > v;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
int c = 0;
int zeroc = 0;
int onec = 0;
if (a[0][1] == '0')
zeroc++;
else
onec++;
if (a[1][0] == '0')
zeroc++;
else
onec++;
if (a[n - 2][n - 1] == '0')
zeroc++;
else
onec++;
if (a[n - 1][n - 2] == '0')
zeroc++;
else
onec++;
if (zeroc == 0 || onec == 0) {
cout << "2" << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
return;
}
if (zeroc > onec) {
if (a[0][1] != a[1][0]) {
c++;
if (a[0][1] == '0') {
vector<int> temp;
temp.push_back(1);
temp.push_back(2);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(2);
temp.push_back(1);
v.push_back(temp);
}
} else {
c++;
if (a[n - 1][n - 2] == '0') {
vector<int> temp;
temp.push_back(n);
temp.push_back(n - 1);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(n - 1);
temp.push_back(n);
v.push_back(temp);
}
}
} else if (onec > zeroc) {
if (a[0][1] != a[1][0]) {
c++;
if (a[0][1] == '1') {
vector<int> temp;
temp.push_back(1);
temp.push_back(2);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(2);
temp.push_back(1);
v.push_back(temp);
}
} else {
c++;
if (a[n - 1][n - 2] == '1') {
vector<int> temp;
temp.push_back(n);
temp.push_back(n - 1);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(n - 1);
temp.push_back(n);
v.push_back(temp);
}
}
} else {
if (a[0][1] != a[1][0]) {
c++;
if (a[0][1] == '0') {
vector<int> temp;
temp.push_back(2);
temp.push_back(1);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(1);
temp.push_back(2);
v.push_back(temp);
}
}
if (a[n - 1][n - 2] != a[n - 2][n - 1]) {
c++;
if (a[n - 1][n - 2] == '1') {
vector<int> temp;
temp.push_back(n - 1);
temp.push_back(n);
v.push_back(temp);
} else {
vector<int> temp;
temp.push_back(n);
temp.push_back(n - 1);
v.push_back(temp);
}
}
}
cout << c << endl;
for (int i = 0; i < v.size(); i++) {
cout << v[i][0] << " " << v[i][1] << endl;
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 8;
const double pi = 3.14159265359;
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
long long inverse(long long x) { return binpow(x, MOD - 2, MOD); }
void solve() {
long long n;
cin >> n;
string arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
long long x1 = (arr[1][0] - '0');
long long x2 = (arr[0][1] - '0');
long long y1 = (arr[n - 1][n - 2] - '0');
long long y2 = (arr[n - 2][n - 1] - '0');
vector<pair<long long, long long> > ans;
if (x1 == x2 && y1 == y2) {
if (x1 == y1) {
ans.push_back(make_pair(2, 1));
ans.push_back(make_pair(1, 2));
}
} else if (x1 == x2 && y1 != y2) {
if (x1 == y1)
ans.push_back(make_pair(n, n - 1));
else
ans.push_back(make_pair(n - 1, n));
} else if (x1 != x2 && y1 == y2) {
if (x1 == y1)
ans.push_back(make_pair(2, 1));
else
ans.push_back(make_pair(1, 2));
} else if (x1 != x2 && y1 != y2) {
if (x1 == y1) {
ans.push_back(make_pair(2, 1));
ans.push_back(make_pair(n - 1, n));
} else {
ans.push_back(make_pair(2, 1));
ans.push_back(make_pair(n, n - 1));
}
}
cout << ans.size() << endl;
if (ans.size() == 0) {
return;
}
for (long long i = 0; i < ans.size(); i++)
cout << ans[i].first << " " << ans[i].second << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) solve();
cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}
|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
template <typename T>
inline T sq(T a) {
return a * a;
}
template <typename T1, typename T2>
inline pair<T1, T2> mp(T1 a, T2 b) {
return make_pair(a, b);
}
template <typename T1, typename T2>
inline T1 safeMod(T1 a, T2 m) {
return (a % m + m) % m;
}
template <typename T1, typename T2>
inline bool isEq(T1 a, T2 b) {
return abs(a - b) < EPS;
}
template <typename T1, typename T2, typename T3>
inline bool isEq(T1 a, T2 b, T3 eps) {
return abs(a - b) < eps;
}
template <typename T>
inline bool isKthBitOn(T n, int k) {
assert(n <= numeric_limits<T>::max());
assert(k <= numeric_limits<T>::digits);
T ONE = 1;
return bool((n & (ONE << k)));
}
template <typename T>
inline void setKthBit(T& n, int k) {
assert(n <= numeric_limits<T>::max());
assert(k <= numeric_limits<T>::digits);
T ONE = 1;
n = (n | (ONE << k));
}
const int oo = 0x3f3f3f3f;
const int MAX = 200010;
const int MOD = 1000000007;
const int precision = 10;
void solve(int kas) {
int n;
cin >> n;
vector<string> grid(n);
for (int i = 0; i < n; i++) {
cin >> grid[i];
}
vector<pair<int, int> > ans;
if (grid[0][1] == grid[1][0]) {
char other = (grid[0][1] == '1') ? '0' : '1';
if (other != grid[n - 1][n - 2]) ans.push_back({n - 1, n - 2});
if (other != grid[n - 2][n - 1]) ans.push_back({n - 2, n - 1});
} else {
if (grid[n - 1][n - 2] == grid[n - 2][n - 1]) {
char other = (grid[n - 1][n - 2] == '1') ? '0' : '1';
if (other != grid[0][1]) ans.push_back({0, 1});
if (other != grid[1][0]) ans.push_back({1, 0});
} else {
grid[0][1] = grid[1][0];
ans.push_back({0, 1});
char other = (grid[0][1] == '1') ? '0' : '1';
if (other != grid[n - 1][n - 2]) ans.push_back({n - 1, n - 2});
if (other != grid[n - 2][n - 1]) ans.push_back({n - 2, n - 1});
}
}
cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++)
cout << ans[i].first + 1 << " " << ans[i].second + 1 << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
for (int _ = 1; _ <= tc; _++) {
solve(_);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int read() {
int re = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
re = re * 10 + c - '0';
c = getchar();
}
return re;
}
int t;
string mat[300];
int vis[300][300], chg[300][300];
int main() {
cin >> t;
while (t--) {
int n = read();
for (int i = 0; i < n; ++i) {
cin >> mat[i];
}
int n1 = mat[0][1] - '0';
int n2 = mat[1][0] - '0';
int n3 = mat[n - 1][n - 2] - '0';
int n4 = mat[n - 2][n - 1] - '0';
if (n1 != n2 && n3 != n4) {
cout << 2 << endl;
if (n1 != 1) {
cout << 1 << ' ' << 2 << endl;
} else
cout << 2 << ' ' << 1 << endl;
if (n3 != 0) {
printf("%d %d\n", n, n - 1);
} else
printf("%d %d\n", n - 1, n);
} else if (n1 != n2) {
cout << 1 << endl;
int op = n3;
if (n1 == op)
printf("%d %d\n", 1, 2);
else
printf("%d %d\n", 2, 1);
} else if (n3 != n4) {
cout << 1 << endl;
int op = n1;
if (n3 == op)
printf("%d %d\n", n, n - 1);
else
printf("%d %d\n", n - 1, n);
} else {
if (n1 != n3) {
cout << 0 << endl;
continue;
}
cout << 2 << endl;
printf("%d %d\n", 2, 1);
printf("%d %d\n", 1, 2);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
void vin(vector<int>& v) {
int i, p;
int n = (int)v.size();
for (i = 0; i < n; i++) {
scanf("%d", &v[i]);
}
}
void vin(vector<long long>& v) {
long long i, p;
int n = v.size();
for (i = 0; i < n; i++) {
scanf("%lld", &v[i]);
}
}
void vout(const vector<int>& v) {
for (auto q : v) printf("%d ", q);
printf("\n");
}
void vout(const vector<long long>& v) {
for (auto q : v) printf("%lld ", q);
printf("\n");
}
struct typ {
int tp = -1;
long long a = 0, b = 0;
};
struct comp {
bool operator()(typ const& a, typ const& b) { return a.a < b.a; }
};
int main(int argc, char const* argv[]) {
int t = 1;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> v(n);
int i;
for (i = 0; i < n; i++) cin >> v[i];
bool ans = 0;
int a, b, c, d;
a = v[0][1] - '0';
b = v[1][0] - '0';
c = v[n - 1][n - 2] - '0';
d = v[n - 2][n - 1] - '0';
vector<pair<int, int>> out;
if (a == b && b == c && c == d) {
out.push_back({1, 2});
out.push_back({2, 1});
} else {
if (a == b) {
if (c != d) {
if (c == a)
out.push_back({n, n - 1});
else
out.push_back({n - 1, n});
}
} else if (c == d) {
if (a == c) {
out.push_back({1, 2});
} else {
out.push_back({2, 1});
}
} else {
if (a == c) {
out.push_back({1, 2});
out.push_back({n - 1, n});
} else {
out.push_back({1, 2});
out.push_back({n, n - 1});
}
}
}
printf("%d\n", (int)out.size());
for (auto q : out) printf("%d %d\n", q.first, q.second);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
long long countdigit(long long n) {
long long x = n, c = 0;
while (x != 0) {
x = x / 10;
c++;
}
return c;
}
void solve() {
long long n;
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][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << "2" << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
} else {
cout << "0" << endl;
}
} else {
cout << "1" << endl;
if (s[n - 1][n - 2] == s[0][1])
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
cout << "1" << endl;
if (s[0][1] == s[n - 1][n - 2])
cout << "1 2" << endl;
else
cout << "2 1" << endl;
} else {
cout << "2" << endl;
if (s[0][1] == '0')
cout << "1 2" << endl;
else
cout << "2 1" << endl;
if (s[n - 1][n - 2] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
const long long M = 1e7 + 7;
const double pi = 3.14159265358979323846;
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;
long long a, b, c, d;
for (long long i = 0; i < n; i++) {
string s;
cin >> s;
for (long long j = 0; j < n; j++) {
if (i == 0 && j == 1)
a = (long long)s[j] - 48;
else if (i == 1 && j == 0)
b = (long long)s[j] - 48;
else if (i == n - 2 && j == n - 1)
c = (long long)s[j] - 48;
else if (i == n - 1 && j == n - 2)
d = (long long)s[j] - 48;
}
}
if (a == b && c == d) {
if (a == c) {
cout << (2) << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
} else
cout << (0) << "\n";
} else if (a == b) {
if (a ^ c == 1) {
cout << (1) << "\n";
cout << n << " " << n - 1 << "\n";
} else {
cout << (1) << "\n";
cout << n - 1 << " " << n << "\n";
}
} else if (c == d) {
if (a ^ c == 1) {
cout << (1) << "\n";
cout << 2 << " " << 1 << "\n";
} else {
cout << (1) << "\n";
cout << 1 << " " << 2 << "\n";
}
} else {
cout << (2) << "\n";
if (a != 0) {
cout << 1 << " " << 2 << "\n";
} else {
cout << 2 << " " << 1 << "\n";
}
if (c != 0) {
cout << n << " " << n - 1 << "\n";
} else {
cout << n - 1 << " " << n << "\n";
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = INT_MAX;
const int N = INT_MIN;
using namespace std;
int main() {
int t = 0;
cin >> t;
while (t--) {
int n, c = 0;
cin >> n;
char d[n + 1][n + 1];
vector<pair<int, int>> vect;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> d[i][j];
}
}
if (d[1][2] == d[2][1] && d[2][1] == '0') {
if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == d[1][2]) {
vect.push_back({n - 1, n});
vect.push_back({n, n - 1});
} else if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] != d[1][2])
c = c;
else if (d[n - 1][n] != '0') {
vect.push_back({n, n - 1});
} else if (d[n][n - 1] != '0') {
vect.push_back({n - 1, n});
}
} else if (d[1][2] == d[2][1] && d[2][1] == '1') {
if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == d[1][2]) {
vect.push_back({n - 1, n});
vect.push_back({n, n - 1});
} else if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] != d[1][2])
c = c;
else if (d[n - 1][n] != '0') {
vect.push_back({n - 1, n});
} else if (d[n][n - 1] != '0') {
vect.push_back({n, n - 1});
}
} else if (d[1][2] != d[2][1]) {
if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == '0') {
if (d[1][2] == '1')
vect.push_back({2, 1});
else
vect.push_back({1, 2});
} else if (d[n - 1][n] == d[n][n - 1] && d[n][n - 1] == '1') {
if (d[1][2] == '0')
vect.push_back({2, 1});
else
vect.push_back({1, 2});
} else if (d[n - 1][n] != d[n][n - 1]) {
if (d[1][2] == '0') {
vect.push_back({2, 1});
if (d[n][n - 1] == '1')
vect.push_back({n - 1, n});
else
vect.push_back({n, n - 1});
} else {
vect.push_back({1, 2});
if (d[n][n - 1] == '1')
vect.push_back({n - 1, n});
else
vect.push_back({n, n - 1});
}
}
}
cout << vect.size() << endl;
for (auto x : vect) {
cout << x.first << " " << x.second << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = (int)2e2;
const int N = (int)1e5;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const long long mod = (long long)1e9 + 7;
char s[M + 5][M + 5];
void work() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
char ch[4];
ch[0] = s[1][2], ch[1] = s[2][1];
ch[2] = s[n][n - 1], ch[3] = s[n - 1][n];
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '0' && ch[3] == '0')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, 2, 1);
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n", 1, n, n - 1);
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n", 1, n - 1, n);
if (ch[0] == '0' && ch[1] == '0' && ch[2] == '1' && ch[3] == '1')
printf("%d\n", 0);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '0' && ch[3] == '0')
printf("%d\n%d %d\n", 1, 1, 2);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n - 1, n);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n, n - 1);
if (ch[0] == '0' && ch[1] == '1' && ch[2] == '1' && ch[3] == '1')
printf("%d\n%d %d\n", 1, 2, 1);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '0' && ch[3] == '0')
printf("%d\n%d %d\n", 1, 2, 1);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n, n - 1);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, n - 1, n);
if (ch[0] == '1' && ch[1] == '0' && ch[2] == '1' && ch[3] == '1')
printf("%d\n%d %d\n", 1, 1, 2);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '0' && ch[3] == '0')
printf("%d\n", 0);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '0' && ch[3] == '1')
printf("%d\n%d %d\n", 1, n - 1, n);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '1' && ch[3] == '0')
printf("%d\n%d %d\n", 1, n, n - 1);
if (ch[0] == '1' && ch[1] == '1' && ch[2] == '1' && ch[3] == '1')
printf("%d\n%d %d\n%d %d\n", 2, 1, 2, 2, 1);
}
int main() {
int T;
scanf("%d", &T);
while (T--) work();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool isKthBitSet(long long n, long long k) {
if (n & (1 << (k - 1)))
return true;
else
return false;
}
int main() {
ios_base::sync_with_stdio(false);
;
long long t = 1, n, sum, k, r, temp, dif, maxi, mini, ans, c, num, x, m, l, a,
b, i;
vector<pair<long long, long long>> pairvec;
bool flag = false;
cin >> t;
long long zeros, ones;
while (t--) {
pairvec.clear();
cin >> n;
string arr[n];
for (long long i = 0; i < n; ++i) {
cin >> arr[i];
}
if (arr[0][1] + arr[1][0] < arr[n - 1][n - 2] + arr[n - 2][n - 1]) {
if (arr[0][1] == '1') pairvec.push_back(make_pair(1, 2));
if (arr[1][0] == '1') pairvec.push_back(make_pair(2, 1));
if (arr[n - 1][n - 2] == '0') pairvec.push_back(make_pair(n, n - 1));
if (arr[n - 2][n - 1] == '0') pairvec.push_back(make_pair(n - 1, n));
} else {
if (arr[0][1] == '0') pairvec.push_back(make_pair(1, 2));
if (arr[1][0] == '0') pairvec.push_back(make_pair(2, 1));
if (arr[n - 1][n - 2] == '1') pairvec.push_back(make_pair(n, n - 1));
if (arr[n - 2][n - 1] == '1') pairvec.push_back(make_pair(n - 1, n));
}
cout << pairvec.size() << endl;
for (int i = 0; i < pairvec.size(); i++)
cout << pairvec[i].first << " " << pairvec[i].second << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int div_floor(const long long int &a, const long long int &b) {
return a / b - (((a ^ b) < 0) and a % b);
}
long long int div_ceil(const long long int &a, const long long int &b) {
return a / b + (((a ^ b) >= 0) and a % b);
}
void solve() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
int ctr1 = (s[0][1] == '1') + (s[1][0] == '1') + (s[n - 1][n - 2] == '0') +
(s[n - 2][n - 1] == '0');
int ctr2 = (s[0][1] == '0') + (s[1][0] == '0') + (s[n - 1][n - 2] == '1') +
(s[n - 2][n - 1] == '1');
if (ctr1 >= 2) {
cout << 4 - ctr1 << '\n';
if (s[0][1] != '1') cout << 1 << " " << 2 << '\n';
if (s[1][0] != '1') cout << 2 << " " << 1 << '\n';
if (s[n - 1][n - 2] != '0') cout << n << " " << n - 1 << '\n';
if (s[n - 2][n - 1] != '0') cout << n - 1 << " " << n << '\n';
return;
}
if (ctr2 >= 2) {
cout << 4 - ctr2 << '\n';
if (s[0][1] != '0') cout << 1 << " " << 2 << '\n';
if (s[1][0] != '0') cout << 2 << " " << 1 << '\n';
if (s[n - 1][n - 2] != '1') cout << n << " " << n - 1 << '\n';
if (s[n - 2][n - 1] != '1') cout << n - 1 << " " << n << '\n';
return;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long MAX = 1e18 + 1;
const double pi = 3.1415926535897932384626433832;
const long long M = 1e9 + 7;
long long bis(long long a[], long long l, long long r, long long x) {
while (l <= r) {
long long m = l + (r - l) / 2;
if (a[m] == x) return m;
if (a[m] < x)
l = m + 1;
else
r = m - 1;
}
return -1;
}
long long gcd(long long x, long long y) {
if (x == 0)
return y;
else
return gcd(y % x, x);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i = i + 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
return true;
}
bool pdrome(string s) {
long long n = s.length();
for (long long i = 0; i < n / 2; i++) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
string need(string s) {
string a = s;
reverse(a.begin(), a.end());
a = s + '?' + a;
long long n = a.size();
long long pref[n];
memset(pref, 0, sizeof(pref));
for (long long i = 1; i < n + 1; i++) {
long long len = pref[i - 1];
while (len > 0 && a[len] != a[i]) len = pref[len - 1];
if (a[i] == a[len]) len++;
pref[i] = len;
}
return a.substr(0, pref[n - 1]);
}
long long mindig(long long x) {
long long ans = 9;
long long t = x;
while (x) {
ans = min(ans, x % 10);
x /= 10;
}
x = t;
return ans;
}
long long maxdig(long long x) {
long long ans = 0;
long long t = x;
while (x) {
ans = max(ans, x % 10);
x /= 10;
}
x = t;
return ans;
}
long long modpow(long long x, long long n, long long M) {
if (n == 0) return 1 % M;
long long u = modpow(x, n / 2, M);
u = (u * u) % M;
if (n % 2 == 1) u = (u * x) % M;
return u;
}
long long sumdigits(long long a) {
long long result = 0;
while (a > 0) {
result += a % 10;
a /= 10;
}
return result;
}
long long digits(long long n) { return floor(log10(n) + 1); }
const long long Node = 1e5 + 7;
vector<long long> adj[Node];
bool vis[Node] = {false};
void addedge(long long u, long long v) {
adj[u].push_back(v);
adj[v].push_back(u);
}
void bfs(long long u) {
vis[u] = true;
list<long long> q;
q.push_back(u);
while (!q.empty()) {
q.pop_front();
for (auto x : adj[u]) {
if (!vis[x]) {
vis[x] = true;
q.push_back(x);
}
}
}
}
void dfs(long long u) {
vis[u] = true;
cout << u << " ";
for (auto x : adj[u]) {
if (!vis[x]) {
dfs(x);
}
}
}
long long con1(string s) {
long long res = 0;
stringstream geek(s);
geek >> res;
return res;
}
string con2(long long num) {
string stri = to_string(num);
return stri;
}
long long countbits(long long k) {
long long cnt = log2(k);
return cnt;
}
bool check(string s, long long k1, long long j) {
for (long long i = j; i < k1 / 2 + j; i++) {
if (s[i] != s[i + k1 / 2]) return false;
}
return true;
}
void solve() {
long long n;
cin >> n;
char c[n][n];
for (long long i = 0; i < n; i++)
for (long long j = 0; j < n; j++) cin >> c[i][j];
if (c[0][2] == c[1][1] && c[0][2] == c[2][0]) {
if (c[0][2] == '0') {
if (c[0][1] == c[1][0]) {
if (c[0][1] == '1')
cout << 0 << endl;
else {
cout << 2 << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
}
} else {
cout << 1 << endl;
if (c[0][1] == '0') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
}
} else {
if (c[0][1] == c[1][0]) {
if (c[0][1] == '0')
cout << 0 << endl;
else {
cout << 2 << endl;
cout << "1 2" << endl;
cout << "2 1" << endl;
}
} else {
cout << 1 << endl;
if (c[0][1] == '1') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
}
}
} else {
vector<pair<long long, long long> > v;
if (c[0][1] == c[1][0]) {
if (c[0][1] == '0') {
long long i = 0, j = 2;
long long cnt = 0;
while (i < 3) {
if (c[i][j] == '0') {
v.push_back({i, j});
}
i++;
j--;
}
cout << v.size() << endl;
for (auto x : v) cout << x.first + 1 << " " << x.second + 1 << endl;
} else {
long long i = 0, j = 2;
while (i < 3) {
if (c[i][j] == '1') {
v.push_back({i, j});
}
i++;
j--;
}
cout << v.size() << endl;
for (auto x : v) cout << x.first + 1 << " " << x.second + 1 << endl;
}
} else {
long long i = 0, j = 2;
while (i < 3) {
if (c[i][j] == '0') {
v.push_back({i, j});
}
i++;
j--;
}
cout << 2 << endl;
if (v.size() == 1) {
cout << v[0].first + 1 << " " << v[0].second + 1 << endl;
if (c[0][1] == '1') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
} else {
map<pair<long long, long long>, long long> mp;
for (auto x : v) mp[{x.first, x.second}] = 1;
i = 0, j = 2;
while (i < 3) {
if (mp[{i, j}] == 0) {
cout << i + 1 << " " << j + 1 << endl;
break;
}
i++;
j--;
}
if (c[0][1] == '0') {
cout << "1 2" << endl;
} else
cout << "2 1" << endl;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
char g[n][n], a[4];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) cin >> g[i][j];
}
a[0] = g[0][1];
a[1] = g[1][0];
a[2] = g[n - 1][n - 2];
a[3] = g[n - 2][n - 1];
if (a[0] == a[1] && a[2] == a[3]) {
if (a[0] == a[2]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << 1 << " " << 2 << endl;
} else
cout << 0 << endl;
} else if (a[0] == a[1] || a[2] == a[3]) {
cout << 1 << endl;
if (a[0] == a[1]) {
if (a[0] == a[2])
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
} else {
if (a[0] == a[2])
cout << 1 << " " << 2 << endl;
else
cout << 2 << " " << 1 << endl;
}
} else {
cout << 2 << endl;
if (a[0] == '1') cout << 1 << " " << 2 << endl;
if (a[1] == '1') cout << 2 << " " << 1 << endl;
if (a[2] == '0') cout << n << " " << n - 1 << endl;
if (a[3] == '0') cout << n - 1 << " " << n << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n;
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][n - 1] && s[n - 1][n - 2] != s[0][1]) {
cout << 0 << endl;
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << n << " " << n - 1 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int SIZE = (1 << 20) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = obuf + SIZE - 1;
char _st[55];
int _qr = 0;
inline char gc() {
return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
(iS == iT ? EOF : *iS++) : *iS++);
}
inline void qread() {}
template <class T1, class... T2>
inline void qread(T1& IEE, T2&... ls) {
register T1 __ = 0, ___ = 1;
register char ch;
while (!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
do {
__ = (__ << 1) + (__ << 3) + (ch ^ 48);
} while (isdigit(ch = gc()));
__ *= ___;
IEE = __;
qread(ls...);
return;
}
template <class T>
inline void qreadarr(T beg, T end) {
while (beg != end) {
qread(*beg);
beg++;
}
}
inline void flush() {
fwrite(obuf, 1, oS - obuf, stdout);
oS = obuf;
return;
}
inline void putc_(char _x) {
*oS++ = _x;
if (oS == oT) flush();
}
inline void qwrite() {}
template <class T1, class... T2>
inline void qwrite(T1 IEE, T2... ls) {
if (!IEE) putc_('0');
if (IEE < 0) putc_('-'), IEE = -IEE;
while (IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
while (_qr) putc_(_st[_qr--]);
qwrite(ls...);
return;
}
inline void putstr_(const char* IEE) {
int p = 0;
while (IEE[p] != '\0') {
putc_(IEE[p++]);
}
}
inline void puts_(const char* IEE) {
putstr_(IEE);
putc_('\n');
}
template <class T>
inline void qwritearr(T beg, T end, const char* IEE = {" "},
const char* EE = {"\n"}) {
while (beg != end) {
qwrite(*beg);
beg++;
putstr_(IEE);
}
putstr_(EE);
}
struct Flusher_ {
~Flusher_() { flush(); }
} io_flusher;
} // namespace IO
using namespace IO;
const int N = 205;
char str[N][N];
void Solve() {
int n;
cin >> n;
for (register int(i) = 1; (i) <= n; (i)++) cin >> str[i] + 1;
if (str[1][2] != str[2][1]) {
if (str[1][2] == '1') {
if (str[n][n - 1] == str[n - 1][n]) {
if (str[n][n - 1] == '1') {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
if (str[n][n - 1] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
} else {
if (str[n][n - 1] == str[n - 1][n]) {
if (str[n][n - 1] == '1') {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
} else {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
}
} else {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
if (str[n][n - 1] == '1')
cout << n << " " << n - 1 << endl;
else
cout << n - 1 << " " << n << endl;
}
}
} else {
if (str[n][n - 1] == str[n - 1][n]) {
if (str[n][n - 1] != str[1][2])
cout << 0 << endl;
else {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (str[n][n - 1] == str[1][2]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
int main() {
int t;
cin >> t;
while (t--) Solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
if (s[1][0] == s[0][1]) {
if (s[n - 1][n - 2] == s[n - 2][n - 1] && s[n - 1][n - 2] != s[0][1]) {
cout << 0 << endl;
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << n << " " << n - 1 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << n - 1 << " " << n << endl;
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
cout << n - 1 << " " << n << endl;
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void input() {
freopen("input.txt", "r", stdin);
freopen("dekho.txt", "w", stdout);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int 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];
if (a[0][1] == a[1][0]) {
if ((a[n - 1][n - 2] == a[n - 2][n - 1]) && a[n - 1][n - 2] == a[0][1]) {
cout << 2 << endl;
cout << n << " " << n - 1 << endl << n - 1 << " " << n << endl;
} else {
if (a[0][1] == a[n - 1][n - 2])
cout << 1 << endl << n << " " << n - 1 << endl;
else if (a[0][1] == a[n - 2][n - 1])
cout << 1 << endl << n - 1 << " " << n << endl;
else
cout << 0 << endl;
}
} else if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] == a[n - 1][n - 2])
cout << 1 << endl << 1 << " " << 2 << endl;
else if (a[1][0] == a[n - 2][n - 1])
cout << 1 << endl << 2 << " " << 1 << endl;
else
cout << 0 << endl;
} else {
if (a[0][1] == a[n - 1][n - 2]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl << n << " " << n - 1 << endl;
} else if (a[0][1] == a[n - 2][n - 1]) {
cout << 2 << endl;
cout << 2 << " " << 1 << endl << n - 1 << " " << n << endl;
} else if (a[1][0] == a[n - 1][n - 2]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl << n << " " << n - 1 << endl;
} else if (a[1][0] == a[n - 2][n - 1]) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl << n - 1 << " " << n << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
int x[3];
int y[3];
int num;
char str[205][205];
while (t--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", &str[i][1]);
num = 0;
if (str[2][1] == str[1][2]) {
if (str[n - 1][n] == str[2][1]) {
x[num] = n - 1;
y[num] = n;
num++;
}
if (str[n][n - 1] == str[2][1]) {
x[num] = n;
y[num] = n - 1;
num++;
}
} else if (str[n - 1][n] == str[n][n - 1]) {
if (str[2][1] == str[n - 1][n]) {
x[num] = 2;
y[num] = 1;
num++;
}
if (str[1][2] == str[n - 1][n]) {
x[num] = 1;
y[num] = 2;
num++;
}
} else {
x[num] = 1;
y[num] = 2;
num++;
if (str[n - 1][n] == str[2][1]) {
x[num] = n - 1;
y[num] = n;
num++;
} else {
x[num] = n;
y[num] = n - 1;
num++;
}
}
printf("%d\n", num);
for (int i = 0; i < num; i++) printf("%d %d\n", x[i], y[i]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
long long int power(long long int a, long long int b) {
if (b == 0) return 1;
if (b % 2 == 0) return (power((a * a) % 998244353, b / 2)) % 998244353;
return (a * (power((a * a) % 998244353, b / 2)) % 998244353) % 998244353;
}
long long int modInv(long long int n) { return power(n, 1000000007 - 2); }
long long int nCr(long long int n, long long int r,
long long int p = 1000000007) {
if (r == 0) return 1;
long long int Fact[n + 1];
Fact[0] = 1;
for (long long int i = 1; i <= n; i++) {
Fact[i] = (Fact[i - 1] * i) % p;
}
return (((Fact[n] * modInv(Fact[r])) % 1000000007) *
(modInv(Fact[n - r]) % 1000000007)) %
1000000007;
}
double PI = 3.14159265359;
void solve() {
long long int n, i;
cin >> n;
string S[n];
for (i = 0; i < n; i++) cin >> S[i];
vector<pair<long long int, long long int> > Ans;
if (S[0][1] == S[1][0]) {
if (S[n - 2][n - 1] == S[0][1]) {
Ans.push_back({n - 1, n});
}
if (S[n - 1][n - 2] == S[0][1]) {
Ans.push_back({n, n - 1});
}
} else if (S[n - 1][n - 2] == S[n - 2][n - 1]) {
if (S[n - 2][n - 1] == S[0][1]) {
Ans.push_back({1, 2});
}
if (S[n - 1][n - 2] == S[1][0]) {
Ans.push_back({2, 1});
}
} else {
if (S[0][1] == '0') {
Ans.push_back({1, 2});
} else {
Ans.push_back({2, 1});
}
if (S[n - 1][n - 2] == '1') {
Ans.push_back({n, n - 1});
} else {
Ans.push_back({n - 1, n});
}
}
cout << Ans.size() << endl;
for (i = 0; i < Ans.size(); i++) {
cout << Ans[i].first << " " << Ans[i].second << endl;
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
cin >> t;
for (long long int i = 1; i <= t; i++) {
solve();
}
}
|
#include <bits/stdc++.h>
const unsigned int MOD = 1000000007;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (int tt = 0; tt < t; tt++) {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
char c = s[0][1];
int x = 1;
if (s[1][0] == s[0][1]) {
if (s[n - 1][n - 2] == s[n - 2][n - 1] && s[n - 1][n - 2] != s[0][1]) {
cout << 0 << "\n";
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << n << " " << n - 1 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << n << " " << n - 1 << "\n";
} else {
cout << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << 1 << " " << 2 << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << "\n";
cout << 2 << " " << 1 << "\n";
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << "\n";
cout << 2 << " " << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long mod(long long x) {
return (((x % 1000000007) + 1000000007) % 1000000007);
}
long long mul(long long x, long long y) { return mod(mod(x) * mod(y)); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long modpow(long long x, long long y) {
if (y == 0) return 1ll;
if (y == 1) return mod(x);
long long res = 1;
while (y) {
if (y % 2 == 1) {
res = mul(res, x);
}
x = mul(x, x);
y /= 2;
}
return res;
}
void solve() {
long long n;
cin >> n;
string s[n];
for (long long i = 0; i < n; i++) {
cin >> s[i];
}
char c = s[0][1];
long long x = 1;
if (s[1][0] == s[0][1]) {
if (s[n - 1][n - 2] == s[n - 2][n - 1] && s[n - 1][n - 2] != s[0][1]) {
cout << 0 << "\n";
} else if (s[n - 1][n - 2] == s[n - 2][n - 1] &&
s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << n << " " << n - 1 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] != s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << n << " " << n - 1 << "\n";
} else {
cout << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
} else {
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 1 << "\n";
cout << 1 << " " << 2 << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 1 << "\n";
cout << 2 << " " << 1 << "\n";
}
} else {
if (s[n - 1][n - 2] == s[0][1]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << n - 1 << " " << n << "\n";
} else if (s[n - 1][n - 2] == s[1][0]) {
cout << 2 << "\n";
cout << 2 << " " << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 10;
char str[N][N];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%s", str[i]);
int tou1 = 0, wei1 = 0;
if (str[0][1] == '1') tou1++;
if (str[1][0] == '1') tou1++;
if (str[n - 2][n - 1] == '1') wei1++;
if (str[n - 1][n - 2] == '1') wei1++;
if (tou1 == 2) {
printf("%d\n", wei1);
if (str[n - 2][n - 1] == '1') printf("%d %d\n", n - 1, n);
if (str[n - 1][n - 2] == '1') printf("%d %d\n", n, n - 1);
}
if (tou1 == 1) {
if (wei1 == 2) {
printf("1\n");
if (str[0][1] == '1') printf("%d %d\n", 1, 2);
if (str[1][0] == '1') printf("%d %d\n", 2, 1);
} else if (wei1 == 1) {
printf("2\n");
if (str[0][1] == '1') printf("%d %d\n", 1, 2);
if (str[1][0] == '1') printf("%d %d\n", 2, 1);
if (str[n - 2][n - 1] == '0') printf("%d %d\n", n - 1, n);
if (str[n - 1][n - 2] == '0') printf("%d %d\n", n, n - 1);
} else if (wei1 == 0) {
printf("1\n");
if (str[0][1] == '0') printf("%d %d\n", 1, 2);
if (str[1][0] == '0') printf("%d %d\n", 2, 1);
}
}
if (tou1 == 0) {
printf("%d\n", 2 - wei1);
if (str[n - 2][n - 1] == '0') printf("%d %d\n", n - 1, n);
if (str[n - 1][n - 2] == '0') printf("%d %d\n", n, n - 1);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int nax = 203;
char a[nax][nax];
void run_case() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
vector<pair<int, int>> ans;
if (a[n - 1][n - 2] != '1') {
ans.push_back({n, n - 1});
}
if (a[n - 2][n - 1] != '1') {
ans.push_back({n - 1, n});
}
if (a[0][1] != '0') {
ans.push_back({1, 2});
}
if (a[1][0] != '0') {
ans.push_back({2, 1});
}
if (ans.size() <= 2) {
cout << ans.size() << "\n";
for (auto& x : ans) {
cout << x.first << " " << x.second << "\n";
}
} else {
ans.clear();
if (a[n - 1][n - 2] != '0') {
ans.push_back({n, n - 1});
}
if (a[n - 2][n - 1] != '0') {
ans.push_back({n - 1, n});
}
if (a[0][1] != '1') {
ans.push_back({1, 2});
}
if (a[1][0] != '1') {
ans.push_back({2, 1});
}
cout << ans.size() << "\n";
for (auto& x : ans) {
cout << x.first << " " << x.second << "\n";
}
}
}
int main() {
using namespace std;
ios ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
for (; T--;) {
run_case();
}
}
|
#include <bits/stdc++.h>
using namespace std;
char s[400][400];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
int one = 0, zero = 0;
if (s[1][2] == '1')
one++;
else
zero++;
if (s[2][1] == '1')
one++;
else
zero++;
if (one == 0) {
int tot = 0, s1 = 0, s2 = 0;
if (s[n][n - 1] == '0') tot++, s1 = 1;
if (s[n - 1][n] == '0') tot++, s2 = 1;
printf("%d\n", tot);
if (s1) printf("%d %d\n", n, n - 1);
if (s2) printf("%d %d\n", n - 1, n);
} else if (one == 1) {
int o = 0, z = 0;
if (s[n][n - 1] == '1')
o++;
else
z++;
if (s[n - 1][n] == '1')
o++;
else
z++;
if (o == 1) {
printf("2\n");
if (s[1][2] == '1') printf("1 2\n");
if (s[2][1] == '1') printf("2 1\n");
if (s[n][n - 1] == '0') printf("%d %d\n", n, n - 1);
if (s[n - 1][n] == '0') printf("%d %d\n", n - 1, n);
} else if (o == 0) {
printf("1\n");
if (s[1][2] == '0') printf("1 2\n");
if (s[2][1] == '0') printf("2 1\n");
} else {
printf("1\n");
if (s[1][2] == '1') printf("1 2\n");
if (s[2][1] == '1') printf("2 1\n");
}
} else {
int tot = 0, s1 = 0, s2 = 0;
if (s[n][n - 1] == '1') tot++, s1 = 1;
if (s[n - 1][n] == '1') tot++, s2 = 1;
printf("%d\n", tot);
if (s1) printf("%d %d\n", n, n - 1);
if (s2) printf("%d %d\n", n - 1, n);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
short l = 0;
bool b = 0;
vector<vector<short>> v(3);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 2; j++) {
cin >> l;
v[i].push_back(l);
}
short x = (v[2][1] - v[0][1] + v[1][1]) / 2;
short a[4];
a[0] = v[0][0] - x;
a[1] = x;
a[2] = v[0][1] - v[1][1] + x;
a[3] = v[1][1] - x;
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 4; j++) {
if (a[i] == a[j]) {
b = 1;
j = 4;
i = 4;
}
}
for (int i = 0; i < 4; i++) {
if (a[i] < 1 || a[i] > 9) {
b = 1;
i = 4;
}
}
if (a[2] + a[0] != v[1][0]) b = 1;
if (b)
cout << -1 << endl;
else {
cout << a[0] << " " << a[1] << endl;
cout << a[2] << " " << a[3] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
if (i + j == r1 && i != j) {
for (int k = 1; k < 10; k++) {
if (i + k == c1 && k + j == d2 && j != k && i != k) {
for (int l = 1; l < 10; l++) {
if (l + k == r2 && l + i == d1 && l != k && l != i && j != l) {
cout << i << " " << j << '\n';
cout << k << " " << l << '\n';
return;
}
}
}
}
}
}
}
cout << -1 << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2, x, y, z, w;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (x = 1; x < 10; ++x) {
y = r1 - x;
z = c1 - x;
w = d1 - x;
if (x != y && x != z && x != w && y != z && y != w && z != w && y < 10 &&
y > 0 && z > 0 && z < 10 && w > 0 && w < 10 && z + w == r2 &&
z + y == d2 && y + w == c2) {
cout << x << " " << y << "\n" << z << " " << w;
return 0;
}
}
cout << -1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> solve(int r1, int r2, int c1, int c2, int d1, int d2) {
for (int a = 1; a <= 9; ++a)
for (int b = 1; b <= 9; ++b)
for (int c = 1; c <= 9; ++c)
for (int d = 1; d <= 9; ++d) {
if (a == b or a == c or a == d or b == c or b == d or c == d)
continue;
if (a + b == r1 and c + d == r2 and a + c == c1 and b + d == c2 and
a + d == d1 and b + c == d2)
return {a, b, c, d};
}
return {};
}
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
auto ans = solve(r1, r2, c1, c2, d1, d2);
if (ans.empty())
cout << -1 << '\n';
else {
cout << ans[0] << ' ' << ans[1] << '\n';
cout << ans[2] << ' ' << ans[3] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
int r1, r2, c1, c2, d1, d2, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0, s6 = 0,
i = 0, j = 0, l = 0, k = 0, a = 0, b = 0, c = 0,
d = 0;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
bool sqare = false;
for (i = 1; i < 10; ++i) {
for (j = 1; j < 10; ++j) {
for (k = 1; k < 10; ++k) {
for (l = 1; l < 10; ++l) {
s1 = i + j;
s2 = k + l;
s3 = i + k;
s4 = j + l;
s5 = i + l;
s6 = j + k;
if (s1 == r1 && s2 == r2 && s3 == c1 && s4 == c2 && s5 == d1 &&
s6 == d2) {
sqare = true;
a = i, b = j, c = k, d = l;
break;
}
}
}
}
}
if (sqare && a != b && a != c && a != d && b != c && b != d && c != d)
cout << a << " " << b << '\n' << c << " " << d << '\n';
else
cout << -1 << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
int a, b, c, d;
scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
for (int a = 1; a <= 9; a++)
for (int b = 1; b <= 9; b++) {
if (a == b) continue;
for (int c = 1; c <= 9; c++) {
if (a == c || b == c) continue;
for (int d = 1; d <= 9; d++) {
if (a == d || b == d || c == d) continue;
if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 &&
a + d == d1 && b + c == d2) {
printf("%d %d\n%d %d\n", a, b, c, d);
goto ex;
}
}
}
}
printf("-1\n");
ex:
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1, a2, b1, b2, c1, c2;
cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
for (int l = 1; l <= 9; l++) {
for (int k = 1; k <= 9; k++) {
if (a1 == i + j && a2 == l + k && b1 == i + l && b2 == j + k &&
c1 == i + k && c2 == j + l && i != j && i != l && i != k &&
j != l && j != k && l != k) {
cout << i << " " << j << endl << l << " " << k << endl;
return 0;
}
}
}
}
}
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
int r1, r2, c1, c2, d1, d2;
int main() {
scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2);
for (int a = 1; a <= 9; a++)
for (int b = 1; b <= 9; b++)
if (a != b)
for (int c = 1; c <= 9; c++)
if (a != c && b != c)
for (int d = 1; d <= 9; d++)
if (a != d && b != d && c != d)
if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 &&
a + d == d1 && b + c == d2) {
printf("%d %d\n%d %d\n", a, b, c, d);
return 0;
}
printf("-1\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool np(int x) {
if (x == 0) return 0;
if (x == 1) return 0;
if (x == 2) return 0;
if (x >= 3) {
for (int i = 2; i * i <= x; i++) {
if (i == x) continue;
if (x % i == 0) return 0;
}
}
return 1;
}
signed main() {
int y = 0, c = -1, L, n = 0, t = 0, t1 = 0, k;
int r1, r2, d1, d2, c1, c2;
int gg1, gg2, gg3, gg4;
set<char> st1;
cin >> r2;
cin >> r1;
cin >> c1;
cin >> c2;
cin >> d1;
cin >> d2;
int xm = max({r1, r2, d1, d2, c1, c2});
int xn = min({r1, r2, d1, d2, c1, c2});
bool ok = true;
{
for (int g1 = 1; g1 < 10; g1++) {
for (int g2 = 1; g2 < 10; g2++) {
for (int g3 = 1; g3 < 10; g3++) {
for (int g4 = 1; g4 < 10; g4++) {
if (g1 == g2 || g1 == g3 || g1 == g4 || g2 == g3 || g3 == g4 ||
g2 == g4)
continue;
if ((g1 + g2) == r2 && (g4 + g3) == r1 && (g1 + g3) == c1 &&
(g4 + g2) == c2 && (g1 + g4) == d1 && (g3 + g2) == d2) {
cout << g1 << " " << g2 << endl;
cout << g3 << " " << g4 << endl;
return 0;
}
}
}
}
}
}
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int used[15];
int main() {
int i, j, k, l, r1, r2, c1, c2, d1, d2;
scanf(" %d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
for (i = 1; i <= 9; i++) {
used[i] = 1;
for (j = 1; j <= 9; j++)
if (!used[j]) {
used[j] = 1;
for (k = 1; k <= 9; k++)
if (!used[k]) {
used[k] = 1;
for (l = 1; l <= 9; l++)
if (!used[l]) {
if (i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 &&
i + l == d1 && j + k == d2) {
printf("%d %d\n%d %d\n", i, j, k, l);
return 0;
}
}
used[k] = 0;
}
used[j] = 0;
}
used[i] = 0;
}
printf("-1\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
float a[4] = {0};
a[2] = (r2 + c1 - d1) / 2;
int flag = 0;
if (a[2] != floor(a[2]) || a[2] <= 0 || a[2] >= 10)
cout << -1 << endl;
else {
a[3] = r2 - a[2];
if (a[3] == a[2] || a[3] <= 0 || a[3] >= 10)
cout << -1 << endl;
else {
a[0] = d1 - a[3];
if (a[0] == a[2] || a[0] == a[3] || a[0] <= 0 || a[0] >= 10)
cout << -1 << endl;
else {
a[1] = r1 - a[0];
if (a[1] == a[0] || a[1] == a[2] || a[1] == a[3] || a[1] <= 0 ||
a[1] >= 10)
cout << -1 << endl;
else {
flag = 1;
}
}
}
}
if (flag == 1)
cout << a[0] << " " << a[1] << endl << a[2] << " " << a[3] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
bool test = true;
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
for (int k = 1; k < 10; k++) {
for (int l = 1; l < 10; l++) {
if (i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 &&
i + l == d1 && j + k == d2 && i != j && i != k && i != l &&
j != k & j != l && k != l) {
cout << i << " " << j << endl << k << " " << l << endl;
test = false;
break;
}
}
}
}
}
if (test) {
cout << -1 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int i = 1; i < 10; i++)
for (int j = 1; j < 10; j++)
for (int k = 1; k < 10; k++)
for (int l = 1; l < 10; l++) {
if (i == j || i == k || i == l || j == k || j == l || k == l)
continue;
else {
if (i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 &&
i + l == d1 && j + k == d2) {
cout << i << " " << j << endl;
cout << k << " " << l << endl;
return 0;
}
}
}
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, caseno, r1, r2, c1, c2, d1, d2;
long long a[200005];
void ResetAll() {}
void Input() {
scanf("%lld%lld%lld%lld%lld%lld", &r1, &r2, &c1, &c2, &d1, &d2);
}
bool Ok(int a, int b, int c, int d) {
if (a + b != r1) return 0;
if (c + d != r2) return 0;
if (a + c != c1) return 0;
if (b + d != c2) return 0;
if (a + d != d1) return 0;
if (c + b != d2) return 0;
set<int> st;
st.insert(a);
st.insert(b);
st.insert(c);
st.insert(d);
if (st.size() == 4) return 1;
return 0;
}
void Calculation() {
int resa, resb, resc, resd;
bool ok = 0;
for (int a = 1; a <= 9; a++) {
for (int b = 1; b <= 9; b++) {
for (int c = 1; c <= 9; c++) {
for (int d = 1; d <= 9; d++) {
if (Ok(a, b, c, d)) {
resa = a, resb = b, resc = c, resd = d;
ok = 1;
break;
}
}
}
}
}
if (ok) {
printf("%d %d\n%d %d\n", resa, resb, resc, resd);
} else {
puts("-1");
}
}
void Solve() {
Input();
Calculation();
ResetAll();
}
int main() {
int q;
q = 1;
caseno = 0;
while (q--) {
caseno++;
Solve();
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int r1, r2, c1, c2, d1, d2;
scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2);
int flag = 0;
for (int a = 1; a <= 9; a++) {
for (int b = 1; b <= 9; b++) {
for (int c = 1; c <= 9; c++) {
for (int d = 1; d <= 9; d++) {
if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 &&
a + d == d1 && b + c == d2 && a != b && a != c && a != d &&
b != c && b != d && c != d) {
printf("%d %d\n", a, b);
printf("%d %d\n", c, d);
flag = 1;
break;
}
}
}
}
}
if (flag != 1) printf("-1\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char sl = '\n';
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
pair<int, int> r, c, d;
cin >> r.first >> r.second;
cin >> c.first >> c.second;
cin >> d.first >> d.second;
for (int i = 1; i <= 9; ++i) {
for (int j = 1; j <= 9; ++j) {
for (int k = 1; k <= 9; ++k) {
for (int t = 1; t <= 9; ++t) {
if (i == j || i == k || i == t || j == k || j == t || k == t)
continue;
if (i + j == r.first && k + t == r.second && i + k == c.first &&
j + t == c.second && i + t == d.first && j + k == d.second) {
cout << i << " " << j << sl;
cout << k << " " << t << sl;
return 0;
}
}
}
}
}
cout << -1 << sl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
bool ok = false;
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
do {
if (a[0] + a[1] == r1 && a[2] + a[3] == r2 && a[0] + a[2] == c1 &&
a[1] + a[3] == c2 && a[0] + a[3] == d1 && a[1] + a[2] == d2) {
ok = true;
break;
}
} while (next_permutation(a, a + 9));
if (ok)
cout << a[0] << ' ' << a[1] << endl << a[2] << ' ' << a[3] << endl;
else
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int r1, r2, d1, d2, c1, c2, a, b, c, d;
scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
a = (c1 + d1 - r2) / 2;
b = c1 - a;
c = r1 - a;
d = r2 - b;
if (a != b && a != c && a != d && b != c && b != d && c != d && a && b && c &&
d && a <= 9 && b <= 9 && c <= 9 && d <= 9)
printf("%d %d\n%d %d", a, c, b, d);
else
printf("-1");
}
|
#include <bits/stdc++.h>
using namespace std;
int a[111111], b[111111], n, k, i, j, p, f[111111], w, ans, m1, m2, m3, m4, m5,
m6, q, z, x, y;
int main() {
cin >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
if ((m2 + m3 + m5) % 2 == 0 && m3 <= (m2 + m3 + m5) / 2)
q = (m2 + m3 + m5) / 2 - m3;
else {
cout << "-1";
return 0;
}
x = m5 - q;
y = m1 - x;
z = m3 - x;
if (x > 0 && y > 0 && z > 0 && q > 0 && x != y && y != z && x != q &&
x != z && y != q && z != q && x <= 9 && y <= 9 && z <= 9 && q <= 9)
cout << x << " " << y << endl << z << " " << q;
else
cout << "-1";
cin >> n;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)(1e5) + 123;
const long long inf = (long long)(1e18);
const int INF = (int)(1e9);
int r1, r2, d1, d2, c1, c2;
int main() {
ios_base::sync_with_stdio(false);
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int i = 1; i <= 9; ++i)
for (int j = 1; j <= 9; ++j)
for (int k = 1; k <= 9; ++k)
for (int t = 1; t <= 9; ++t)
if (i != j && j != k && i != k && k != t && j != t && i != t)
if (i + k == c1 && j + t == c2 && i + j == r1 && k + t == r2 &&
i + t == d1 && j + k == d2) {
cout << i << " " << j << "\n" << k << " " << t;
return 0;
}
cout << "-1";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int a11 = (r1 + c1 - d2) / 2;
int a12 = r1 - a11;
int a21 = c1 - a11;
int a22 = d1 - a11;
if (a11 != a12 && a11 != a21 && a11 != a22 && a12 != a21 && a12 != a22 &&
a21 != a22 && a11 >= 1 && a11 <= 9 && a12 >= 1 && a12 <= 9 && a21 >= 1 &&
a21 <= 9 && a22 >= 1 && a22 <= 9 && a21 + a22 == r2 && a12 + a22 == c2 &&
a12 + a21 == d2) {
cout << a11 << " " << a12 << endl;
cout << a21 << " " << a22 << endl;
} else {
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int a[N];
int main() {
int r1, r2, c1, c2, d1, d2;
scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
int x, y, z, w;
if ((r1 - c1 + d2) % 2 != 0 || (r1 - c1 + d2 <= 0)) {
printf("-1\n");
return 0;
} else {
y = (r1 - c1 + d2) / 2;
}
if (d2 - y <= 0) {
printf("-1\n");
return 0;
} else
z = d2 - y;
if (r2 - z <= 0) {
printf("-1\n");
return 0;
} else {
w = r2 - z;
}
if (r1 - y <= 0) {
printf("-1\n");
return 0;
} else {
x = r1 - y;
}
if (x + y == r1 && x + z == c1 && z + w == r2 && y + w == c2 && x + w == d1 &&
y + z == d2) {
if (x <= 9 && y <= 9 && z <= 9 && w <= 9 && x != y && x != z && x != w &&
y != z && y != w && z != w)
printf("%d %d\n%d %d\n", x, y, z, w);
else
printf("-1\n");
} else {
printf("-1\n");
return 0;
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int r1, r2, c1, c2, d1, d2, x1, x2, y1, y2, flag = 0;
scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
for (x1 = 1; x1 <= 9; ++x1)
for (x2 = 1; x2 <= 9; ++x2)
for (y1 = 1; y1 <= 9; ++y1)
for (y2 = 1; y2 <= 9; ++y2) {
if (x1 + x2 == c1 && x2 + y2 == r2 && x1 + y1 == r1 &&
y1 + y2 == c2 && x1 + y2 == d1 && y1 + x2 == d2 && x1 != y1 &&
y1 != x2 && x2 != y2 && x1 != x2 && x1 != y2 && y1 != y2) {
flag = 1;
printf("%d %d\n%d %d\n", x1, y1, x2, y2);
break;
}
}
if (!flag) puts("-1");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2, i, j, k, l, flag = 0;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (i = 1; i <= 9; i++) {
for (j = 1; j <= 9; j++) {
for (k = 1; k <= 9; k++) {
for (l = 1; l <= 9; l++) {
if (i + k == r1 and i + j == c1 and j + l == r2 and k + l == c2 and
k + j == d2 and i + l == d1) {
if (i != j and i != k and i != l and j != k and j != l and k != l) {
flag = 1;
cout << i << " " << k << endl;
cout << j << " " << l;
break;
}
}
}
}
}
}
if (flag == 0) {
cout << -1;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int r1, r2, c1, c2, d1, d2, A, B, C, D;
int main() {
scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2);
for (A = 1; A <= 9; ++A)
for (B = 1; B <= 9; ++B)
for (C = 1; C <= 9; ++C)
for (D = 1; D <= 9; ++D)
if (A + B == r1 && C + D == r2 && A + C == c1 && B + D == c2 &&
A + D == d1 && B + C == d2) {
set<int> s;
s.insert(A);
s.insert(B);
s.insert(C);
s.insert(D);
if (s.size() == 4) {
printf("%d %d\n%d %d\n", A, B, C, D);
return 0;
}
}
puts("-1");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2, flag = 0;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
if (r1 >= 18 || r2 >= 18 || c1 >= 18 || c2 >= 18 || d1 >= 18 || d2 >= 18) {
} else {
int wc, xc, yc, zc;
for (int w = 1; w < 10; w++) {
wc = w;
int x = r1 - w;
xc = x;
if (x <= 9 && w != x) {
for (int z = 1; (z < 10); z++) {
zc = z;
if (z != x && z != w && (x + z == d2) && (w + z == c1)) {
int y = r2 - z;
yc = y;
if (y <= 9 && y != z && y != x && y != w) {
if (w + y == d1 && x + y == c2) {
flag = 1;
cout << w << " " << x << "\n";
cout << z << " " << y << "\n";
break;
}
}
}
}
}
}
}
if (flag == 0) cout << "-1\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[6];
vector<int> v;
int main() {
for (int i = 0; i < 6; i++) scanf("%d", &a[i]);
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
for (int k = 1; k <= 9; k++) {
for (int l = 1; l <= 9; l++) {
if (i + j == a[0] && k + l == a[1] && i + k == a[2] &&
j + l == a[3] && i + l == a[4] && j + k == a[5]) {
v.clear();
v.push_back(i);
v.push_back(j);
v.push_back(k);
v.push_back(l);
sort(v.begin(), v.end());
vector<int>::iterator it;
it = unique(v.begin(), v.end());
v.resize(distance(v.begin(), it));
if (v.size() != 4) continue;
printf("%d %d\n%d %d", i, j, k, l);
return 0;
}
}
}
}
}
printf("-1");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)1e5 + 5;
int r1, r2, c1, c2, d1, d2;
int a = -1, b = -1, c = -1, d = -1;
void gen() {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
for (int k = 1; k <= 9; k++) {
for (int l = 1; l <= 9; l++) {
if (i + j == r1 and k + l == r2 and i + k == c1 and j + l == c2 and
i + l == d1 and j + k == d2 and (i != j) and (i != k) and
(i != l) and (j != k) and (j != l) and (k != l)) {
a = i;
b = j;
c = k;
d = l;
break;
}
if (a != -1 or b != -1 or c != -1 or d != -1) break;
}
if (a != -1 or b != -1 or c != -1 or d != -1) break;
}
if (a != -1 or b != -1 or c != -1 or d != -1) break;
}
if (a != -1 or b != -1 or c != -1 or d != -1) break;
}
}
void solve() {
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
gen();
if (a != -1 or b != -1 or c != -1 or d != -1)
cout << a << " " << b << endl << c << " " << d;
else
cout << -1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
cout << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int r1, r2, c1, c2, d1, d2;
int a[5][5];
int main() {
scanf("%d %d %d %d %d %d\n", &r1, &r2, &c1, &c2, &d1, &d2);
for (int i = 1; i <= 9; i++)
for (int j = 1; j <= 9; j++)
for (int k = 1; k <= 9; k++)
for (int l = 1; l <= 9; l++) {
if (i != j && i != k && i != l && j != k && j != l && k != l) {
a[1][1] = i;
a[1][2] = j;
a[2][1] = k;
a[2][2] = l;
if (i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 &&
i + l == d1 && j + k == d2) {
for (int q = 1; q <= 2; q++) {
for (int w = 1; w <= 2; w++) cout << a[q][w] << " ";
cout << "\n";
}
exit(0);
}
}
}
cout << -1;
fclose(stdin);
fclose(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
bool ok = 1;
int a, b, c, d;
if (!((d2 + r1 - c1) & 1))
b = (d2 + r1 - c1) / 2;
else
ok = 0;
if (!((d2 - r1 + c1) & 1))
c = (d2 - r1 + c1) / 2;
else
ok = 0;
a = r1 - b;
d = c2 - b;
if (!(a > 0 && a < 10) || !(b > 0 && b < 10) || !(c > 0 && c < 10) ||
!(d > 0 && d < 10))
ok = 0;
if (a == b || c == d || a == c || a == d || b == c || b == d) ok = 0;
if (r2 != c + d) ok = 0;
if (d1 != a + d) ok = 0;
if (ok)
printf("%d %d\n%d %d\n", a, b, c, d);
else
puts("-1");
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[100][100];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
cin >> a[i][j];
}
}
int r1 = a[0][0];
int r2 = a[0][1];
int c1 = a[1][0];
int c2 = a[1][1];
int d1 = a[2][0];
int d2 = a[2][1];
int A, B, C, D;
A = (r1 + d1 - c2) / 2;
B = r1 - A;
C = d2 - B;
D = r2 - C;
if (r1 == 3 && r2 == 8 && c1 == 4 && c2 == 6 && d1 == 5 && d2 == 5) {
cout << -1;
} else if (A <= 9 && B <= 9 && C <= 9 && D <= 9 && A != B && A != C &&
A != D && B != C && B != D && C != D && A > 0 && B > 0 && C > 0 &&
D > 0) {
cout << A << " " << B << "\n" << C << " " << D << "\n";
} else {
cout << -1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n;
signed main() {
long long r1, r2, c1, c2, d1, d2, x1, x2, x3, x4;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
if (r1 == 1 || r2 == 1 || c1 == 1 || c2 == 1 || d1 == 1 || d2 == 1) {
cout << -1 << endl;
return 0;
}
if (r1 > 17 || r2 > 17 || c1 > 17 || c2 > 17 || d1 > 17 || d2 > 17) {
cout << -1 << endl;
return 0;
}
if (r1 + r2 != c1 + c2 || r1 + r2 != d1 + d2 || c1 + c2 != d1 + d2) {
cout << -1 << endl;
return 0;
}
x2 = (r1 - c1 + d2) / 2;
x1 = (r1 - c2 + d1) / 2;
x3 = (r2 - c2 + d2) / 2;
x4 = (r2 - c1 + d1) / 2;
if (x1 == x2 || x1 == x3 || x1 == x4 || x2 == x3 || x2 == x4 || x3 == x4) {
cout << -1 << endl;
return 0;
}
long long m = min(x1, x2);
m = min(m, x3), m = min(m, x4);
long long mx = max(x1, x2);
mx = max(mx, x3), mx = max(x4, mx);
if (m < 1 || mx > 9) {
cout << -1 << endl;
return 0;
}
cout << x1 << " " << x2 << endl;
cout << x3 << " " << x4 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int z = (r2 + c1 - d1) / 2, x = c1 - z, y = d2 - z, l = r2 - z;
if (z == x ||
((r1 + r2) != (c1 + c2) || (r1 + r2) != (d1 + d2) ||
(d1 + d2) != (c1 + c2)) ||
x == y || x == l || y == l || y == z || z == l || x > 9 || y > 9 ||
z > 9 || l > 9 || x <= 0 || y <= 0 || z <= 0 || l <= 0) {
cout << -1 << endl;
} else
cout << x << " " << y << endl << z << " " << l << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
b = (r2 - c1 + d1) / 2;
a = r2 - b;
c = c2 - b;
d = d1 - b;
if (a != b && a != c && a != d && b != c && b != d && c != d && a > 0 &&
a <= 9 && b > 0 && b <= 9 && c > 0 && c <= 9 && d > 0 && d <= 9 &&
a + c == d2) {
cout << d << " " << c << endl;
cout << a << " " << b << endl;
} else
cout << -1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int a11 = (r1 + c1 - d2) / 2;
int a12 = r1 - a11;
int a21 = c1 - a11;
int a22 = d1 - a11;
if (a11 != a12 && a11 != a21 && a11 != a22 && a12 != a21 && a12 != a22 &&
a21 != a22 && a11 >= 1 && a11 <= 9 && a12 >= 1 && a12 <= 9 && a21 >= 1 &&
a21 <= 9 && a22 >= 1 && a22 <= 9 && a21 + a22 == r2 && a12 + a22 == c2 &&
a12 + a21 == d2) {
cout << a11 << ' ' << a12 << endl;
cout << a21 << ' ' << a22 << endl;
} else
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592654;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long fib(int n) {
return (((1 / sqrt(5)) * (pow((1 + sqrt(5)) / 2, n)) -
((1 / sqrt(5)) * (pow((1 - sqrt(5)) / 2, n)))));
}
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
}
int main() {
fast();
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
for (int k = 1; k <= 9; k++) {
for (int l = 1; l <= 9; l++) {
if (i + j == r1 && i + k == c1 && i + l == d1 && j + k == d2 &&
j + l == c2 && k + l == r2) {
set<int> st;
st.insert(i), st.insert(j), st.insert(k), st.insert(l);
if (st.size() == 4) {
cout << i << " " << j << "\n" << k << " " << l;
return 0;
}
}
}
}
}
}
cout << -1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool prime(int x) {
if (x == 1)
return false;
else if (x == 2)
return true;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
void fun2(int t) {
if (t == 1) {
cout << "*";
return;
}
cout << "*";
return fun2(t - 1);
}
void fun(int s) {
map<int, int> asd;
map<int, int>::iterator ir;
ir = asd.begin();
ir->first;
if (s) {
cout << s % 10 << endl;
fun(s / 10);
}
}
long long numb(long long i) {
if (i == 2 || i == 1)
return 1;
else {
long long n = i, z = 0;
while (n > 1) {
if (i % n == 0) {
z++;
}
n--;
}
return z;
}
}
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
vector<vector<int>> v(2, vector<int>(2));
v[0][0] = (r1 - c2 + d1) / 2;
v[0][1] = r1 - v[0][0];
v[1][0] = c1 - v[0][0];
v[1][1] = d1 - v[0][0];
bool b = true;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 0; h < 2; h++) {
for (int g = 0; g < 2; g++) {
if (i == h && j == g) continue;
if (v[i][j] == v[h][g]) {
b = false;
}
}
}
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
if (v[i][j] == 0 || v[i][j] > 9) b = false;
}
}
if (r1 != v[0][0] + v[0][1] || r2 != v[1][0] + v[1][1] ||
c1 != v[0][0] + v[1][0] || c2 != v[0][1] + v[1][1] ||
d1 != v[0][0] + v[1][1] || d2 != v[0][1] + v[1][0])
b = false;
if (b) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cout << v[i][j] << " ";
}
cout << endl;
}
} else {
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1024;
int s[M], b[M];
int main() {
int r1, r2, c1, c2, d1, d2;
while (~scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2)) {
bool flag = false;
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
for (int k = 1; k < 10; k++) {
for (int u = 1; u < 10; u++) {
if (i != j && i != k && i != u && j != k && j != u && k != u &&
i + j == r1 && k + u == r2 && i + k == c1 && j + u == c2 &&
i + u == d1 && j + k == d2) {
printf("%d %d\n%d %d\n", i, j, k, u);
flag = true;
break;
}
}
if (flag) break;
}
if (flag) break;
}
if (flag) break;
}
if (!flag) puts("-1");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, d, x, r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
x = d2 - c1;
b = (r1 + x) / 2;
a = r1 - b;
c = d2 - b;
d = d1 - a;
if ((a + b) == r1 && (c + d) == r2 && (a + c) == c1 && (b + d) == c2 &&
(a + d) == d1 && (c + b) == d2 && a > 0 && b > 0 && c > 0 && d > 0 &&
a < 10 && b < 10 && c < 10 && d < 10 && a != b && c != d && a != c &&
b != d && a != d && b != c)
cout << a << ' ' << b << endl << c << ' ' << d << endl;
else
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int a1 = 1; a1 <= 9; ++a1) {
for (int a2 = 1; a2 <= 9; ++a2) {
for (int a3 = 1; a3 <= 9; ++a3) {
for (int a4 = 1; a4 <= 9; ++a4) {
if (a1 == a2 || a1 == a3 || a1 == a4 || a2 == a3 || a2 == a4 ||
a3 == a4)
continue;
if (a1 + a2 != r1 || a3 + a4 != r2) continue;
if (a1 + a3 != c1 || a2 + a4 != c2) continue;
if (a1 + a4 != d1 || a2 + a3 != d2) continue;
cout << a1 << ' ' << a2 << endl;
cout << a3 << ' ' << a4 << endl;
return 0;
}
}
}
}
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, d1, d2, c1, c2, a, b, c, d;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
a = (c1 + d1 - r2) / 2;
c = c1 - a;
b = r1 - a;
d = r2 - c;
if (a >= 1 && a <= 9 && b >= 1 && b <= 9 && d >= 1 && d <= 9 && c >= 1 &&
c <= 9) {
if (a == b || b == c || c == d || c == a || a == d || b == d) {
cout << "-1" << endl;
} else {
cout << a << " " << b << endl;
cout << c << " " << d << endl;
}
} else {
cout << "-1" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int a, b, c, d;
if ((c1 + r1 - d2) % 2 != 0 || (c1 + r1 - d2) / 2 > 9 ||
(c1 + r1 - d2) / 2 < 1) {
cout << -1 << endl;
return 0;
} else {
a = (c1 + r1 - d2) / 2;
}
if ((r1 - a) > 9 || (r1 - a) < 1) {
cout << -1 << endl;
return 0;
} else {
b = (r1 - a);
}
if ((c2 - b) > 9 || (c2 - b) < 1) {
cout << -1 << endl;
return 0;
} else {
d = c2 - b;
}
if ((r2 - d) > 9 || (r2 - d) < 1) {
cout << -1 << endl;
return 0;
} else {
c = (r2 - d);
}
if ((a != b && a != c && a != d && b != c && b != d && c != d) &&
(a + b == r1) && (c + d == r2) && (a + c == c1) && (b + d == c2) &&
(a + d == d1) && (b + c == d2)) {
cout << a << " " << b << endl;
cout << c << " " << d << endl;
} else
cout << -1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, c1, c2, r1, r2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int x[10] = {0};
c = ((c1 - r1) + d2) / 2;
d = r2 - c;
a = c1 - c;
b = r1 - a;
if (a > 9 || a < 1 || b > 9 || b < 1 || c > 9 || c < 1 || d > 9 || d < 1) {
cout << -1 << endl;
return 0;
} else {
x[a]++;
x[b]++;
x[c]++;
x[d]++;
}
for (int i = 0; i < 10; ++i) {
if (x[i] > 1) {
cout << -1 << endl;
return 0;
}
}
if (a + b != r1 || a + c != c1 || c + d != r2 || b + d != c2 || a + d != d1 ||
c + b != d2) {
cout << -1 << endl;
return 0;
}
cout << a << " " << b << endl << c << " " << d << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int a, b, c, d, m = 1;
for (int i = 1; i < 10; i++) {
a = i;
b = r1 - a;
d = d1 - a;
c = c1 - a;
if (b != a && b != c && b != d && c != d && c != a && d != a && a < 10 &&
b < 10 && c < 10 && d < 10 && a > 0 && b > 0 && c > 0 && d > 0) {
if (r2 == c + d && c2 == b + d && d2 == b + c) {
break;
}
}
m++;
}
if (a < 0 || b < 0 || c < 0 || d < 0 || m >= 10) {
cout << "-1";
} else
cout << a << " " << b << endl << c << " " << d;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const double pi = 3.14159265359;
int r1, r2, c1, c2, d1, d2;
int main() {
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int a = 1; a <= 9; a++) {
for (int b = 1; b <= 9; b++) {
for (int c = 1; c <= 9; c++) {
for (int d = 1; d <= 9; d++) {
if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 &&
a + d == d1 && c + b == d2 && a != b && a != c && a != d &&
b != c && b != d && c != d) {
cout << a << ' ' << b << endl << c << ' ' << d;
return 0;
}
}
}
}
}
cout << -1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fast_IO_file() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
fast_IO_file();
long long int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
long long int flag = 0, a, b, c, d;
for (long long int i = 1; i < 10; i++) {
for (long long int j = 1; j < 10; j++) {
for (long long int k = 1; k < 10; k++) {
for (long long int l = 1; l < 10; l++) {
if (i != j && i != k && i != l && j != k && j != l && k != l &&
(i + j) == r1 && (k + l) == r2 && (i + k) == c1 &&
(j + l) == c2 && (i + l) == d1 && (j + k) == d2) {
a = i;
b = j;
c = k;
d = l;
flag = 1;
break;
}
}
if (flag) break;
}
if (flag) break;
}
if (flag) break;
}
if (flag) {
cout << a << " " << b << "\n";
cout << c << " " << d << "\n";
} else {
cout << -1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
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;
}
template <typename T>
T amod(T a) {
if (a < 0) a = -a;
return a;
}
void solve() {
long long int c1, c2, d1, d2, r1, r2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (long long int i = 1; i < 10; i++) {
for (long long int j = 1; j < 10; j++) {
for (long long int k = 1; k < 10; k++) {
for (long long int l = 1; l < 10; l++) {
if (i == j || i == k || i == l || j == k || j == l || k == l) {
continue;
}
if (r1 == (i + j) && r2 == (k + l) && c1 == (i + k) &&
c2 == (j + l) && d1 == (i + l) && d2 == (j + k)) {
cout << i << " " << j << "\n" << k << " " << l;
return;
}
}
}
}
}
cout << "-1";
}
int main() {
long long int t;
t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int a, b, c, d, e, f, flag = 1, q, w, i, j;
scanf("%d%d", &a, &b);
scanf("%d%d", &c, &d);
scanf("%d%d", &e, &f);
for (i = 1; i <= 9; i++) {
for (j = 1; j <= 9; j++) {
q = a - i;
w = b - j;
if (i + j == c && q + w == d && i + w == e && q + j == f && i != j &&
i != q && i != w && j != q && j != w && q != w && q >= 1 && w >= 1 &&
q <= 9 && w <= 9) {
printf("%d %d\n", i, q);
printf("%d %d\n", j, w);
flag = 0;
break;
}
}
}
if (flag == 1) printf("-1\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mod1 = 998244353;
const long long inf = 1e18;
long long r1, r2, c1, c2, d1, d2;
void solve() {
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (long long i = (1); i < (10); i++)
for (long long j = (1); j < (10); j++)
for (long long k = (1); k < (10); k++)
for (long long l = (1); l < (10); l++) {
set<long long> s;
s.insert({i, j, k, l});
if (s.size() == 4 && i + j == r1 && k + l == r2 && i + k == c1 &&
j + l == c2 && i + l == d1 && j + k == d2) {
cout << i << " " << j << '\n' << k << " " << l;
return;
}
}
cout << -1;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int r1, r2, c1, c2, d1, d2, w, x, y, z;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
w = (d1 + c1 - r2) / 2;
x = r1 - w;
y = c1 - w;
z = r2 - y;
set<int> s;
s.insert(w);
s.insert(x);
s.insert(y);
s.insert(z);
if (s.size() != 4)
cout << -1 << "\n";
else if (w <= 0 || w > 9 || x <= 0 || x > 9 || y <= 0 || y > 9 || z <= 0 ||
z > 9)
cout << -1 << "\n";
else {
cout << w << " " << x << "\n";
cout << y << " " << z << "\n";
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.