#include <bits/stdc++.h> #define fucktor vector using namespace std; struct backshot{ int toget; int togive; }; void solve(){ int n; cin >> n; fucktor<backshot>shots(n); fucktor<int>v(n); int left = -1; int right = n; for(int i = 0; i < n; ++i){ cin >> v[i]; if(v[i] == 0 and left+1 == i) left = i; else if(v[i] == 0) right = min(right, i); shots[i] = {v[i], v[i]}; } for(int i = 0; i <= left; ++i){ if(v[i]){ cout << "NIE" << endl; return; } } for(int i = right; i < n; ++i){ if(v[i]){ cout << "NIE" << endl; return; } } for(int i = left+1; i < right-1; ++i){ int tg = shots[i].toget; shots[i].toget = max(0, shots[i].toget-shots[i+1].togive); shots[i+1].togive = max(0, shots[i+1].togive - tg); int infuture = shots[i+1].toget - shots[i].togive; if(infuture < 1 and i < right-2){shots[i].togive -= (shots[i+1].toget-1);shots[i+1].toget = 1;} else {shots[i+1].toget = max(0, shots[i+1].toget - shots[i].togive); shots[i].togive = 0;} } int p1 = 0, p2 = 0; for(int i = 0; i < n; ++i){ p1 += shots[i].toget; p2 += shots[i].togive; } if((p1 <= 1) and (p2 <= 1)){ cout << "TAK" << endl; } else{ cout << "NIE" << endl; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) solve(); }
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 | #include <bits/stdc++.h> #define fucktor vector using namespace std; struct backshot{ int toget; int togive; }; void solve(){ int n; cin >> n; fucktor<backshot>shots(n); fucktor<int>v(n); int left = -1; int right = n; for(int i = 0; i < n; ++i){ cin >> v[i]; if(v[i] == 0 and left+1 == i) left = i; else if(v[i] == 0) right = min(right, i); shots[i] = {v[i], v[i]}; } for(int i = 0; i <= left; ++i){ if(v[i]){ cout << "NIE" << endl; return; } } for(int i = right; i < n; ++i){ if(v[i]){ cout << "NIE" << endl; return; } } for(int i = left+1; i < right-1; ++i){ int tg = shots[i].toget; shots[i].toget = max(0, shots[i].toget-shots[i+1].togive); shots[i+1].togive = max(0, shots[i+1].togive - tg); int infuture = shots[i+1].toget - shots[i].togive; if(infuture < 1 and i < right-2){shots[i].togive -= (shots[i+1].toget-1);shots[i+1].toget = 1;} else {shots[i+1].toget = max(0, shots[i+1].toget - shots[i].togive); shots[i].togive = 0;} } int p1 = 0, p2 = 0; for(int i = 0; i < n; ++i){ p1 += shots[i].toget; p2 += shots[i].togive; } if((p1 <= 1) and (p2 <= 1)){ cout << "TAK" << endl; } else{ cout << "NIE" << endl; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) solve(); } |