#include <iostream> using namespace std; const int MAX_N = 1000033; int t, n; long long int a[MAX_N]; long long int b[MAX_N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> t; while (t > 0) { --t; cin >> n; a[0] = 0; a[n + 1] = 0; int left=-1, right=-1; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (left < 0 && a[i]>0) left = i; if (a[i] > 0) right = i; b[i] = 0; } b[0] = 0; b[n + 1] = 0; int counter = 0; for (int i = 1; i <= n; ++i) { long long int sum_neighbors = a[i - 1] + a[i + 1]; if (a[i] == sum_neighbors) { b[i] = -1; counter += 1; } if (a[i] == sum_neighbors + 1) { b[i] = -2; counter += 2; } if (a[i] > sum_neighbors + 1) { counter = 10; } } if (counter > 2) { cout << "NIE" << endl; continue; } int counter_breaks = 0; bool isGood = true; for (int i = left; i <= right; ++i) { a[i] = 2 * a[i] + b[i]; } for (int i = left; i <= right; ++i) { a[i] = a[i] - a[i - 1]; if (a[i] < -1) { isGood = false; break; } if (a[i] == 0) { ++counter_breaks; if (counter_breaks > 1) { isGood = false; break; } } } if (isGood == false) { cout << "NIE" << endl; continue; } if (a[right] < 2) { cout << "TAK" << endl; continue; } cout << "NIE" << endl; } return 0; }
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <iostream> using namespace std; const int MAX_N = 1000033; int t, n; long long int a[MAX_N]; long long int b[MAX_N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> t; while (t > 0) { --t; cin >> n; a[0] = 0; a[n + 1] = 0; int left=-1, right=-1; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (left < 0 && a[i]>0) left = i; if (a[i] > 0) right = i; b[i] = 0; } b[0] = 0; b[n + 1] = 0; int counter = 0; for (int i = 1; i <= n; ++i) { long long int sum_neighbors = a[i - 1] + a[i + 1]; if (a[i] == sum_neighbors) { b[i] = -1; counter += 1; } if (a[i] == sum_neighbors + 1) { b[i] = -2; counter += 2; } if (a[i] > sum_neighbors + 1) { counter = 10; } } if (counter > 2) { cout << "NIE" << endl; continue; } int counter_breaks = 0; bool isGood = true; for (int i = left; i <= right; ++i) { a[i] = 2 * a[i] + b[i]; } for (int i = left; i <= right; ++i) { a[i] = a[i] - a[i - 1]; if (a[i] < -1) { isGood = false; break; } if (a[i] == 0) { ++counter_breaks; if (counter_breaks > 1) { isGood = false; break; } } } if (isGood == false) { cout << "NIE" << endl; continue; } if (a[right] < 2) { cout << "TAK" << endl; continue; } cout << "NIE" << endl; } return 0; } |