#include <bits/stdc++.h> using namespace std; const int SIZE=1e6+6; int tab[SIZE]; int tabw[SIZE]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T,N,a,p; bool can; cin>>T; while(T--){ cin>>N; for(int i=1;i<=N;i++){cin>>tab[i];} tab[N+1]=0; for(int i=1;i<=N;i++){ for(int i=1;i<=N;i++){tabw[i]=tab[i];}tabw[N+1]=0; a=i; p=i-1; while(true){ tabw[a]--; if(tabw[p]){swap(a,p);continue;} if(p<a){ if(!tabw[a+1]){break;} p++; a++; }else{ if(!tabw[a-1]){break;} p--; a--; } } can=1; for(int i=1;i<=N;i++){if(tabw[i]){can=0;break;}} if(can){cout<<"TAK\n";break;} } if(!can){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 47 48 | #include <bits/stdc++.h> using namespace std; const int SIZE=1e6+6; int tab[SIZE]; int tabw[SIZE]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T,N,a,p; bool can; cin>>T; while(T--){ cin>>N; for(int i=1;i<=N;i++){cin>>tab[i];} tab[N+1]=0; for(int i=1;i<=N;i++){ for(int i=1;i<=N;i++){tabw[i]=tab[i];}tabw[N+1]=0; a=i; p=i-1; while(true){ tabw[a]--; if(tabw[p]){swap(a,p);continue;} if(p<a){ if(!tabw[a+1]){break;} p++; a++; }else{ if(!tabw[a-1]){break;} p--; a--; } } can=1; for(int i=1;i<=N;i++){if(tabw[i]){can=0;break;}} if(can){cout<<"TAK\n";break;} } if(!can){cout<<"NIE\n";} } return 0;} |