# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1267576 | quangykqh | Selling RNA Strands (JOI16_selling_rna) | C++20 | 1598 ms | 200416 KiB |
#include<bits/stdc++.h>
using namespace std;
const int MN=1e5+1209;
long long n,m,k,ans,pos[500],MIN;
string skibidi[MN],sex[MN],s[MN];
struct trie
{
struct Node2
{
int cnt;
Node2 *child[5][5];
Node2()
{
cnt=0;
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
child[i][j]=NULL;
}
};
Node2 *root=new Node2;
Node2 *cur=root;
void addstring(string &p,string &q)
{
cur=root;
for(int i=0;i<p.length();i++)
{
if(!cur->child[pos[p[i]]][pos[q[i]]])
cur->child[pos[p[i]]][pos[q[i]]]=new Node2;
cur=cur->child[pos[p[i]]][pos[q[i]]];
}
}
void addstring2(string& s)
{
root->cnt++;
cur=root;
for(int i=0;i<s.length();i++)
{
Node2 *cb=cur;
for(int j=i;j<s.length();j++)
{
if(!cur->child[pos[s[j]]][0])break;
cur=cur->child[pos[s[j]]][0];
cur->cnt++;
}
cur=cb;
for(int j=i;j<s.length();j++)
{
if(!cur->child[0][pos[s[s.length()-j-1]]])break;
cur=cur->child[0][pos[s[s.length()-j-1]]];
cur->cnt++;
}
cur=cb;
if(!cur->child[pos[s[i]]][pos[s[s.length()-i-1]]])break;
cur=cur->child[pos[s[i]]][pos[s[s.length()-i-1]]];
cur->cnt++;
}
}
int takeans(string &p,string &q)
{
cur=root;
for(int i=0;i<p.length();i++)
{
cur=cur->child[pos[p[i]]][pos[q[i]]];
}
return cur->cnt;
}
};
trie TRIE;
int main()
{
if(fopen("GAME.INP","r"))
{
freopen("GAME.INP","r",stdin);
freopen("GAME.OUT","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
pos['A']=1;
pos['C']=2;
pos['U']=3;
pos['G']=4;
pos['#']=0;
for(int i=1;i<=n;i++)
{
cin>>s[i];
}
for(int i=1;i<=m;i++)
{
cin>>skibidi[i]>>sex[i];
reverse(sex[i].begin(),sex[i].end());
while(sex[i].length()<skibidi[i].length())
sex[i].push_back('#');
while(skibidi[i].length()<sex[i].length())
skibidi[i].push_back('#');
TRIE.addstring(skibidi[i],sex[i]);
}
for(int i=1;i<=n;i++)
{
TRIE.addstring2(s[i]);
}
for(int i=1;i<=m;i++)
cout<<TRIE.takeans(skibidi[i],sex[i])<<'\n';
}
Compilation message (stderr)
# | 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... |