这也算个神题吧 也只有POI出的出来了
Po姐的题解很详细就不多说了
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline void read(int &x){
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
const int N=100005;
int n,a[N];
inline bool Jud(){
while (n>1){
if (!a[1]) a[1]=2;
if (a[n]==1) n--;
else if (a[n]==3) a[n]=2;
for (int i=n;i;i--)
if (!a[i]){
if (a[i-1]==1)
a[i-1]=2,a[i]=-1;
else if (a[i-1]==3)
a[i-1]=2,a[i]=2;
else
return 0;
}
int pnt=0;
for (int i=1;i<=n;i++)
if (a[i]!=-1)
a[++pnt]=a[i];
n=pnt;
for (int i=1;i<=n;i++) a[i]--;
}
return 1;
}
int main(){
int Q;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
read(Q);
while (Q--){
read(n);
for (int i=1;i<=n;i++) read(a[i]);
if (Jud())printf("TAK\n");else printf("NIE\n");
}
return 0;
}