#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() void solve() { int n; cin >> n; vector<ll>T(n); rep(i, n) cin >> T[i]; rep(i, 2) { while(T.back()==0) T.pop_back(); reverse(all(T)); } for(auto i : T) if(!i) { cout << "NIE\n"; return; } n=T.size(); rep(i, 5) for(int j=n-1; j>=n-5; --j) if(i<=j) { rep(a, n) if(i<=a && a<=j) --T[a]; ll x=0; bool ok=true; rep(a, n-1) { x=T[a]-x; if(i<=a && a<j) { if(x<0) ok=false; } else { if(x<=0) ok=false; } } if(x!=T[n-1]) ok=false; if(ok) { cout << "TAK\n"; return; } rep(a, n) if(i<=a && a<=j) ++T[a]; } cout << "NIE\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int _=1; cin >> _; while(_--) 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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() void solve() { int n; cin >> n; vector<ll>T(n); rep(i, n) cin >> T[i]; rep(i, 2) { while(T.back()==0) T.pop_back(); reverse(all(T)); } for(auto i : T) if(!i) { cout << "NIE\n"; return; } n=T.size(); rep(i, 5) for(int j=n-1; j>=n-5; --j) if(i<=j) { rep(a, n) if(i<=a && a<=j) --T[a]; ll x=0; bool ok=true; rep(a, n-1) { x=T[a]-x; if(i<=a && a<j) { if(x<0) ok=false; } else { if(x<=0) ok=false; } } if(x!=T[n-1]) ok=false; if(ok) { cout << "TAK\n"; return; } rep(a, n) if(i<=a && a<=j) ++T[a]; } cout << "NIE\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int _=1; cin >> _; while(_--) solve(); } |