# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
332706 | daniel920712 | Selling RNA Strands (JOI16_selling_rna) | C++14 | 151 ms | 68204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <map>
using namespace std;
int MOD=1e9+7;
vector < int > a[100005],b[100005];
vector < int > can;
map < pair < int , int > , int > con[65][65];
char tt[100005];
char tt2[100005];
int sz[100005];
int main()
{
int N,M,K,t=0,i,j,k,t2,xx,yy,ans;
scanf("%d %d",&N,&M);
for(i=0;i<N;i++)
{
scanf("%s",tt);
K=(int) strlen(tt);
sz[i]=K;
if(K>50) can.push_back(i);
t=0;
for(j=0;j<K;j++)
{
t=(int) ( ((long long) t)*4%MOD);
if(tt[j]=='U') t++;
if(tt[j]=='C') t+=2;
if(tt[j]=='G') t+=3;
t%=MOD;
a[i].push_back(t);
}
t=0;
for(j=K-1;j>=0;j--)
{
t=(int) ( ((long long) t)*4%MOD);
if(tt[j]=='U') t++;
if(tt[j]=='C') t+=2;
if(tt[j]=='G') t+=3;
t%=MOD;
b[i].push_back(t);
}
if(K<=50)
{
for(j=0;j<K;j++) for(k=0;k<K;k++) con[j][k][make_pair(a[i][j],b[i][k])]++;
a[i].clear();
b[i].clear();
}
}
while(M--)
{
ans=0;
scanf("%s %s",tt,tt2);
xx=strlen(tt);
yy=strlen(tt2);
t=0;
for(j=0;j<xx;j++)
{
t=(int) ( ((long long) t)*4%MOD);
if(tt[j]=='U') t++;
if(tt[j]=='C') t+=2;
if(tt[j]=='G') t+=3;
t%=MOD;
}
t2=0;
for(j=yy-1;j>=0;j--)
{
t2=(int) (((long long) t2)*4%MOD);
if(tt2[j]=='U') t2++;
if(tt2[j]=='C') t2+=2;
if(tt2[j]=='G') t2+=3;
t2%=MOD;
}
for(auto i:can)
{
if(sz[i]<xx||sz[i]<yy) continue;
if(a[i][xx-1]==t&&b[i][yy-1]==t2) ans++;
}
if(con[xx-1][yy-1].find(make_pair(t,t2))!=con[xx-1][yy-1].end()) ans+=con[xx-1][yy-1][make_pair(t,t2)];
printf("%d\n",ans);
}
return 0;
}
컴파일 시 표준 에러 (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... |