链接Miku
规律简单,暴力模拟
此题大坑点
一个元素可能在此组没出现但是出现在上一组
一定要坚持读完数据
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int t;
int n,m;
//int x,y;
int f;
int a[1001][1001],b[1001][1001];
int maxn=1000005;
int x[2000001],y[2000001];
int xx;
int idx[2000001];
int idy[2000001];
int cnt1;
int cnt2;
int maxx[2000001];
int may[2000001];
int main(){
// freopen("std.in","r",stdin);
// freopen("std1.out","w",stdout);
scanf("%d",&t);
while(t--){
int f=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(idx,0,sizeof(idx));
memset(idy,0,sizeof(idy));
memset(maxx,0,sizeof(maxx));
memset(may,0,sizeof(may));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j){
scanf("%d",&a[i][j]);
a[i][j]+=maxn;
idx[a[i][j]]=i;
idy[a[i][j]]=j;
}
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j){
scanf("%d",&xx);
x[xx+maxn]=i;
y[xx+maxn]=j;
if(idx[xx+maxn]==0&&f==0)
{
cout<<"NIE"<<endl;
f=1;
}
}
if(f)
continue;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(!maxx[x[a[i][j]]]){
maxx[x[a[i][j]]]=i;
}else{
if(idx[a[i][j]]!=maxx[x[a[i][j]]]){
cout<<"NIE"<<endl;
f=1;
break;
}
}
if(!may[y[a[i][j]]]){
may[y[a[i][j]]]=j;
}else{
if(idy[a[i][j]]!=may[y[a[i][j]]]){
cout<<"NIE"<<endl;
f=1;
break;
}
}
}
if(f)
break;
}
if(f)
continue;
else{
cout<<"TAK"<<endl;
}
}
return 0;
}