text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
if (a[0] + a[1] <= a[n - 1])
cout << "1 2 " << n << "\n";
else
cout << "-1"
<< "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 5;
int n, cut, a[sz], dp[sz];
void solve() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
if (a[0] + a[1] <= a[n - 1])
printf("1 2 %d\n", n);
else
puts("-1");
}
int main() {
int t;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
void IO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
template <typename... T>
void read(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void write(T&&... args) {
((cout << args << " "), ...);
}
int mpow(int, int);
long long int n;
void solve() {
read(n);
int a[n];
for (int i = 0; i < n; i += 1) read(a[i]);
int a1 = a[0];
int b = a[1];
int c = a[n - 1];
if ((a1 + b) <= c) {
write(1, 2, n);
} else {
cout << -1;
}
cout << "\n";
}
int main() {
IO();
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
int mpow(int base, int exp) {
base %= 1000000007;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((long long int)result * base) % 1000000007;
base = ((long long int)base * base) % 1000000007;
exp >>= 1;
}
return result;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, true : false;
}
template <typename T>
struct IsC {
template <typename C>
static char test(typename C::const_iterator*);
template <typename C>
static int test(...);
static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&,
const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T>
using TS = tuple_size<tuple<T...>>;
template <size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type operator<<(
ostream& o, const tuple<T...>& t) {
return o << ", " << get<idx>(t) << ')';
}
template <size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template <size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type operator<<(
ostream& o, const tuple<T...>& t) {
return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template <typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
return o << make_tuple(p.first, p.second);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
const C& c) {
o << '[';
for (auto it = c.cbegin(); it != c.cend(); ++it)
o << *it << (next(it) != c.cend() ? ", " : "");
return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
if (!0) return;
for (const auto& vv : v) {
for (const auto& i : vv) o << setw(width) << i;
o << '\n';
}
}
void solve() {
int n;
cin >> n;
int a, b, c;
cin >> a >> b;
for (auto i = (0); (i) < ((n - 2)); ++(i)) cin >> c;
if (a + b <= c)
cout << 1 << ' ' << 2 << ' ' << n << '\n';
else
cout << -1 << '\n';
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int tc = 1;
cin >> tc;
for (auto i = (1); (i) < (tc + 1); ++(i)) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
if (a[0] + a[1] <= a[n - 1])
cout << "1 2 " << n << endl;
else {
cout << "-1" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
bool possible;
long long a1[100000];
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
possible = false;
for (int j = 0; j < n; j++) {
cin >> a1[j];
}
for (int j = 2; j < n; j++) {
if (a1[j] >= a1[0] + a1[1]) {
possible = true;
cout << 1 << " " << 2 << " " << j + 1 << endl;
break;
}
}
if (possible == false) cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (a[n] >= a[1] + a[2]) {
cout << 1 << " " << 2 << " " << n << endl;
} else {
cout << -1 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long int n, temp = 0;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
if (a[0] + a[1] <= a[n - 1]) {
cout << 1 << " " << 2 << " " << n << "\n";
temp = 1;
}
if (temp == 0) cout << -1 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n, flag = 0;
cin >> n;
long long m[n], a[n], i;
for (int i = 1; i <= n; i++) cin >> m[i];
if (m[1] + m[2] <= m[n])
cout << "1 2 " << n << endl;
else
cout << "-1" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using PII = pair<long long, long long>;
const int maxn = 1e5 + 5;
const long long mod = 1e9 + 7;
int a[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (a[1] + a[2] > a[n])
cout << -1 << '\n';
else
cout << "1 2 " << n << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
int n;
cin >> n;
vector<int> array;
int a;
for (int j = 0; j < n; j++) {
cin >> a;
array.push_back(a);
}
int max = array[n - 1];
if (array[0] + array[1] <= max) {
cout << 1 << " " << 2 << " " << n << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long T;
cin >> T;
while (T--) {
long long n;
cin >> n;
long long a[n + 1];
vector<int> vct;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
bool b = false;
bool flag = false;
int k = 3;
for (int i = 3; i <= n; i++) {
vct.push_back(i);
if (a[1] + a[2] <= a[i]) {
k = i;
b = true;
flag = true;
break;
}
}
if (b == true) {
cout << 1 << " " << 2 << " " << k << "\n";
} else {
cout << "-1\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int inf = LLONG_MAX;
const long long int mod = 1e9 + 7;
const long double pi = acos(-1);
void solution() {
long long int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long int ans = a[0] + a[1];
for (int i = 2; i < n; i++) {
if (a[i] >= ans) {
cout << 1 << " " << 2 << " " << i + 1;
return;
}
}
cout << "-1";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long int t;
t = 1;
cin >> t;
while (t--) {
solution();
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void CyBerForCe() {
long long n;
cin >> n;
vector<long long> v;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
v.push_back(a);
}
long long a = 1, b = 2, c = 0;
for (long long i = 2; i < v.size(); i++) {
if (v[i] >= v[0] + v[1]) {
c = i + 1;
break;
}
}
if (c == 0)
cout << "-1\n";
else
cout << a << " " << b << " " << c << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) CyBerForCe();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n + 1];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
if (arr[1] + arr[2] <= arr[n]) {
cout << 1 << " " << 2 << " " << n << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
double pi = 3.141592653589;
void solve() {
long long n;
cin >> n;
long long a[n];
for (long long &i : a) cin >> i;
if (a[0] + a[1] <= a[n - 1]) {
cout << 1 << " " << 2 << " " << n << "\n";
return;
}
cout << -1 << "\n";
}
int32_t main() {
long long x;
cin >> x;
while (x--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long amax(long long a[], long long n) {
long long max = 0;
for (long long i = 0; i < n; i++) {
if (a[i] > max) max = a[i];
}
return max;
}
long long amin(long long a[], long long n) {
long long min = 1000000000;
for (long long i = 0; i < n; i++) {
if (a[i] < min) min = a[i];
}
return min;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long a1 = a[n / 2];
long long b1 = a[(n / 2) - 1];
long long c = a[(n / 2) + 1];
if (a[0] + a[1] <= a[n - 1])
cout << 1 << " " << 2 << " " << n << endl;
else
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
bool isprime(long long int x) {
for (long long int i = 2; i <= sqrt(x); i++) {
if (x % i == 0) return false;
}
return true;
}
long long int modpow(long long int x, long long int y) {
x %= 1000000007;
long long int res = 1;
while (y > 0) {
if (y & 1) res *= x % 1000000007;
y = y >> 1;
x = x * x % 1000000007;
}
return res % 1000000007;
}
long long int ncr(long long int n, long long int k) {
long long int res = 1;
if (k > n - k) k = n - k;
for (long long int i = 0; i < (long long int)k; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
long long int bintodec(long long int n) {
long long int decimal = 0, i = 0, rem;
while (n != 0) {
rem = n % 10;
n /= 10;
decimal += rem * pow(2, i);
++i;
}
return decimal;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int i = 0, n, aa, t;
vector<long long int> a;
cin >> t;
while (t--) {
cin >> n;
for (long long int i = 0; i < (long long int)n; i++) {
cin >> aa;
a.push_back(aa);
}
i = 0;
bool f = false;
if ((a[0] + a[1]) <= a[a.size() - 1]) {
cout << i + 1 << " " << i + 2 << " " << n << '\n';
f = true;
}
if (f == false) cout << -1 << '\n';
a.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long long_max = 9223372036854775807;
const long long inf = INT_MAX;
void pr(long long n) { cout << (n) << "\n"; }
void pr(string s) { cout << (s) << "\n"; }
void pr(string s, string s2) { cout << (s) << " " << (s2) << "\n"; }
void pr(pair<long long, long long> p) {
cout << (p).first << " " << (p).second << "\n";
};
void pr(long long a, long long b) { cout << (a) << " " << (b) << "\n"; }
void pr(long long a, long long b, long long c) {
cout << (a) << " " << (b) << " " << (c) << "\n";
}
void pr(long long a, long long b, long long c, long long d) {
cout << (a) << " " << (b) << " " << (c) << " " << (d) << "\n";
}
void pr(long long a, long long b, long long c, long long d, long long e) {
cout << (a) << " " << (b) << " " << (c) << " " << (d) << " " << (e) << "\n";
}
void pr(vector<long long> v) {
for (int i = 0; i < v.size(); ++i) cout << v[i] << " ";
cout << "\n";
}
void pr(vector<string> v) {
for (int i = 0; i < v.size(); ++i) cout << v[i] << " ";
cout << "\n";
}
void decimal(int);
long long min(long long, long long);
long long max(long long, long long);
long long multi(long long, long long);
long long add(long long, long long);
long long subtract(long long, long long);
long long modpower(long long, long long);
long long gcd(long long, long long);
long long modinv(long long, long long);
long long power(long long, long long);
long long divi(long long, long long);
void subsetsUtil(vector<long long>&, vector<vector<long long> >&,
vector<long long>&, long long);
vector<vector<long long> > subsets(vector<long long>&);
long long ncrmod(long long, long long, long long);
long long ncr(long long, long long);
long long npr(long long, long long);
long long nprmod(long long, long long);
vector<string> permutations(string);
void makeCombiUtil(vector<vector<long long> >&, vector<long long>&, long long,
long long, long long);
vector<vector<long long> > makeCombi(long long, long long);
void printSubSeqRec(string, long long, long long, string);
void printSubSeq(string);
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first == b.first)
return a.second < b.second;
else
return a.first < b.first;
}
long long numdigit(long long n) {
long long cnt = 0;
while (n > 0) {
n /= 10;
cnt++;
}
return cnt;
}
pair<long double, long long> powerldpair(long double, long long);
bool isprime(long long n) {
if (n <= 1) return false;
for (long long i = 2; i <= sqrt(n); ++i)
if (n % i == 0) return false;
return true;
}
bool revcomp(long long a, long long b) { return a > b; }
vector<long long> decToBinary(long long n);
void solve() {
long long n;
cin >> n;
vector<long long> vec(n);
for (long long i = 0; i < (n); ++i) cin >> vec[i];
for (long long i = 0; i < (n - 2); ++i) {
long long th = vec[i] + vec[i + 1];
auto it = lower_bound(vec.begin() + i + 2, vec.end(), th);
if (it != vec.end()) {
pr(i + 1, i + 2, it - vec.begin() + 1);
return;
}
}
pr(-1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
long long min(long long x, long long y) {
if (x > y) return y;
return x;
}
long long max(long long x, long long y) {
if (x > y) return x;
return y;
}
long long add(long long x, long long y) {
return ((x % mod) + (y % mod) + mod) % mod;
}
long long multi(long long x, long long y) {
return ((x % mod) * (y % mod)) % mod;
}
long long subtract(long long x, long long y) {
return ((x % mod) - (y % mod) + mod) % mod;
}
long long divi(long long a, long long b) {
return (a % mod * modpower(b, mod - 2) % mod) % mod;
}
long long modpower(long long x, long long y) {
long long p = mod;
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long power(long long a, long long b) {
long long prod = 1;
while (b) {
if (b & 1) {
prod = (prod * a);
}
a = (a * a);
b >>= 1;
}
return prod;
}
pair<long double, long long> powerldpair(long double a, long long b) {
long double prod = 1;
long long powten = 0;
long long powtemp = 0;
while (b) {
if (b & 1) {
prod = (prod * a);
powten += powtemp;
while (prod >= 10) {
prod /= 10;
powten++;
}
}
a = (a * a);
powtemp *= 2;
while (a >= 10) {
a /= 10;
powtemp++;
}
b >>= 1;
}
return make_pair(prod, powten);
}
long long gcd(long long a, long long b) {
if (b > a) swap(a, b);
if (b == 0)
return a;
else
return gcd(b, a % b);
}
void subsetsUtil(vector<long long>& A, vector<vector<long long> >& res,
vector<long long>& subset, long long index) {
res.push_back(subset);
for (long long i = index; i < A.size(); i++) {
subset.push_back(A[i]);
subsetsUtil(A, res, subset, i + 1);
subset.pop_back();
}
return;
}
vector<vector<long long> > subsets(vector<long long>& A) {
vector<long long> subset;
vector<vector<long long> > res;
long long index = 0;
subsetsUtil(A, res, subset, index);
return res;
}
void decimal(int n) {
cout << fixed;
cout << setprecision(n);
}
vector<long long> decToBinary(long long n) {
long long binaryNum[65] = {0};
int i = 0;
while (n > 0) {
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
vector<long long> bin(65, 0);
for (int j = i - 1; j >= 0; --j) {
bin[j] = binaryNum[j];
}
return bin;
}
long long modinv(long long n, long long p) { return modpower(n, p - 2); }
long long ncrmod(long long n, long long r, long long p) {
if (r == 0) return 1;
long long fac[n + 1];
fac[0] = 1;
for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
return (fac[n] * modinv(fac[r], p) % p * modinv(fac[n - r], p) % p) % p;
}
long long ncr(long long n, long long k) {
long long res = 1;
if (k > n - k) k = n - k;
for (long long i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
long long npr(long long n, long long k) {
long long P = 1;
for (long long i = 0; i < k; i++) P *= (n - i);
return P;
}
long long nprmod(long long n, long long k) {
long long P = 1;
for (long long i = 0; i < k; i++) P = multi(P, n - i);
return P % mod;
}
vector<string> permutations(string str) {
vector<string> vec;
sort(str.begin(), str.end());
do {
vec.push_back(str);
} while (next_permutation(str.begin(), str.end()));
return vec;
}
void makeCombiUtil(vector<vector<long long> >& ans, vector<long long>& tmp,
long long n, long long left, long long k) {
if (k == 0) {
ans.push_back(tmp);
return;
}
for (long long i = left; i <= n; ++i) {
tmp.push_back(i);
makeCombiUtil(ans, tmp, n, i + 1, k - 1);
tmp.pop_back();
}
}
vector<vector<long long> > makeCombi(long long n, long long k) {
vector<vector<long long> > ans;
vector<long long> tmp;
makeCombiUtil(ans, tmp, n, 1, k);
return ans;
}
void printSubSeqRec(string str, long long n, long long index = -1,
string curr = "") {
if (index == n) return;
cout << curr << "\n";
for (long long i = index + 1; i < n; i++) {
curr += str[i];
printSubSeqRec(str, n, i, curr);
curr = curr.erase(curr.size() - 1);
}
return;
}
void printSubSeq(string str) { printSubSeqRec(str, str.size()); }
|
#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void solve() {
long long int n;
cin >> n;
vector<pair<long long int, long long int>> vp;
for (long long int i = 0; i < n; ++i) {
long long int x;
cin >> x;
vp.push_back({x, i + 1});
}
sort(vp.begin(), vp.end());
if ((vp[0].first + vp[1].first) <= vp[n - 1].first) {
long long int arr[3] = {vp[0].second, vp[1].second, vp[n - 1].second};
sort(arr, arr + 3);
for (long long int i = 0; i <= 2; ++i) cout << arr[i] << " ";
} else
cout << "-1";
cout << "\n";
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long t, n, i;
cin >> t;
while (t--) {
cin >> n;
int a[n], x = 0;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 2; i < n; i++) {
if ((a[0] + a[1]) <= a[i]) {
cout << "1"
<< " "
<< "2"
<< " " << i + 1 << endl;
x = 1;
break;
}
}
if (x == 0) cout << "-1" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void think() {
long long n;
cin >> n;
vector<long long> a(n, 0);
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] + a[1] <= a[n - 1]) {
cout << 1 << " " << 2 << " " << n << "\n";
} else {
cout << -1 << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long testcase = 1;
cin >> testcase;
while (testcase--) {
think();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e5 + 10;
int t, n, a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int x = a[1], y = a[2], z = a[n];
if (x + y <= z || y + z <= x || z + x <= y) {
cout << 1 << " " << 2 << " " << n << '\n';
} else
cout << "-1" << '\n';
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
int mod = 1000000007;
using namespace std;
bool isp(long long x) {
for (long long i = 2; i * i <= x; ++i)
if (x % i == 0) return false;
return true;
}
void pog() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
}
bool sortinrev(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return (a.first > b.first);
}
bool prime_check(long long n) {
bool flag = 1;
for (long long i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
flag = 0;
break;
}
}
return flag;
}
long long power(long long x, unsigned long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int32_t main() {
pog();
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) {
cin >> arr[i];
};
long long sum = arr[0] + arr[1];
long long flag = 0;
for (long long i = 2; i < n; i++)
if (sum <= arr[i]) {
flag = i + 1;
break;
}
if (flag)
cout << 1 << " " << 2 << " " << flag << "\n";
else
cout << -1 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
long long mod = 1e9 + 7;
const int N = 5e4 + 10;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
long long T, n, m, x, y, z, ans, tem, cnt;
struct node {
long long id, v;
};
node a[N];
int cmp(node a, node b) { return a.v < b.v; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].v;
a[i].id = i;
}
sort(a + 1, a + n + 1, cmp);
if (a[n].v >= a[1].v + a[2].v) {
cout << a[1].id << " " << a[2].id << " " << a[n].id << "\n";
} else
cout << "-1\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int t, n;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
unsigned long long int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (arr[0] + arr[1] <= arr[n - 1]) {
cout << 1 << " " << 2 << " " << n << "\n";
} else {
cout << "-1\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (arr[0] + arr[1] <= arr[n - 1]) {
cout << "1 2 " << n << "\n";
} else {
cout << "-1"
<< "\n";
}
}
}
|
#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long arr[n];
for (int i = 0; i < n; ++i) cin >> arr[i];
if (arr[0] + arr[1] <= arr[n - 1])
cout << 1 << " " << 2 << " " << n << endl;
else
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int modu = 1e9 + 7;
int noofdig(int N) { return floor(log10(N)) + 1; }
int bits_count(unsigned int u) {
unsigned int uCount;
uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
return ((uCount + (uCount >> 3)) & 030707070707) % 63;
}
long long int f(long long int a) { return 0; }
void pre() {}
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (auto &t : a) cin >> t;
if (a[0] + a[1] <= a[n - 1]) {
cout << 1 << " " << 2 << " " << n << '\n';
return;
}
cout << -1 << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e4 + 5;
int a[MAXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = a[0] + a[1];
int c = -1;
for (int i = 2; i < n; i++) {
if (a[i] >= sum) {
c = i;
break;
}
}
if (c == -1) {
cout << c << endl;
} else {
cout << "1 2 " << c + 1 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int v[500005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, m, d, i, j, t;
cin >> t;
while (t--) {
cin >> n;
for (i = 1; i <= n; ++i) cin >> v[i];
if (v[1] + v[2] > v[n])
cout << -1 << '\n';
else
cout << "1 2 " << n << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << "\n";
}
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...);
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
os << "[ ";
for (auto v : V) os << v << " ";
return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> second) {
os << "{ ";
for (auto s : second) os << s << " ";
return os << "}";
}
template <class T>
ostream& operator<<(ostream& os, unordered_set<T> second) {
os << "{ ";
for (auto s : second) os << s << " ";
return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream& operator<<(ostream& os, map<L, R> M) {
os << "{ ";
for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, unordered_map<L, R> M) {
os << "{ ";
for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
const long long mod = 1e9 + 7;
inline long long add(long long x, long long y) {
x += y;
if (x >= mod) return x - mod;
return x;
}
inline long long sub(long long x, long long y) {
x -= y;
if (x < 0) return x + mod;
return x;
}
inline long long mul(long long x, long long y) { return (x * 1ll * y) % mod; }
inline long long power(long long x, long long y) {
long long ans = 1;
while (y) {
if (y & 1) ans = mul(ans, x);
x = mul(x, x);
y >>= 1;
}
return ans;
}
inline long long inv(long long x) { return power(x, mod - 2); }
const long long maxn = 1e6 + 100;
const long long INF = 1e16 + 7;
const long long MXI = 2e5 + 5;
const long double PI = acos((long double)-1);
const long long xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
void Code_karr_bsdk() {
long long n, data;
cin >> n;
long long a, b, c;
for (long long i = 1; i <= n; i++) {
cin >> data;
if (i == 1) a = data;
if (i == 2) b = data;
if (i == n) c = data;
}
if (a + b <= c)
cout << "1 2 " << n << "\n";
else
cout << "-1\n";
return;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
auto start = std::chrono::high_resolution_clock::now();
long long t = 1;
cin >> t;
while (t--) {
Code_karr_bsdk();
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 0;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] + a[1] <= a[n - 1]) {
cout << 1 << " " << 2 << " " << n << "\n";
} else
cout << -1 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << ") ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
int const lmt = 2e5 + 5;
int a[lmt];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
for (long long i = 0; i < n; i++) cin >> a[i];
if (a[0] + a[1] <= a[n - 1]) {
cout << 1 << " ";
cout << 2 << " ";
cout << n << "\n";
} else {
cout << -1 << "\n";
}
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("tree-vectorize")
#pragma GCC target("sse4")
using namespace std;
using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
template <typename T>
using vc = vector<T>;
template <typename T>
using vvc = vector<vector<T>>;
template <typename T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
constexpr lint ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
class ABadTriangle {
public:
void solve(std::istream& in, std::ostream& out) {
ios_base::sync_with_stdio(false);
in.tie(nullptr), out.tie(nullptr);
int tt;
in >> tt;
while (tt--) {
int N;
in >> N;
vc<int> A(N);
for (int i = (0); i < (N); ++i) in >> A[i];
if (A[0] + A[1] > A[N - 1])
out << "-1\n";
else
out << 1 << ' ' << 2 << ' ' << N << '\n';
}
}
};
int main() {
ABadTriangle solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long int i = 0;
int flag = 0;
while (i < n - 2) {
long long int x, y, z;
x = a[i];
y = a[i + 1];
z = a[n - 1];
if (z >= x + y) {
cout << i + 1 << " " << i + 2 << " " << n << endl;
flag = 1;
break;
}
i++;
}
if (flag == 0) {
cout << "-1" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> a(n);
for (auto &x : a) cin >> x;
long long int p = -1, q = -1, r = -1;
long long int big = a[n - 1];
bool ok = false;
for (int i = n - 2; i >= 0; i--) {
if (a[i] + a[i - 1] <= big && i - 1 >= 0) {
p = i;
q = i + 1;
r = n;
ok = true;
}
}
if (ok == true)
cout << p << " " << q << " " << r << endl;
else
cout << -1 << endl;
}
int main() {
long long int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
void test() {
long long n;
cin >> n;
vector<long long> v;
for (long long i = 0; i < n; i++) {
long long num;
cin >> num;
v.push_back(num);
}
if (v[0] + v[1] <= v[n - 1]) {
cout << 1 << " " << 2 << " " << n << endl;
} else {
cout << -1 << endl;
}
}
int main() {
long long t;
cin >> t;
while (t--) {
test();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t cases, total, elements, i;
cin >> cases;
for (i = 0; i < cases; i++) {
int flag = 0, val = 0;
vector<int> x = {};
cin >> total;
for (int j = 0; j < total; j++) {
cin >> elements;
x.push_back(elements);
}
for (int l = 1; l <= x.size() - 2; l++) {
if (x[0] + x[l] <= x[x.size() - 1]) {
flag = 1;
val = l;
break;
}
}
if (flag == 0) {
cout << -1 << endl;
} else {
cout << 1 << " " << val + 1 << " " << x.size() << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
void showlist(list<long long int> g) {
list<long long int>::iterator it;
for (it = g.begin(); it != g.end(); ++it) cout << *it << " ";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int n{}, m{}, k{};
cin >> n;
vector<long long int> v(n);
for (long long int i = 0; i < (n); i++) cin >> v.at(i);
long long int r{};
for (long long int i = 0; i < (n - 1); i++) {
if ((v[i] + v[i + 1]) <= v[v.size() - 1]) {
cout << i + 1 << " " << i + 2 << " " << n << ("\n");
r = 1;
break;
}
}
if (r == 0) cout << -1 << ("\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, i, j, k, x, flag;
long long* a;
cin >> t;
while (t--) {
cin >> n;
a = new long long[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] + a[1] <= a[n - 1]) {
cout << "1 2 " << n << "\n";
} else {
cout << "-1"
<< "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t) {
int n;
cin >> n;
vector<int> vec;
int flag = 1;
for (int j = 0; j < n; j++) {
int x;
cin >> x;
vec.push_back(x);
}
for (int i = 2; i < n; i++) {
if (vec[0] + vec[1] <= vec[i]) {
flag = 0;
cout << 1 << " " << 2 << " " << i + 1 << "\n";
break;
}
}
if (flag) cout << -1 << "\n";
t--;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<pair<int, int> > A(n);
for (int i = 0; i < n; i++) {
cin >> A[i].first;
A[i].second = i + 1;
}
sort(A.begin(), A.end());
if (A[0].first + A[1].first <= A[n - 1].first) {
cout << A[0].second << ' ' << A[1].second << ' ' << A[n - 1].second
<< '\n';
} else {
cout << "-1\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i;
cin >> t;
while (t--) {
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] + a[1] > a[n - 1]) {
cout << -1 << endl;
} else {
cout << 1 << " " << 2 << " " << n << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using dl = double;
const int N = 2e5 + 10;
ll aarray[200000 + 10];
ll magic[101][101];
vector<ll> primes;
bool prime[1000001];
int main() {
ios_base::sync_with_stdio(false);
string str;
ll i, j, n, m, k, t;
cin >> t;
while (t--) {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> aarray[i];
}
if (aarray[1] + aarray[2] <= aarray[n]) {
cout << 1 << " " << 2 << " " << n << endl;
} else
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
if (n >= 3 && arr[0] + arr[1] <= arr[n - 1])
cout << "1 2 " << n << endl;
else
cout << "-1" << endl;
}
int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
;
int t;
cin >> t;
while (t--) {
int a[5 * 10000 + 5] = {};
int n;
cin >> n;
for (int i = (0); i < (n); i += (1)) cin >> a[i];
if (a[0] + a[1] > a[n - 1])
cout << "-1" << '\n';
else
cout << "1 2 " << n << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int T, n, vet[51234];
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &vet[i]);
}
if ((vet[0] + vet[1]) > vet[n - 1]) {
puts("-1");
} else {
printf("%d %d %d\n", 1, 2, n);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long xyp(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y % 2 == 1) res = (res * x) % 1000000007;
x = (x * x) % 1000000007;
y /= 2;
}
return res % 1000000007;
}
long long inv(long long x) { return xyp(x, 1000000007 - 2); }
long long inv_euclid(long long a, long long m = 1000000007) {
long long m0 = m;
long long y = 0, x = 1;
if (m == 1) return 0;
while (a > 1) {
long long q = a / m;
long long t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0) x += m0;
return x;
}
bool isp(long long a) {
if (a == 2) return true;
if (a == 1) return false;
for (long long x = 2; x <= sqrt(a) + 1; x++)
if (a % x == 0) return false;
return true;
}
long long add(long long a, long long b) {
return (a % 1000000007 + b % 1000000007 +
((8000000000000000064LL) / 1000000007) * 1000000007) %
1000000007;
}
long long sub(long long a, long long b) {
return (a % 1000000007 - b % 1000000007 +
((8000000000000000064LL) / 1000000007) * 1000000007) %
1000000007;
}
long long mul(long long a, long long b) {
return ((a % 1000000007) * (b % 1000000007) +
((8000000000000000064LL) / 1000000007) * 1000000007) %
1000000007;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long _o_;
cin >> _o_;
while (_o_--) {
long long n;
cin >> n;
long long a[n];
for (auto &z : a) cin >> z;
if (a[0] + a[1] <= a[n - 1]) {
cout << 1 << ' ' << 2 << ' ' << n << '\n';
} else
cout << -1 << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t, n, i;
cin >> t;
while (t--) {
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] + a[1] > a[n - 1]) {
cout << -1 << endl;
} else {
cout << 1 << " " << 2 << " " << n << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long int n, i, j, k, f = 0;
scanf("%lld", &n);
long long int a[n];
for (i = 0; i < n; i++) scanf("%lld", &a[i]);
for (i = 2; i < n; i++) {
if (a[i] >= a[0] + a[1]) {
f = 1;
break;
}
}
if (f == 1)
printf("1 2 %lld\n", i + 1);
else
printf("-1\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
const long long L_INF = 1LL << 60;
const long long INF = 2147483647;
const double PI = acos(-1);
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
void debug(T v) {
for (long long i = 0; i < v.size(); ++i) cout << v[i] << " ";
cout << endl;
}
long long pcount(long long x) { return __builtin_popcountll(x); }
const long long dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; ++i) cin >> a[i];
if (a[0] + a[1] <= a[n - 1])
cout << "1 2 " << n << endl;
else
cout << -1 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, i, j;
cin >> n;
vector<long long int> v;
long long int h;
for (i = 0; i < n; i++) {
cin >> h;
v.push_back(h);
}
long long int a, b, c;
a = v[0];
b = v[1];
long long int u = 2;
for (i = 2; i < n; i++) {
if ((a + b) <= v[i]) {
c = i;
break;
} else
u++;
}
if (u == n)
cout << "-1\n";
else
cout << 1 << " " << 2 << " " << c + 1 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, t, a[50006];
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if ((a[2] + a[1]) <= a[n]) {
cout << "1 2 " << n << endl;
;
} else
cout << "-1" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<long long int> v(n);
for (long long int i = 0; i < n; ++i) cin >> v[i];
if (v[0] + v[1] <= v.back()) {
cout << "1 2 " << v.size();
return;
}
cout << -1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1, tmp = 0;
cin >> t;
while (t--) {
solve();
if (t) cout << "\n";
}
cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, i, j;
cin >> t;
for (i = 1; i <= t; i++) {
long long int n;
cin >> n;
long long int a[n + 1];
for (j = 1; j <= n; j++) {
cin >> a[j];
}
if ((a[1] + a[2]) <= a[n]) {
cout << 1 << " " << 2 << " " << n << endl;
} else {
cout << "-1" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (a[0] + a[1] > a[n - 1])
cout << -1 << endl;
else
cout << 1 << " " << 2 << " " << n << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
if (v[n - 1] >= v[0] + v[1])
cout << 1 << " " << 2 << " " << n << endl;
else
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int a[maxn];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
if (a[1] + a[2] <= a[n]) {
cout << 1 << " " << 2 << " " << n << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 2e9 + 5;
double PI = 3.14159265358979323846;
void solve() {
long long int n;
cin >> n;
long long int aa[n];
for (int i = 0; i < n; i++) {
cin >> aa[i];
}
long long int a = aa[0], b = aa[1], c = aa[n - 1];
if (a + b <= c) {
cout << 1 << " " << 2 << " " << n << "\n";
} else {
cout << -1 << "\n";
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
long long binpow(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
long long binpowmod(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long mod_inverse(long long n, long long p) {
return binpowmod(n, p - 2, p);
}
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
bool comp_pairs_by_s(pair<long long, long long> &x,
pair<long long, long long> &y) {
return x.second < y.second;
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
class cmp {
public:
bool operator()(pair<int, int> A, pair<int, int> B) {
if (abs(A.first - A.second) == abs(B.first - B.second))
return A.first > B.first;
return abs(A.first - A.second) < abs(B.first - B.second);
}
};
void swap(long long &x, long long &y) {
int temp = x;
x = y;
y = temp;
}
unsigned int onesComplement(unsigned int n) {
int number_of_bits = floor(log2(n)) + 1;
return ((1 << number_of_bits) - 1) ^ n;
}
bool comp(pair<long long, long long> x, pair<long long, long long> y) {
return x.second < y.second;
}
bool comp1(pair<long long, long long> x, pair<long long, long long> y) {
return x.second < y.second;
}
void selfmin(int &x, int y) { x = min(x, y); }
void solve() {
int n;
cin >> n;
vector<long long> a(n);
for (auto &it : a) cin >> it;
if (a[0] + a[1] > a[n - 1])
cout << -1;
else {
cout << 1 << ' ' << 2 << ' ' << n;
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (arr[n - 1] >= arr[0] + arr[1]) {
cout << "1 2 " << n << "\n";
} else {
cout << "-1\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long Bin_expo(long long n, long long b, long long m) {
long long res = 1;
while (b > 0) {
if (b & 1) {
res = (res * n) % m;
}
n = (n * n) % m;
b /= 2;
}
return res % m;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long tc;
cin >> tc;
while (tc--) {
long long n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
long long f = 0;
for (long long i = 2; i < n; i++) {
if (v[i] >= v[0] + v[1]) {
cout << "1 2 " << i + 1 << "\n";
f = 1;
break;
}
}
if (f) continue;
cout << "-1\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, arr[50005];
cin >> t;
for (int i = 0; i < t; i++) {
int x = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (arr[0] + arr[1] <= arr[n - 1]) {
cout << "1"
<< " "
<< "2"
<< " " << n << "\n";
} else
cout << "-1"
<< "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t;
cin >> t;
while (t--) {
ll n;
cin >> n;
vector<ll> sides(n);
for (int i = 0; i < (n); ++i) cin >> sides[i];
if (sides[1] > (sides[n - 1] - sides[0]))
cout << -1 << "\n";
else
cout << "1 2 " << n << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, b, c;
cin >> a;
cin >> b;
for (int i = 0; i < n - 2; i++) {
cin >> c;
}
if (a + b <= c) {
cout << "1 2 " << n << endl;
} else {
cout << -1 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long a, b = 0, c = 0, d = 0, e = 0;
cin >> a;
int arr[a];
for (int i = 0; i < a; i++) {
cin >> arr[i];
}
b = arr[0];
for (int i = 0; i < a; i++) {
if (i != 0) {
if (arr[i] >= b) {
c = arr[i];
d = i;
break;
}
}
}
for (int i = 0; i < a; i++) {
if (i != d) {
if (arr[i] >= (b + c)) {
e = i;
break;
}
}
}
if (e != 0) {
cout << 1 << " " << d + 1 << " " << e + 1 << endl;
} else {
cout << -1 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long int inf64 = LLONG_MAX;
vector<string> vect;
long long int n;
vector<pair<int, int> > d4{{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
bool good(long long int xx, long long int yy) {
return (xx < n and xx >= 0 and yy < n and yy >= 0);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int t;
cin >> t;
while (t--) {
cin >> n;
vect = vector<string>(n);
long long int i;
for (i = 0; i < n; i++) {
cin >> vect[i];
}
vector<pair<int, int> > ans1, ans2;
for (auto p : d4) {
long long int xx, yy;
xx = 0 + p.first;
yy = 0 + p.second;
if (good(xx, yy) and vect[xx][yy] == '1') ans1.push_back({xx, yy});
xx = n - 1 + p.first;
yy = n - 1 + p.second;
if (good(xx, yy) and vect[xx][yy] == '0') ans1.push_back({xx, yy});
}
for (auto p : d4) {
long long int xx, yy;
xx = 0 + p.first;
yy = 0 + p.second;
if (good(xx, yy) and vect[xx][yy] == '0') ans2.push_back({xx, yy});
xx = n - 1 + p.first;
yy = n - 1 + p.second;
if (good(xx, yy) and vect[xx][yy] == '1') ans2.push_back({xx, yy});
}
if (ans1.size() < ans2.size()) {
cout << ans1.size() << '\n';
for (auto x : ans1) cout << x.first + 1 << ' ' << x.second + 1 << '\n';
} else {
cout << ans2.size() << '\n';
for (auto x : ans2) cout << x.first + 1 << ' ' << x.second + 1 << '\n';
}
}
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;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
if (a[1][0] == a[0][1] && a[n - 1][n - 2] == a[n - 2][n - 1] &&
a[1][0] != a[n - 1][n - 2]) {
cout << 0 << "\n";
} else if (a[1][0] != a[0][1] && a[n - 1][n - 2] != a[n - 2][n - 1]) {
cout << 2 << "\n";
if (a[1][0] == '1') {
a[0][1] = '1';
cout << 1 << " " << 2 << "\n";
if (a[n - 1][n - 2] == '1') {
a[n - 1][n - 2] = '0';
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '1') {
a[n - 2][n - 1] = '0';
cout << n - 1 << " " << n << "\n";
}
} else if (a[1][0] == '0') {
a[0][1] = '0';
cout << 1 << " " << 2 << "\n";
if (a[n - 1][n - 2] == '0') {
a[n - 1][n - 2] = '1';
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '0') {
a[n - 2][n - 1] = '1';
cout << n - 1 << " " << n << "\n";
}
}
} else if (a[1][0] == a[0][1] && a[n - 1][n - 2] != a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[1][0] == '0') {
if (a[n - 1][n - 2] == '0') {
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '0') {
cout << n - 1 << " " << n << "\n";
}
}
if (a[1][0] == '1') {
if (a[n - 1][n - 2] == '1') {
cout << n << " " << n - 1 << "\n";
} else if (a[n - 2][n - 1] == '1') {
cout << n - 1 << " " << n << "\n";
}
}
} else if (a[1][0] != a[0][1] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[n - 1][n - 2] == '0') {
if (a[1][0] == '0') {
cout << 2 << " " << 1 << "\n";
} else {
cout << 1 << " " << 2 << "\n";
}
} else {
if (a[1][0] == '1') {
cout << 2 << " " << 1 << "\n";
} else {
cout << 1 << " " << 2 << "\n";
}
}
} else if (a[1][0] == a[0][1] && a[n - 1][n - 2] == a[n - 2][n - 1] &&
a[1][0] == a[n - 1][n - 2]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int Tc, N;
char Grid[205][205];
int main() {
cin >> Tc;
while (Tc--) {
cin >> N;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) cin >> Grid[i][j];
}
if (Grid[1][2] == Grid[2][1]) {
if (Grid[N - 1][N] == Grid[N][N - 1] && Grid[1][2] == Grid[N][N - 1]) {
cout << 2 << endl;
cout << N << " " << N - 1 << endl;
cout << N - 1 << " " << N << endl;
} else if (Grid[N - 1][N] == Grid[N][N - 1])
cout << 0 << endl;
else if (Grid[N - 1][N] == Grid[1][2])
cout << 1 << endl << N - 1 << " " << N << endl;
else
cout << 1 << endl << N << " " << N - 1 << endl;
} else {
if (Grid[N - 1][N] == Grid[N][N - 1]) {
cout << 1 << endl;
if (Grid[1][2] == Grid[N - 1][N])
cout << 1 << " " << 2 << endl;
else
cout << 2 << " " << 1 << endl;
} else {
cout << 2 << endl;
if (Grid[1][2] == '1')
cout << 1 << " " << 2 << endl;
else
cout << 2 << " " << 1 << endl;
if (Grid[N][N - 1] == '0')
cout << N << " " << N - 1 << endl;
else
cout << N - 1 << " " << N << endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
set<int> ist;
map<string, int> msi;
map<string, string> mss;
map<int, string> mis;
map<int, int> mii;
pair<int, int> pii;
vector<int> v;
vector<pair<int, int> > vv;
int cc[] = {1, -1, 0, 0};
int rr[] = {0, 0, 1, -1};
void SUNRISE() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
char dp[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> dp[i][j];
}
}
if ((dp[0][1] == dp[1][0]) && (dp[n - 1][n - 2] == dp[n - 2][n - 1]) &&
(dp[0][1] != dp[n - 1][n - 2])) {
cout << 0 << endl;
} else if ((dp[0][1] == dp[1][0]) &&
(dp[n - 1][n - 2] == dp[n - 2][n - 1]) &&
(dp[0][1] == dp[n - 1][n - 2])) {
cout << 2 << endl;
cout << 1 << " " << 2 << endl;
cout << 2 << " " << 1 << endl;
} else if ((dp[0][1] != dp[1][0]) &&
(dp[n - 1][n - 2] != dp[n - 2][n - 1])) {
cout << 2 << endl;
if (dp[0][1] == '0') {
cout << 1 << " " << 2 << endl;
} else {
cout << 2 << " " << 1 << endl;
}
if (dp[n - 1][n - 2] == '1') {
cout << n << " " << n - 1 << endl;
} else {
cout << n - 1 << " " << n << endl;
}
} else {
if (dp[0][1] == dp[1][0]) {
if (dp[n - 1][n - 2] == dp[0][1]) {
cout << 1 << endl;
cout << n << " " << n - 1 << endl;
} else {
cout << 1 << endl;
cout << n - 1 << " " << n << endl;
}
} else {
if (dp[n - 1][n - 2] == dp[0][1]) {
cout << 1 << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << 1 << endl;
cout << 2 << " " << 1 << endl;
}
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
SUNRISE();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long i, j, m, n, k;
long long t;
cin >> t;
while (t--) {
cin >> n;
char a[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> a[i][j];
}
}
if (a[0][1] == a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] != a[n - 1][n - 2]) {
cout << 0 << "\n";
} else {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
}
} else if (a[0][1] == a[1][0] && a[n - 1][n - 2] != a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[0][1] == a[n - 1][n - 2]) {
cout << n << " " << n - 1 << "\n";
} else
cout << n - 1 << " " << n << "\n";
} else if (a[0][1] != a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
cout << 1 << "\n";
if (a[0][1] == a[n - 1][n - 2]) {
cout << 1 << " " << 2 << "\n";
} else
cout << 2 << " " << 1 << "\n";
} else {
cout << 2 << "\n";
if (a[0][1] == a[n - 1][n - 2]) {
cout << 1 << " " << 2 << "\n";
cout << n - 1 << " " << n << "\n";
} else {
cout << 1 << " " << 2 << "\n";
cout << n << " " << n - 1 << "\n";
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 204;
int t, n;
string s[N];
void solve(char z1, char z2, char y1, char y2) {
if (z1 == '0' && z2 == '0') {
if (y1 == '1' && y2 == '1')
puts("0");
else if (y1 == '0' && y2 == '0') {
printf("2\n%d %d\n%d %d\n", n, n - 1, n - 1, n);
} else if (y1 == '1' && y2 == '0') {
printf("1\n%d %d\n", n - 1, n);
} else {
printf("1\n%d %d\n", n, n - 1);
}
}
if (z1 == '1' && z2 == '1') {
if (y1 == '0' && y2 == '0')
puts("0");
else if (y1 == '1' && y2 == '1') {
printf("2\n%d %d\n%d %d\n", n, n - 1, n - 1, n);
} else if (y1 == '0' && y2 == '1') {
printf("1\n%d %d\n", n - 1, n);
} else {
printf("1\n%d %d\n", n, n - 1);
}
}
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i <= n - 1; ++i) cin >> s[i];
char z1 = s[1][0], z2 = s[0][1], y1 = s[n - 1][n - 2], y2 = s[n - 2][n - 1];
if (z1 == z2)
solve(z1, z2, y1, y2);
else if (z1 == '1' && z2 == '0') {
if (y1 == '1' && y2 == '0')
printf("2\n1 2\n%d %d\n", n, n - 1);
else if (y1 == '1' && y2 == '1')
printf("1\n2 1\n");
else if (y1 == '0' && y2 == '1')
printf("2\n1 2\n%d %d\n", n - 1, n);
else
printf("1\n1 2\n");
} else {
if (y1 == '1' && y2 == '0')
printf("2\n1 2\n%d %d\n", n - 1, n);
else if (y1 == '1' && y2 == '1')
printf("1\n1 2\n");
else if (y1 == '0' && y2 == '1')
printf("2\n1 2\n%d %d\n", n, n - 1);
else
printf("1\n2 1\n");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long n, long long mod) {
long long res = 1;
x %= mod;
while (n) {
if (n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long c = 0, d = 0, i = 0, j = 0, k = 0, t = 0, n = 0, q = 0;
cin >> t;
while (t--) {
cin >> n;
pair<long long, long long> a, b;
string s[n];
for (long long i = 0; i < n; i++) {
cin >> s[i];
if (i == 1) a = make_pair(s[0][1] - '0', s[1][0] - '0');
if (i == n - 1)
b = make_pair(s[n - 1][n - 2] - '0', s[n - 2][n - 1] - '0');
}
long long ans = 0;
if (a.first + a.second == 2) {
if (b.first == 1) ans++;
if (b.second == 1) ans++;
cout << ans << "\n";
if (b.second) cout << n - 1 << " " << n << "\n";
if (b.first) cout << n << " " << n - 1 << "\n";
} else if (a.first + a.second == 0) {
if (b.first == 0) ans++;
if (b.second == 0) ans++;
cout << ans << "\n";
if (b.second == 0) cout << n - 1 << " " << n << "\n";
if (b.first == 0) cout << n << " " << n - 1 << "\n";
} else if (a.first + a.second == 1 && b.first + b.second == 1) {
cout << 2 << "\n";
if (a.first == 1) cout << 1 << " " << 2 << "\n";
if (a.second == 1) cout << 2 << " " << 1 << "\n";
if (b.first == 0) cout << n << " " << n - 1 << "\n";
if (b.second == 0) cout << n - 1 << " " << n << "\n";
} else if (a.first + a.second == 1 && b.first + b.second == 0) {
cout << 1 << "\n";
if (a.first == 0) cout << 1 << " " << 2 << "\n";
if (a.second == 0) cout << 2 << " " << 1 << "\n";
} else if (a.first + a.second == 1 && b.first + b.second == 2) {
cout << 1 << "\n";
if (a.first == 1) cout << 1 << " " << 2 << "\n";
if (a.second == 1) cout << 2 << " " << 1 << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int myXOR(long long int x, long long int y) { return (x | y) & (~x | ~y); }
int main() {
int tt = 1;
cin >> tt;
while (tt--) {
long long int n, i, j;
cin >> n;
char a[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) cin >> a[i][j];
}
long long int ans = 0;
if (a[0][1] == a[1][0] && a[n - 1][n - 2] == a[n - 2][n - 1]) {
if (a[0][1] == a[n - 1][n - 2]) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
} else
cout << 0 << "\n";
} else {
vector<pair<long long int, long long int> > v;
long long int f = 0;
char ch;
if (a[0][1] == a[1][0]) {
f = 1;
ch = a[0][1];
}
if (a[n - 1][n - 2] == a[n - 2][n - 1]) {
f = 2;
ch = a[n - 1][n - 2];
}
if (f == 0) {
if (a[0][1] != '1') {
ans++;
v.push_back({1, 2});
} else if (a[1][0] != '1') {
ans++;
v.push_back({2, 1});
}
if (a[n - 1][n - 2] != '0') {
ans++;
v.push_back({n, n - 1});
} else if (a[n - 2][n - 1] != '0') {
ans++;
v.push_back({n - 1, n});
}
cout << ans << "\n";
for (i = 0; i < ans; i++) {
cout << v[i].first << " " << v[i].second << "\n";
}
}
if (f == 1) {
if (a[n - 2][n - 1] == ch) {
ans++;
v.push_back({n - 1, n});
} else if (a[n - 1][n - 2] == ch) {
ans++;
v.push_back({n, n - 1});
}
cout << ans << "\n";
for (i = 0; i < ans; i++) {
cout << v[i].first << " " << v[i].second << "\n";
}
}
if (f == 2) {
if (a[0][1] == ch) {
ans++;
v.push_back({1, 2});
} else if (a[1][0] == ch) {
ans++;
v.push_back({2, 1});
}
cout << ans << "\n";
for (i = 0; i < ans; i++) {
cout << v[i].first << " " << v[i].second << "\n";
}
}
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
int n;
cin >> n;
getline(cin, s);
vector<vector<char>> v(n);
char c;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> c;
v[i].push_back(c);
}
getline(cin, s);
}
int ctr1 = 0, ctr2 = 0;
if (v[1][0] == v[0][1]) {
c = v[1][0];
if (v[n - 1][n - 2] == c) ctr1++;
if (v[n - 2][n - 1] == c) ctr2++;
cout << ctr1 + ctr2 << endl;
if (v[n - 1][n - 2] == c) cout << n << " " << n - 1 << endl;
if (v[n - 2][n - 1] == c) cout << n - 1 << " " << n << endl;
} else if (v[n - 1][n - 2] == v[n - 2][n - 1]) {
c = v[n - 1][n - 2];
if (v[1][0] == c) ctr1++;
if (v[0][1] == c) ctr2++;
cout << ctr1 + ctr2 << endl;
if (v[1][0] == c) cout << "2 1" << endl;
if (v[0][1] == c) cout << "1 2" << endl;
} else {
cout << "2\n";
if (v[1][0] == v[n - 1][n - 2])
cout << "2 1\n" << n - 1 << " " << n << endl;
else if (v[1][0] == v[n - 2][n - 1])
cout << "2 1\n" << n << " " << n - 1 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, mod = 1e9 + 7, len = 30;
void run_case() {
int n;
cin >> n;
char c[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> c[i][j];
vector<pair<int, int>> vec;
if (c[0][1] == c[1][0]) {
if (c[n - 1][n - 2] == c[0][1]) vec.push_back({n - 1, n - 2});
if (c[n - 2][n - 1] == c[0][1]) vec.push_back({n - 2, n - 1});
} else {
if (c[0][1] == c[n - 1][n - 2]) vec.push_back({0, 1});
if (c[1][0] == c[n - 1][n - 2]) vec.push_back({1, 0});
if (c[n - 1][n - 2] != c[n - 2][n - 1]) vec.push_back({n - 2, n - 1});
}
cout << vec.size() << endl;
for (auto i : vec) cout << i.first + 1 << " " << i.second + 1 << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) run_case();
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(1337);
ostream& operator<<(ostream& a, const pair<long long, long long> b) {
cout << "{" << b.first << ", " << b.second << "}";
return a;
}
ostream& operator<<(ostream& a, const vector<long long int>& b) {
for (auto& k : b) cout << k << " ";
return a;
}
ostream& operator<<(ostream& a, const vector<pair<long long, long long> >& b) {
for (auto& k : b) cout << k << " ";
return a;
}
const long long int INF = (long long int)1e9;
const long long int MOD = 1000 * 1000 * 1000 + 7, MOD2 = 274876858367;
const long long int maxn = (long long int)3e5 + 10, L = 22;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int T = 1;
cin >> T;
while (T--) {
long long int n;
cin >> n;
vector<string> a(n);
for (long long int i = 0; i < n; ++i) cin >> a[i];
vector<pair<long long, long long> > ans, res;
if (a[0][1] != '0') ans.push_back({0, 1});
if (a[1][0] != '0') ans.push_back({1, 0});
if (a[2][0] != '1') ans.push_back({2, 0});
if (a[1][1] != '1') ans.push_back({1, 1});
if (a[0][2] != '1') ans.push_back({0, 2});
if (a[0][1] != '1') res.push_back({0, 1});
if (a[1][0] != '1') res.push_back({1, 0});
if (a[2][0] != '0') res.push_back({2, 0});
if (a[1][1] != '0') res.push_back({1, 1});
if (a[0][2] != '0') res.push_back({0, 2});
if (ans.size() > res.size()) swap(ans, res);
cout << ans.size() << '\n';
for (pair<long long, long long>& x : ans)
cout << x.first + 1 << " " << x.second + 1 << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast", "no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int exp(long long int x, long long int y, long long int mod) {
long long int res = 1;
x = x % mod;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
long long int modinverse(long long int x, long long int mod) {
return exp(x, mod - 2, mod);
}
using namespace std;
const long long int inf = 0x3f3f3f3f3f3f3f3fll;
void solve() {
long long int n;
cin >> n;
string s[n];
for (long long int i = 0; i < n; i++) cin >> s[i];
if (s[0][1] == '0' && s[1][0] == '0') {
if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '0') {
cout << 2 << '\n';
cout << n << " " << n - 1 << '\n';
cout << n - 1 << " " << n << '\n';
} else if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '1') {
cout << 1 << '\n';
cout << n << " " << n - 1 << '\n';
} else if (s[n - 1][n - 2] == '1' && s[n - 2][n - 1] == '0') {
cout << 1 << '\n';
cout << n - 1 << " " << n << '\n';
} else
cout << 0 << '\n';
} else if (s[0][1] == '1' && s[1][0] == '0') {
if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '0') {
cout << 1 << '\n';
cout << 2 << " " << 1 << '\n';
} else if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '1') {
cout << 2 << '\n';
cout << 2 << " " << 1 << '\n';
cout << n - 1 << " " << n << '\n';
} else if (s[n - 1][n - 2] == '1' && s[n - 2][n - 1] == '0') {
cout << 2 << '\n';
cout << 2 << " " << 1 << '\n';
cout << n << " " << n - 1 << '\n';
} else {
cout << 1 << '\n';
cout << 1 << " " << 2 << '\n';
}
} else if (s[0][1] == '0' && s[1][0] == '1') {
if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '0') {
cout << 1 << '\n';
cout << 1 << " " << 2 << '\n';
} else if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '1') {
cout << 2 << '\n';
cout << 2 << " " << 1 << '\n';
cout << n << " " << n - 1 << '\n';
} else if (s[n - 1][n - 2] == '1' && s[n - 2][n - 1] == '0') {
cout << 2 << '\n';
cout << 2 << " " << 1 << '\n';
cout << n - 1 << " " << n << '\n';
} else {
cout << 1 << '\n';
cout << 2 << " " << 1 << '\n';
}
} else {
if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '0')
cout << 0 << '\n';
else if (s[n - 1][n - 2] == '0' && s[n - 2][n - 1] == '1') {
cout << 1 << '\n';
cout << n - 1 << " " << n << '\n';
} else if (s[n - 1][n - 2] == '1' && s[n - 2][n - 1] == '0') {
cout << 1 << '\n';
cout << n << " " << n - 1 << '\n';
} else {
cout << 2 << '\n';
cout << n << " " << n - 1 << '\n';
cout << n - 1 << " " << n << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
cin >> t;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void testCase() {
long long n;
cin >> n;
vector<string> grid(n);
vector<pair<long long, long long>> ans;
for (string &s : grid) cin >> s;
char t1 = grid[0][1];
char t2 = grid[1][0];
char b1 = grid[n - 1][n - 2];
char b2 = grid[n - 2][n - 1];
if (t1 == t2) {
if (b1 == t2) ans.push_back({n - 1, n - 2});
if (b2 == t2) ans.push_back({n - 2, n - 1});
} else if (b1 == b2) {
if (b1 == t1) ans.push_back({0, 1});
if (b1 == t2) ans.push_back({1, 0});
} else {
if (t1 == '1') ans.push_back({0, 1});
if (t2 == '1') ans.push_back({1, 0});
if (b1 == '0') ans.push_back({n - 1, n - 2});
if (b2 == '0') ans.push_back({n - 2, n - 1});
}
cout << (long long)(ans.size()) << endl;
for (auto &it : ans) cout << it.first + 1 << " " << it.second + 1 << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
long long t_c = 1;
cin >> t_c;
while (t_c--) testCase();
}
|
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
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;
}
const int N = 1e9 + 1;
const int x = 201;
int a[200][200];
void solve() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
int a = s[0][1], b = s[1][0];
int c = s[n - 1][n - 2], d = s[n - 2][n - 1];
vector<pair<int, int>> v;
if (a == b) {
if (a == c) v.push_back({n, n - 1});
if (a == d) v.push_back({n - 1, n});
} else if (c == d) {
if (c == a) v.push_back({1, 2});
if (c == b) v.push_back({2, 1});
} else {
v.push_back({2, 1});
if (a == c) v.push_back({n, n - 1});
if (a == d) v.push_back({n - 1, n});
}
cout << ((int)(v).size()) << '\n';
for (auto x : v) cout << x.first << " " << x.second << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
const long double eps = 1e-8;
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n + 1][n + 1];
string temp;
for (long long int i = 1; i < n + 1; i++) {
cin >> temp;
for (long long int j = 0; j < n; j++) {
a[i][j + 1] = temp[j] - '0';
}
}
long long int x = a[1][2];
long long int y = a[2][1];
long long int p = a[n][n - 1];
long long int q = a[n - 1][n];
if (x == y) {
if (p == q) {
if (p != x)
cout << 0 << "\n";
else {
cout << 2 << "\n";
cout << "1 2"
<< "\n";
cout << "2 1"
<< "\n";
}
} else {
if (p == x) {
cout << 1 << "\n";
cout << n << " " << n - 1 << "\n";
} else {
cout << 1 << "\n";
cout << n - 1 << " " << n << "\n";
}
}
} else {
if (p == q) {
cout << 1 << "\n";
if (x == p) {
cout << "1 2"
<< "\n";
} else
cout << "2 1"
<< "\n";
} else {
cout << 2 << "\n";
if (x == p) {
cout << "1 2"
<< "\n";
cout << n - 1 << " " << n << "\n";
} else {
cout << "1 2"
<< "\n";
cout << n << " " << n - 1 << "\n";
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int n = 0, f = 1, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
n = n * 10 + ch - '0';
ch = getchar();
}
return n * f;
}
char s[305][305];
int main() {
int t, x, sth, n;
t = read();
for (int greg = 1; greg <= t; greg++) {
n = read();
for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
if (s[1][2] == s[2][1]) {
sth = 0;
if (s[n][n - 1] == s[1][2]) sth++;
if (s[n - 1][n] == s[1][2]) sth++;
printf("%d\n", sth);
if (s[n][n - 1] == s[1][2]) printf("%d %d\n", n, n - 1);
if (s[n - 1][n] == s[1][2]) printf("%d %d\n", n - 1, n);
} else {
sth = 1;
if (s[n][n - 1] != s[n - 1][n]) sth++;
printf("%d\n", sth);
if (s[1][2] == s[n - 1][n])
printf("1 2\n");
else
printf("2 1\n");
if (sth == 2) printf("%d %d\n", n, n - 1);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a[205][205];
char c;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> c;
a[i][j] = c - '0';
}
if (a[1][2] == a[2][1]) {
if (a[n - 1][n] == a[n][n - 1]) {
if (a[1][2] == a[n - 1][n]) {
cout << "2\n1 2\n2 1\n";
} else {
cout << "0\n";
}
} else {
if (a[1][2] == a[n - 1][n]) {
cout << "1\n" << n - 1 << " " << n << endl;
} else {
cout << "1\n" << n << " " << n - 1 << endl;
}
}
} else {
if (a[n - 1][n] == a[n][n - 1]) {
if (a[1][2] == a[n - 1][n]) {
cout << "1\n1 2\n";
} else {
cout << "1\n2 1\n";
}
} else {
if (a[1][2] == a[n - 1][n]) {
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;
void edit(vector<int> &skill, int n) {
for (int i = 0; i < n; i++) {
int x;
cin >> x;
skill.push_back(x);
}
}
void achilles() {
int n;
cin >> n;
char arr[n][n];
cin.ignore();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
cin.ignore();
}
int a = arr[0][1] - '0';
int b = arr[1][0] - '0';
int c = arr[n - 2][n - 1] - '0';
int d = arr[n - 1][n - 2] - '0';
if ((a == b)) {
if (c == d) {
if (a == c) {
cout << 2 << "\n";
cout << n - 1 << " " << n << "\n" << n << " " << n - 1 << "\n";
return;
} else {
cout << 0 << "\n";
return;
}
} else {
cout << 1 << "\n";
if (c == a) {
cout << n - 1 << " " << n << "\n";
return;
} else if (d == a) {
cout << n << " " << n - 1 << "\n";
return;
}
}
} else if (c == d) {
{
cout << 1 << "\n";
if (a == c) {
cout << 1 << " " << 2 << "\n";
return;
} else if (b == c) {
cout << 2 << " " << 1 << "\n";
return;
}
}
} else {
cout << 2 << "\n";
if (a == c) {
cout << 2 << " " << 1 << "\n";
cout << n - 1 << " " << n << "\n";
return;
} else {
cout << 2 << " " << 1 << "\n";
cout << n << " " << n - 1 << "\n";
return;
}
}
}
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) achilles();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
if (s[0][1] == s[1][0] and s[n - 2][n - 1] == s[n - 1][n - 2] and
s[0][1] != s[n - 2][n - 1]) {
puts("0");
return 0;
}
if (s[0][1] == s[1][0]) {
if (s[n - 1][n - 2] == s[0][1] and s[n - 2][n - 1] == s[0][1]) {
puts("2");
puts("1 2");
puts("2 1");
} else {
puts("1");
if (s[n - 2][n - 1] == s[0][1])
cout << n - 1 << " " << n << "\n";
else
cout << n << " " << n - 1 << "\n";
}
return 0;
}
if (s[n - 1][n - 2] == s[n - 2][n - 1]) {
puts("1");
if (s[n - 2][n - 1] == s[0][1])
puts("1 2");
else
puts("2 1");
return 0;
}
puts("2");
if (s[0][1] == '1')
puts("1 2");
else
puts("2 1");
if (s[n - 2][n - 1] == '0')
cout << n - 1 << " " << n << "\n";
else
cout << n << " " << n - 1 << "\n";
return 0;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long Min(long long a, long long b) { return (a < b) ? a : b; }
long long Max(long long a, long long b) { return (a < b) ? b : a; }
long long gcd(long long m, long long n) {
if (n == 0) return m;
return gcd(n, m % n);
}
long long lcm(long long m, long long n) { return m * n / gcd(m, n); }
long long dx[6] = {-1, 0, 1, 0, 0, 0}, dy[6] = {0, 1, 0, -1, 0, 0},
dz[6] = {0, 0, 0, 0, 1, -1};
void solve() {
long long n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
char c[5] = {v[0][1], v[1][0], v[n - 1][n - 2], v[n - 2][n - 1]};
char ch[2][5] = {"0011", "1100"};
for (int i = 0; i < 2; i++) {
long long cnt = 0;
for (int j = 0; j < 4; j++) {
if (c[j] != ch[i][j]) cnt++;
}
if (cnt <= 2) {
vector<pair<long long, long long> > a;
for (int j = 0; j < 4; j++) {
if (c[j] != ch[i][j]) {
if (j == 0)
a.push_back({1, 2});
else if (j == 1)
a.push_back({2, 1});
else if (j == 2)
a.push_back({n, n - 1});
else
a.push_back({n - 1, n});
}
}
cout << a.size() << "\n";
for (auto t : a) cout << t.first << " " << t.second << "\n";
return;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long tc = 1;
cin >> tc;
while (tc--) solve();
exit(0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, sr, sl, eu, ele;
cin >> t;
while (t--) {
int n;
scanf("%d", &n);
getchar();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
char c = getchar();
if (i == 1 && j == 2) sr = c - '0';
if (i == 2 && j == 1) sl = c - '0';
if (i == n - 1 && j == n) eu = c - '0';
if (i == n && j == n - 1) ele = c - '0';
}
getchar();
}
int tot = sr + sl + eu + ele;
int a = 0, f[2], l[2];
if (tot == 0 || tot == 4) {
a = 2;
f[0] = 1, f[1] = 2;
l[0] = 2, l[1] = 1;
} else if (tot == 2) {
if (sr != sl) {
if (sr == eu) {
a = 2;
f[0] = 2, l[0] = 1;
f[1] = n - 1, l[1] = n;
} else {
a = 2;
f[0] = 1, l[0] = 2;
f[1] = n - 1, l[1] = n;
}
}
} else {
if (sr == sl) {
if (eu == sl) {
a = 1;
f[0] = n - 1;
l[0] = n;
} else {
a = 1;
f[0] = n;
l[0] = n - 1;
}
} else {
if (eu == sl) {
a = 1;
f[0] = 2;
l[0] = 1;
} else {
a = 1;
f[0] = 1;
l[0] = 2;
}
}
}
printf("%d\n", a);
for (int i = 0; i < a; i++) {
printf("%d %d\n", f[i], l[i]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
string s;
vector<string> v;
cin >> n;
for (int i = (0); i < int(n); i++) {
cin >> s;
v.push_back(s);
}
vector<pair<int, int> > ans;
if (v[0][1] == v[1][0]) {
if (v[n - 1][n - 2] == v[0][1]) ans.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] == v[0][1]) ans.push_back({n - 2, n - 1});
} else if (v[n - 1][n - 2] == v[n - 2][n - 1]) {
if (v[0][1] == v[n - 1][n - 2]) ans.push_back({0, 1});
if (v[1][0] == v[n - 1][n - 2]) ans.push_back({1, 0});
} else {
ans.push_back({0, 1});
v[0][1] = v[1][0];
if (v[n - 1][n - 2] == v[0][1]) ans.push_back({n - 1, n - 2});
if (v[n - 2][n - 1] == v[0][1]) ans.push_back({n - 2, n - 1});
}
cout << ans.size() << endl;
for (auto t : ans) cout << t.first + 1 << ' ' << t.second + 1 << endl;
}
int main() {
int t;
cin >> t;
for (int i = (0); i < int(t); i++) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char mp[300][300];
int n;
void solve() {
int cnt = 0;
if ((mp[1][2] - '0') && (mp[2][1] - '0')) {
cnt = 0;
if (mp[n][n - 1] - '0') {
cnt++;
}
if (mp[n - 1][n] - '0') {
cnt++;
}
printf("%d\n", cnt);
if (mp[n][n - 1] - '0') {
printf("%d %d\n", n, n - 1);
}
if (mp[n - 1][n] - '0') {
printf("%d %d\n", n - 1, n);
}
} else if (!(mp[1][2] - '0') && !(mp[2][1] - '0')) {
cnt = 0;
if (!(mp[n][n - 1] - '0')) {
cnt++;
}
if (!(mp[n - 1][n] - '0')) {
cnt++;
}
printf("%d\n", cnt);
if (!(mp[n][n - 1] - '0')) {
printf("%d %d\n", n, n - 1);
}
if (!(mp[n - 1][n] - '0')) {
printf("%d %d\n", n - 1, n);
}
} else if ((mp[1][2] - '0') || (mp[2][1] - '0')) {
if ((mp[n][n - 1] - '0') && (mp[n - 1][n] - '0')) {
printf("1\n");
if (mp[1][2] - '0') {
printf("1 2\n");
} else {
printf("2 1\n");
}
} else if (!(mp[n][n - 1] - '0') && !(mp[n - 1][n] - '0')) {
printf("1\n");
if (mp[1][2] - '0') {
printf("2 1\n");
} else {
printf("1 2\n");
}
} else {
printf("2\n");
if (mp[1][2] - '0') {
printf("2 1\n");
} else {
printf("1 2\n");
}
if (mp[n][n - 1] - '0') {
printf("%d %d\n", n, n - 1);
} else {
printf("%d %d\n", n - 1, n);
}
}
}
}
int main() {
int Case = 1;
scanf("%d", &Case);
getchar();
while (Case--) {
scanf("%d", &n);
char c = getchar();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
c = getchar();
mp[i][j] = c;
}
getchar();
}
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[205][205];
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
vector<pair<int, int>> ans[2];
ans[s[1][2] == '1'].push_back(make_pair(1, 2));
ans[s[2][1] == '1'].push_back(make_pair(2, 1));
ans[s[n - 1][n] == '0'].push_back(make_pair(n - 1, n));
ans[s[n][n - 1] == '0'].push_back(make_pair(n, n - 1));
if (ans[0].size() > 2) swap(ans[0], ans[1]);
printf("%d\n", (int)ans[0].size());
for (auto x : ans[0]) printf("%d %d\n", x.first, x.second);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long T, n, i, j;
long long S_0, S_1, F_0, F_1, count;
cin >> T;
while (T--) {
cin >> n;
string A[n];
for (i = 0; i < n; i++) {
cin >> A[i];
}
S_0 = 0;
S_1 = 0;
F_0 = 0;
F_1 = 0;
if (A[0][1] == '0')
S_0 += 1;
else
S_1 += 1;
if (A[1][0] == '0')
S_0 += 1;
else
S_1 += 1;
if (A[n - 2][n - 1] == '0')
F_0 += 1;
else
F_1 += 1;
if (A[n - 1][n - 2] == '0')
F_0 += 1;
else
F_1 += 1;
count = 0;
vector<long long> X;
vector<long long> Y;
if (S_0 == 2) {
if (A[n - 1][n - 2] == '0') {
X.push_back(n - 1);
Y.push_back(n - 2);
count += 1;
}
if (A[n - 2][n - 1] == '0') {
X.push_back(n - 2);
Y.push_back(n - 1);
count += 1;
}
} else if (S_1 == 2) {
if (A[n - 1][n - 2] == '1') {
X.push_back(n - 1);
Y.push_back(n - 2);
count += 1;
}
if (A[n - 2][n - 1] == '1') {
X.push_back(n - 2);
Y.push_back(n - 1);
count += 1;
}
} else if (F_1 == 2) {
if (A[0][1] == '1') {
X.push_back(0);
Y.push_back(1);
count += 1;
}
if (A[1][0] == '1') {
X.push_back(1);
Y.push_back(0);
count += 1;
}
} else if (F_0 == 2) {
if (A[0][1] == '0') {
X.push_back(0);
Y.push_back(1);
count += 1;
}
if (A[1][0] == '0') {
X.push_back(1);
Y.push_back(0);
count += 1;
}
} else if ((S_0 == 1 || S_1 == 1) && (F_0 == 1 || F_1 == 1)) {
if (A[0][1] == '1') {
count += 1;
X.push_back(0);
Y.push_back(1);
}
if (A[1][0] == '1') {
count += 1;
X.push_back(1);
Y.push_back(0);
}
if (A[n - 2][n - 1] == '0') {
count += 1;
X.push_back(n - 2);
Y.push_back(n - 1);
}
if (A[n - 1][n - 2] == '0') {
count += 1;
X.push_back(n - 1);
Y.push_back(n - 2);
}
}
cout << count << "\n";
for (i = 0; i < X.size(); i++) {
cout << (X[i] + 1) << " " << (Y[i] + 1) << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
char arr[n][n];
for (long long i = 0; i < n; i++)
for (long long j = 0; j < n; j++) cin >> arr[i][j];
bool f = false;
if ((arr[0][1] == arr[1][0]) && (arr[n - 1][n - 2] == arr[n - 2][n - 1]) &&
(arr[0][1] != arr[n - 1][n - 2]))
f = true;
if (f)
cout << 0 << '\n';
else {
long long cnt0 = 0, cnt1 = 0;
if (arr[0][1] == '0')
cnt0++;
else
cnt1++;
if (arr[1][0] == '0')
cnt0++;
else
cnt1++;
if (arr[n - 1][n - 2] == '0')
cnt0++;
else
cnt1++;
if (arr[n - 2][n - 1] == '0')
cnt0++;
else
cnt1++;
if (cnt0 == cnt1 + 2) {
if (arr[0][1] == arr[1][0]) {
cout << 1 << '\n';
if (arr[n - 1][n - 2] == '0')
cout << n << " " << n - 1 << '\n';
else
cout << n - 1 << " " << n << '\n';
} else {
cout << 1 << '\n';
if (arr[0][1] == '0')
cout << 1 << " " << 2 << '\n';
else
cout << 2 << " " << 1 << '\n';
}
} else if (cnt1 == cnt0 + 2) {
if (arr[0][1] == arr[1][0]) {
cout << 1 << '\n';
if (arr[n - 1][n - 2] == '1')
cout << n << " " << n - 1 << '\n';
else
cout << n - 1 << " " << n << '\n';
} else {
cout << 1 << '\n';
if (arr[0][1] == '1')
cout << 1 << " " << 2 << '\n';
else
cout << 2 << " " << 1 << '\n';
}
} else if (cnt1 == cnt0) {
cout << 2 << '\n';
cout << 1 << " " << 2 << '\n';
if (arr[n - 1][n - 2] != arr[0][1])
cout << n << " " << n - 1 << '\n';
else
cout << n - 1 << " " << n << '\n';
} else {
cout << 2 << '\n';
cout << 1 << " " << 2 << '\n';
cout << 2 << " " << 1 << '\n';
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long T, N, M, ans, temp;
char m[200][2001];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> T;
for (long long t = 1; t <= T; t++) {
cin >> N;
for (long long i = 0; i < N; i++) {
cin >> m[i];
}
vector<pair<long long, long long> > c;
if (m[0][1] == '0' && m[1][0] == '0') {
if (m[N - 1][N - 2] == '0') {
c.push_back({N, N - 1});
}
if (m[N - 2][N - 1] == '0') {
c.push_back({N - 1, N});
}
} else if (m[0][1] == '1' && m[1][0] == '1') {
if (m[N - 1][N - 2] == '1') {
c.push_back({N, N - 1});
}
if (m[N - 2][N - 1] == '1') {
c.push_back({N - 1, N});
}
} else {
if (m[N - 1][N - 2] == '0' && m[N - 2][N - 1] == '0') {
if (m[0][1] == '0') {
c.push_back({1, 2});
}
if (m[1][0] == '0') {
c.push_back({2, 1});
}
} else if (m[N - 1][N - 2] == '1' && m[N - 2][N - 1] == '1') {
if (m[0][1] == '1') {
c.push_back({1, 2});
}
if (m[1][0] == '1') {
c.push_back({2, 1});
}
} else {
if (m[0][1] == '1') {
c.push_back({1, 2});
}
if (m[1][0] == '1') {
c.push_back({2, 1});
}
if (m[N - 1][N - 2] == '0') {
c.push_back({N, N - 1});
}
if (m[N - 2][N - 1] == '0') {
c.push_back({N - 1, N});
}
}
}
cout << c.size() << '\n';
for (long long i = 0; i < c.size(); i++) {
cout << c[i].first << ' ' << c[i].second << '\n';
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string mp[210];
int n;
bool func(char x, char y) {
int res = (mp[1][0] == x) + (mp[0][1] == x) + (mp[n - 1][n - 2] == y) +
(mp[n - 2][n - 1] == y);
if (res <= 2) {
cout << res << "\n";
if (mp[1][0] != y)
cout << "2 1"
<< "\n";
if (mp[0][1] != y)
cout << "1 2"
<< "\n";
if (mp[n - 1][n - 2] != x) cout << n << " " << n - 1 << "\n";
if (mp[n - 2][n - 1] != x) cout << n - 1 << " " << n << "\n";
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int i, j, k, a, b, c, x, y, z, m, t;
cin >> t;
string s;
while (t--) {
cin >> n;
getline(cin, s);
for (i = 0; i < n; i++) {
getline(cin, mp[i]);
}
if (!func('0', '1')) func('1', '0');
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, o = 0, c = 0;
cin >> n;
vector<vector<char>> V(n, vector<char>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) cin >> V[i][j];
}
if (V[1][0] == V[0][1] && V[n - 1][n - 2] == V[n - 2][n - 1]) {
if (V[1][0] == V[n - 1][n - 2]) {
cout << "2" << endl;
cout << "1"
<< " "
<< "2" << endl;
cout << "2"
<< " "
<< "1";
} else
cout << "0";
} else if (V[0][1] == V[1][0]) {
cout << "1" << endl;
if (V[n - 1][n - 2] != V[0][1])
cout << n - 1 << " " << n;
else
cout << n << " " << n - 1;
} else if (V[n - 1][n - 2] == V[n - 2][n - 1]) {
cout << "1" << endl;
if (V[n - 1][n - 2] != V[0][1])
cout << "2"
<< " "
<< "1";
else
cout << "1"
<< " "
<< "2";
} else {
cout << "2" << endl;
cout << "1"
<< " "
<< "2" << endl;
if (V[n - 2][n - 1] == V[0][1])
cout << n << " " << n - 1;
else
cout << n - 1 << " " << n;
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, t;
char s[205][205];
int main() {
cin >> t;
int i, j, k;
while (t--) {
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> (s[i] + 1);
}
int cnt = 0;
bool i1 = 0, i2 = 0;
if (s[1][2] == s[2][1]) {
if (s[n][n - 1] == s[1][2]) {
++cnt;
i1 = 1;
}
if (s[n - 1][n] == s[1][2]) {
++cnt;
i2 = 1;
}
cout << cnt << endl;
if (i1) cout << n << " " << n - 1 << endl;
if (i2) cout << n - 1 << " " << n << endl;
continue;
}
if (s[1][2] != s[2][1]) {
if (s[n][n - 1] == s[n - 1][n]) {
cout << 1 << endl;
if (s[1][2] == s[n][n - 1]) {
cout << 1 << " " << 2 << endl;
} else
cout << 2 << " " << 1 << endl;
} else {
cout << 2 << endl;
cout << 2 << " " << 1 << endl;
if (s[n][n - 1] == s[1][2]) {
cout << n << " " << n - 1 << endl;
} else
cout << n - 1 << " " << n << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int n;
int list[201][201];
cin >> t;
while (t > 0) {
t--;
cin >> n;
char qwe;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((i == 0 && j == 0) || (i == (n - 1) && j == (n - 1))) {
cin >> qwe;
} else {
cin >> qwe;
list[i][j] = (int)qwe;
}
}
}
int b = list[n - 2][n - 1];
int c = list[n - 1][n - 2];
int d = list[n - 3][n - 1];
int e = list[n - 2][n - 2];
int f = list[n - 1][n - 3];
int num = 0;
if (f == e && e == d) {
if (c == e) {
num++;
}
if (b == e) {
num++;
}
cout << num << endl;
if (c == e) {
cout << n - 1 + 1 << " " << n - 2 + 1 << endl;
}
if (b == e) {
cout << n - 2 + 1 << " " << n - 1 + 1 << endl;
}
} else if (e != f && e != d) {
if (b == c) {
if (b == e) {
cout << 1 << endl << n - 2 + 1 << " " << n - 2 + 1 << endl;
} else {
cout << 2 << endl;
cout << n - 1 + 1 << " " << n - 3 + 1 << endl;
cout << n - 3 + 1 << " " << n - 1 + 1 << endl;
}
} else {
cout << 2 << endl;
cout << n - 2 + 1 << " " << n - 2 + 1 << endl;
if (c == e) {
cout << n - 2 + 1 << " " << n - 1 + 1 << endl;
} else {
cout << n - 1 + 1 << " " << n - 2 + 1 << endl;
}
}
} else {
if (b == c && b == e) {
cout << 2 << endl;
cout << n - 2 + 1 << " " << n - 2 + 1 << endl;
if (f == e) {
cout << n - 1 + 1 << " " << n - 3 + 1 << endl;
} else {
cout << n - 3 + 1 << " " << n - 1 + 1 << endl;
}
} else {
if (b == c) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
if (f == e) {
cout << n - 3 + 1 << " " << n - 1 + 1 << endl;
} else {
cout << n - 1 + 1 << " " << n - 3 + 1 << endl;
}
if (b == c) {
} else {
if (e == b) {
cout << n - 2 + 1 << " " << n - 1 + 1 << endl;
} else {
cout << n - 1 + 1 << " " << n - 2 + 1 << endl;
}
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
char s[n + 1][n + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> s[i][j];
}
}
vector<pair<int, int>> ans;
char a = s[2][1];
char b = s[1][2];
char c = s[n - 1][n];
char d = s[n][n - 1];
if (a == b && c == d && a == c) {
cout << 2 << "\n";
cout << 1 << " " << 2 << "\n";
cout << 2 << " " << 1 << "\n";
continue;
}
if (a == b) {
if (c == d) {
if (a != c) {
cout << 0 << "\n";
continue;
}
}
cout << 1 << "\n";
if (a == c) {
cout << n - 1 << " " << n << "\n";
} else {
cout << n << " " << n - 1 << "\n";
}
} else if (c == d) {
if (a == b) {
if (a != c) {
cout << 0 << "\n";
continue;
}
}
cout << 1 << "\n";
if (c == a) {
cout << 2 << " " << 1 << "\n";
} else {
cout << 1 << " " << 2 << "\n";
}
} else {
cout << 2 << "\n";
if (a == '0') {
cout << 2 << " " << 1 << "\n";
} else
cout << 1 << " " << 2 << "\n";
if (c == '1') {
cout << n - 1 << " " << n << "\n";
} else
cout << n << " " << n - 1 << "\n";
}
}
cerr << "\nTime Taken : " << (float)(clock() - time_p) / CLOCKS_PER_SEC
<< "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 210;
char s[maxn][maxn];
bool vis[maxn][maxn];
int d[][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int n;
bool dfs(int x, int y, char ch) {
for (int i = 0; i < 4; ++i) {
int nx = x + d[i][0], ny = y + d[i][1];
if (nx == n && ny == n) return 1;
if (nx < 1 || nx > n || ny < 1 || ny > n || vis[nx][ny] || s[nx][ny] != ch)
continue;
vis[nx][ny] = 1;
if (dfs(nx, ny, ch)) return 1;
}
return 0;
}
bool check() {
memset(vis, 0, sizeof(vis));
return !dfs(1, 1, '0') && !dfs(1, 1, '1');
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> (s[i] + 1);
s[1][2] = ((s[1][2] - '0') ^ 1) + '0';
s[2][1] = ((s[2][1] - '0') ^ 1) + '0';
if (check()) {
cout << 2 << '\n';
cout << "1 2\n2 1\n";
continue;
}
s[1][2] = ((s[1][2] - '0') ^ 1) + '0';
s[2][1] = ((s[2][1] - '0') ^ 1) + '0';
s[n][n - 1] = ((s[n][n - 1] - '0') ^ 1) + '0';
s[n - 1][n] = ((s[n - 1][n] - '0') ^ 1) + '0';
if (check()) {
cout << 2 << '\n';
cout << n << ' ' << n - 1 << '\n';
cout << n - 1 << ' ' << n << '\n';
continue;
}
s[n][n - 1] = ((s[n][n - 1] - '0') ^ 1) + '0';
s[n - 1][n] = ((s[n - 1][n] - '0') ^ 1) + '0';
pair<int, int> a[3] = {make_pair(0, 0), make_pair(1, 2), make_pair(2, 1)};
pair<int, int> b[3] = {make_pair(0, 0), make_pair(n, n - 1),
make_pair(n - 1, n)};
for (int i = 0; i <= 2; ++i) {
int x = a[i].first, y = a[i].second;
if (x) s[x][y] = ((s[x][y] - '0') ^ 1) + '0';
for (int j = 0; j <= 2; ++j) {
int xx = b[j].first, yy = b[j].second;
if (xx) s[xx][yy] = ((s[xx][yy] - '0') ^ 1) + '0';
if (check()) {
if (x && xx) {
cout << 2 << '\n';
cout << x << ' ' << y << '\n';
cout << xx << ' ' << yy << '\n';
} else if (x) {
cout << 1 << '\n';
cout << x << ' ' << y << '\n';
} else if (xx) {
cout << 1 << '\n';
cout << xx << ' ' << yy << '\n';
} else {
cout << 0 << '\n';
}
goto done;
}
if (xx) s[xx][yy] = ((s[xx][yy] - '0') ^ 1) + '0';
}
if (x) s[x][y] = ((s[x][y] - '0') ^ 1) + '0';
}
done:
continue;
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.