#include <bits/stdc++.h> using namespace std; bool start(vector<int> a) { int n = (int) a.size(); for (int i = 0; i < n - 1; i++) { a[i+1] -= a[i] - 1; if (a[i+1] < 0 || (a[i+1] == 0 && i + 1 != n - 1)) { return false; } } return a.back() <= 1; } bool test_case() { int n; cin >> n; vector<int> a(n); for (int& x : a) { cin >> x; } if (a == vector<int>(n, 0)) { return true; } for (int rep = 0; rep < 2; rep++) { while (a.back() == 0) { a.pop_back(); } reverse(a.begin(), a.end()); } n = (int) a.size(); if (start(a)) { return true; } if (n >= 2 && a[1] >= 2) { a[1]--; if (start(a)) { return true; } } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { cout << (test_case() ? "TAK\n" : "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 | #include <bits/stdc++.h> using namespace std; bool start(vector<int> a) { int n = (int) a.size(); for (int i = 0; i < n - 1; i++) { a[i+1] -= a[i] - 1; if (a[i+1] < 0 || (a[i+1] == 0 && i + 1 != n - 1)) { return false; } } return a.back() <= 1; } bool test_case() { int n; cin >> n; vector<int> a(n); for (int& x : a) { cin >> x; } if (a == vector<int>(n, 0)) { return true; } for (int rep = 0; rep < 2; rep++) { while (a.back() == 0) { a.pop_back(); } reverse(a.begin(), a.end()); } n = (int) a.size(); if (start(a)) { return true; } if (n >= 2 && a[1] >= 2) { a[1]--; if (start(a)) { return true; } } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { cout << (test_case() ? "TAK\n" : "NIE\n"); } } |