#include <bits/stdc++.h> using namespace std; int tab[1000001]; int main() { ios_base::sync_with_stdio(0); int i, t, n, l, p, maks; cin >> t; while(t--){ cin >> n; maks = 0; for(i = 0; i < n; i++) { cin >> tab[i]; maks = max(tab[i], maks); } l = 0; p = n-1; while(tab[l] == 0) l++; while(tab[p] == 0) p--; bool odp = true, pocz = false; long long s = tab[l]; for(i = l + 1; i <= p; i++){ if (tab[i] == 0) { odp = false; break; } s = tab[i] - s; if (s < -1) { odp = false; break; } if (s == 0 && pocz == false && i < p) { s = 1; pocz = true; } } //cout << s << endl; if (i == p+1 && s == 1 && pocz == true && maks> 1) { odp = false; } if (s > 1) odp = false; if(odp == true) cout <<"TAK\n"; else cout <<"NIE\n"; } 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 | #include <bits/stdc++.h> using namespace std; int tab[1000001]; int main() { ios_base::sync_with_stdio(0); int i, t, n, l, p, maks; cin >> t; while(t--){ cin >> n; maks = 0; for(i = 0; i < n; i++) { cin >> tab[i]; maks = max(tab[i], maks); } l = 0; p = n-1; while(tab[l] == 0) l++; while(tab[p] == 0) p--; bool odp = true, pocz = false; long long s = tab[l]; for(i = l + 1; i <= p; i++){ if (tab[i] == 0) { odp = false; break; } s = tab[i] - s; if (s < -1) { odp = false; break; } if (s == 0 && pocz == false && i < p) { s = 1; pocz = true; } } //cout << s << endl; if (i == p+1 && s == 1 && pocz == true && maks> 1) { odp = false; } if (s > 1) odp = false; if(odp == true) cout <<"TAK\n"; else cout <<"NIE\n"; } return 0; } |