elpsconr @ 2024-05-14 22:41:07
去掉map后只过了后面俩个测试点,为啥非要加map匹配?
#include<bits/stdc++.h>
using namespace std;
const int N=3e6+6;
typedef long long ll;
int n,q,idx,trie[N][63],st[N];
char s[N];
map<char,int> v;
void insert(char s[])
{
int p=0;
for(int i=0;s[i];++i)
{
if(!trie[p][s[i]]) trie[p][s[i]]=++idx;
p=trie[p][s[i]];st[p]++;
}
}
int query(char s[])
{
int p=0;
for(int i=0;s[i];++i)
{
if(!trie[p][s[i]]) return 0;
p=trie[p][s[i]];
}
return st[p];
}
void solve()
{
cin>>n>>q;
//memset(st,0,sizeof st);
//memset(trie,0,sizeof trie);
for(int i=0;i<=idx;i++)
{
st[i]=0;
for(int j=0;j<=62;j++)
{
trie[i][j]=0;
}
}
idx=0;
for(int i=0;i<n;++i)
{
cin>>s;insert(s);
}
for(int i=0;i<q;++i)
{
cin>>s;
cout<<query(s)<<endl;
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int t;cin>>t;
//for(char i='a';i<='z';++i) v[i]=++idx;
//for(char i='A';i<='Z';++i) v[i]=++idx;
//for(char i='0';i<='9';++i) v[i]=++idx;
while(t--)
solve();
return 0;
}
by SpeedStar @ 2024-05-14 23:53:54
@elpsconr 你看你trie数组第二维开了多大
by elpsconr @ 2024-05-15 00:07:32
@寒烟冷浅暮殇 63开五百也过不了,试过了
by elpsconr @ 2024-05-15 00:08:24
@寒烟冷浅暮殇 63开123也过不了,再大就mle了