Description
Input
Output
Sample Input
3 4 4 2
xx..
.xx.
xx..
x.
.x
x.
..
2 2 2 2
xx
xx
.x
x.
Sample Output
NIE
#include<cstdio> #include<iostream> #include<cstring> #define LL long long using namespace std; inline LL read() { LL x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T,n,m,a,b,cnt; bool map[1010][1010]; bool mrk[1010][1010]; int colx[1000010],coly[1000010]; inline bool paint(int x,int y) { for (int i=1;i<=cnt;i++) { int nx=x+colx[i],ny=y+coly[i]; if (nx<1||ny<1||nx>n||ny>m||!mrk[nx][ny])return 1; mrk[nx][ny]=0; } return 0; } inline void work() { n=read();m=read(); a=read();b=read(); for(int i=1;i<=n;i++) for (int j=1;j<=m;j++) { char ch=getchar();while (ch!='x'&&ch!='.')ch=getchar(); mrk[i][j]=map[i][j]=(ch=='x'); } cnt=0; for (int i=1;i<=a;i++) for (int j=1;j<=b;j++) { char ch=getchar();while (ch!='x'&&ch!='.')ch=getchar(); if (ch=='x') { colx[++cnt]=i; coly[cnt]=j; } } if (cnt==0) { printf("NIE\n"); return; } int rex=colx[1],rey=coly[1]; for (int i=1;i<=cnt;i++) { colx[i]-=rex; coly[i]-=rey; } for(int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (mrk[i][j]) { if (paint(i,j)) { printf("NIE\n"); return; } } printf("TAK\n"); } int main() { T=read(); while (T--)work(); }