#include <bits/stdc++.h>
using namespace std;
const int N=1000010;
int n,m,G,Il,Ir;
int Tl[N][30],Tr[N][30];
vector<int> Fl[N],Fr[N];
string s;
void add(int i)
{
cin>>s;
G=0;
for(auto & c : s)
{
if(!Tl[G][c-'A']) Tl[G][c-'A']=++Il;
G=Tl[G][c-'A'];
Fl[G].push_back(i);
}
reverse(s.begin(),s.end());
G=0;
for(auto & c : s)
{
if(!Tr[G][c-'A']) Tr[G][c-'A']=++Ir;
G=Tr[G][c-'A'];
Fr[G].push_back(i);
}
}
void get()
{
vector<int> A;
G=0;
cin>>s;
for(auto & c : s)
{
G=Tl[G][c-'A'];
if(!G) break;
}
A.insert(A.end(),Fl[G].begin(),Fl[G].end());
G=0;
cin>>s;
for(auto & c : s)
{
G=Tr[G][c-'A'];
if(!G) break;
}
A.insert(A.end(),Fr[G].begin(),Fr[G].end());
sort(A.begin(),A.end());
int ans=0;
for(int i=0; i<(int)A.size()-1; ++i) ans+=A[i]==A[i+1];
cout<<ans<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(int i=0; i<n; ++i) add(i);
for(int i=0; i<m; ++i) get();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
47352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
467 ms |
404516 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1563 ms |
49424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
47352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |