记录编号 |
583039 |
评测结果 |
AAAAAAAAAAAAA |
题目名称 |
[USACO Dec08] 密信 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.332 s |
提交时间 |
2023-10-03 17:16:17 |
内存使用 |
8.11 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4+10;
int n,m;
int s[N];
class made{
public:
int sum,f;
int so[3];
}a[N*3];
int tot,len,ans;
void insert(){
int p = 0;
for(int i = 1;i <= len;i++){
int u = s[i];
if(a[p].so[u] == 0)a[p].so[u] = ++tot;
a[p].sum++;
p = a[p].so[u];
}
a[p].sum++,a[p].f++;
}
int ask(){
int p = 0,ans = 0;
for(int i = 1;i <= len;i++){
ans += a[p].f;
int u = s[i];
if(a[p].so[u] == 0)return ans;
p = a[p].so[u];
}
ans += a[p].sum;
return ans;
}
int main(){
freopen("sec.in","r",stdin);
freopen("sec.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++){
scanf("%d",&len);
for(int j = 1;j <= len;j++){
char ch[1];scanf("%s",ch);
s[j] = (ch[0] == '1');
}
insert();
}
for(int i = 1;i <= m;i++){
scanf("%d",&len);
ans = 0;
for(int j = 1;j <= len;j++){
char ch[2];scanf("%s",ch);
s[j] = (ch[0] == '1');
}
printf("%d\n",ask());
}
return 0;
}