# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332742 | daniel920712 | Selling RNA Strands (JOI16_selling_rna) | C++14 | 319 ms | 310188 KiB |
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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <map>
using namespace std;
struct A
{
int x,y;
int con=0;
int nxt[6][6];
}Node[1000005];
int now=1,xx,yy;
char tt[100005];
char tt2[100005];
void New(int here)
{
Node[here].con=0;
memset(Node[here].nxt,-1,sizeof(Node[here].nxt));
}
void build(int x,int y,int here)
{
int a,b;
Node[here].con++;
Node[here].x=x;
Node[here].y=y;
if(x==xx&&y==xx) return;
if(x==xx&&y==-1) return;
if(x==-1&&y==xx) return;
if(x!=-1)
{
if(tt[x]=='A') a=0;
if(tt[x]=='U') a=1;
if(tt[x]=='C') a=2;
if(tt[x]=='G') a=3;
}
if(y!=-1)
{
if(tt[xx-y-1]=='A') b=0;
if(tt[xx-y-1]=='U') b=1;
if(tt[xx-y-1]=='C') b=2;
if(tt[xx-y-1]=='G') b=3;
}
if(x==-1)
{
if(Node[here].nxt[5][b]==-1)
{
Node[here].nxt[5][b]=now++;
New(Node[here].nxt[5][b]);
}
build(-1,y+1,Node[here].nxt[5][b]);
}
else if(y==-1)
{
if(Node[here].nxt[a][5]==-1)
{
Node[here].nxt[a][5]=now++;
New(Node[here].nxt[a][5]);
}
build(x+1,-1,Node[here].nxt[a][5]);
}
else
{
if(Node[here].nxt[a][b]==-1)
{
Node[here].nxt[a][b]=now++;
New(Node[here].nxt[a][b]);
}
build(x+1,y+1,Node[here].nxt[a][b]);
if(Node[here].nxt[a][5]==-1)
{
Node[here].nxt[a][5]=now++;
New(Node[here].nxt[a][5]);
}
build(x+1,-1,Node[here].nxt[a][5]);
if(Node[here].nxt[5][b]==-1)
{
Node[here].nxt[5][b]=now++;
New(Node[here].nxt[5][b]);
}
build(-1,y+1,Node[here].nxt[5][b]);
}
}
int Find(int here)
{
int a,b;
if((Node[here].x==xx||Node[here].x==-1)&&(Node[here].y==yy||Node[here].y==-1)) return Node[here].con;
if(Node[here].x==-1||Node[here].x==xx)
{
if(tt2[yy-Node[here].y-1]=='A') b=0;
if(tt2[yy-Node[here].y-1]=='U') b=1;
if(tt2[yy-Node[here].y-1]=='C') b=2;
if(tt2[yy-Node[here].y-1]=='G') b=3;
if(Node[here].nxt[5][b]==-1) return 0;
return Find(Node[here].nxt[5][b]);
}
else if(Node[here].y==-1||Node[here].y==yy)
{
if(tt[Node[here].x]=='A') a=0;
if(tt[Node[here].x]=='U') a=1;
if(tt[Node[here].x]=='C') a=2;
if(tt[Node[here].x]=='G') a=3;
if(Node[here].nxt[a][5]==-1) return 0;
return Find(Node[here].nxt[a][5]);
}
else
{
if(tt2[yy-Node[here].y-1]=='A') b=0;
if(tt2[yy-Node[here].y-1]=='U') b=1;
if(tt2[yy-Node[here].y-1]=='C') b=2;
if(tt2[yy-Node[here].y-1]=='G') b=3;
if(tt[Node[here].x]=='A') a=0;
if(tt[Node[here].x]=='U') a=1;
if(tt[Node[here].x]=='C') a=2;
if(tt[Node[here].x]=='G') a=3;
if(Node[here].nxt[a][b]==-1) return 0;
return Find(Node[here].nxt[a][b]);
}
}
int main()
{
int N,M,K,t=0,i,j,k,t2,ans;
scanf("%d %d",&N,&M);
New(0);
for(i=0;i<N;i++)
{
scanf("%s",tt);
xx=strlen(tt);
build(0,0,0);
}
while(M--)
{
ans=0;
scanf("%s %s",tt,tt2);
xx=strlen(tt);
yy=strlen(tt2);
printf("%d\n",Find(0));
}
return 0;
}
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... |