This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=2000010;
int n,m,G,Il,Ir;
int Tl[N][4],Tr[N][4];
vector<int> Fl[N],Fr[N];
string s;
void add(int i)
{
cin>>s;
for(auto & c : s)
{
if(c=='G') c='B';
if(c=='U') c='D';
}
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)
{
if(c=='G') c='B';
if(c=='U') c='D';
}
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)
{
if(c=='G') c='B';
if(c=='U') c='D';
}
reverse(s.begin(),s.end());
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);
//freopen("RNA.inp","r",stdin);
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |