#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, s;
vector<int> tab;
int solve() {
int endings = 0;
for (int i = 0; i < n-1; ++i) {
//for (int k = 0; k < n; ++k) cout << tab[k] << ' ';cout << endl;
if (tab[i]-1 > tab[i+1]) return -3;
if (tab[i]-1 == tab[i+1]) { //Means i contains both ends
for (int j = i+2; j < n; ++j)
if (tab[j]>0) return -1;
return 1;
}
if (tab[i] == tab[i+1]) { //Means i contains at least one end
endings++;
}
tab[i+1] -= tab[i]-endings;
tab[i] -= tab[i];
}
if (tab[n-1] == 1)
return 2;
return -2;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(NULL));
int t;
cin >> t;
while (t--) {
cin >> n;
tab.resize(n);
for (int i = 0; i < n; ++i) cin >> tab[i];
/*n = 6;
tab.resize(n);
for (int i = 0; i < n; ++i) tab[i] = rand()%6;*/
bool a = solve()>0;
/*bool b = brute();
if (a) l++;
if (a!=b) {
for (int i = 0; i < n; ++i) cout << tab[i];
return -38;
}*/
cout << (a ? "TAK" : "NIE") /*<< ' ' << (b ? "TAK" : "NIE")*/ << '\n';
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <bits/stdc++.h> using namespace std; #define int long long int n, s; vector<int> tab; int solve() { int endings = 0; for (int i = 0; i < n-1; ++i) { //for (int k = 0; k < n; ++k) cout << tab[k] << ' ';cout << endl; if (tab[i]-1 > tab[i+1]) return -3; if (tab[i]-1 == tab[i+1]) { //Means i contains both ends for (int j = i+2; j < n; ++j) if (tab[j]>0) return -1; return 1; } if (tab[i] == tab[i+1]) { //Means i contains at least one end endings++; } tab[i+1] -= tab[i]-endings; tab[i] -= tab[i]; } if (tab[n-1] == 1) return 2; return -2; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //srand(time(NULL)); int t; cin >> t; while (t--) { cin >> n; tab.resize(n); for (int i = 0; i < n; ++i) cin >> tab[i]; /*n = 6; tab.resize(n); for (int i = 0; i < n; ++i) tab[i] = rand()%6;*/ bool a = solve()>0; /*bool b = brute(); if (a) l++; if (a!=b) { for (int i = 0; i < n; ++i) cout << tab[i]; return -38; }*/ cout << (a ? "TAK" : "NIE") /*<< ' ' << (b ? "TAK" : "NIE")*/ << '\n'; } } |
English