1 条题解
-
0
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; const int N=1010; const ull base=13331; ull h[N][N],p[N*N]; char s[N]; ull get(ull f[],int l,int r){return f[r]-f[l-1]*p[r-l+1];} unordered_map< ull , bool > st; int main() { int n,m,a,b;scanf("%d%d%d%d",&n,&m,&a,&b); p[0]=1;for(int i=1;i<=1000000;i++)p[i]=p[i-1]*base; for(int i=1;i<=n;i++) { scanf("%s",s+1); h[i][0]=0;for(int j=1;j<=m;j++)h[i][j]=h[i][j-1]*base+s[j]-'0'; } for(int j=b;j<=m;j++) { ull t=0; int l=j-b+1,r=j; for(int i=1;i<=n;i++) { t=t*p[ b ]+get(h[i],l,r); if(i>a)t-=get(h[i-a],l,r)*p[a*b]; if(i>=a)st[t]=1; } } int q;scanf("%d",&q); while(q--) { ull t=0; for(int i=1;i<=a;i++) { scanf("%s",s+1); for(int j=1;j<=b;j++)t=t*base+s[j]-'0'; } if(st.count(t))puts("1");else puts("0"); } return 0; }
- 1
信息
- ID
- 4016
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 49
- 已通过
- 17
- 上传者