Submission #332718

# Submission time Handle Problem Language Result Execution time Memory
332718 2020-12-03T04:11:59 Z daniel920712 Selling RNA Strands (JOI16_selling_rna) C++14
60 / 100
1500 ms 29420 KB
#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[105][105];
char tt[100005];
char tt2[100005];
int sz[100005];
int big=40;
bool have[105][105]={0};
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>big) 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);
        }




    }
    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(xx<=big&&yy<=big)
        {
            if(!have[xx][yy])
            {
                have[xx][yy]=1;
                for(i=0;i<N;i++)
                {
                    if(sz[i]>big||xx>sz[i]||yy>sz[i]) continue;
                    con[xx-1][yy-1][make_pair(a[i][xx-1],b[i][yy-1])]++;
                }
            }
            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;
}

Compilation message

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:21:23: warning: unused variable 'k' [-Wunused-variable]
   21 |     int N,M,K,t=0,i,j,k,t2,xx,yy,ans;
      |                       ^
selling_rna.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
selling_rna.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |         scanf("%s",tt);
      |         ~~~~~^~~~~~~~~
selling_rna.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |         scanf("%s %s",tt,tt2);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5612 KB Output is correct
2 Correct 4 ms 5612 KB Output is correct
3 Correct 4 ms 5612 KB Output is correct
4 Correct 4 ms 5612 KB Output is correct
5 Correct 4 ms 5612 KB Output is correct
6 Correct 4 ms 5612 KB Output is correct
7 Correct 4 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 26860 KB Output is correct
2 Correct 368 ms 28652 KB Output is correct
3 Correct 251 ms 27884 KB Output is correct
4 Correct 296 ms 28524 KB Output is correct
5 Correct 330 ms 25324 KB Output is correct
6 Correct 324 ms 25236 KB Output is correct
7 Correct 248 ms 22636 KB Output is correct
8 Correct 425 ms 25964 KB Output is correct
9 Correct 389 ms 25868 KB Output is correct
10 Correct 454 ms 26092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 9196 KB Output is correct
2 Correct 43 ms 8428 KB Output is correct
3 Correct 47 ms 8940 KB Output is correct
4 Correct 28 ms 7916 KB Output is correct
5 Correct 43 ms 8428 KB Output is correct
6 Correct 52 ms 8908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5612 KB Output is correct
2 Correct 4 ms 5612 KB Output is correct
3 Correct 4 ms 5612 KB Output is correct
4 Correct 4 ms 5612 KB Output is correct
5 Correct 4 ms 5612 KB Output is correct
6 Correct 4 ms 5612 KB Output is correct
7 Correct 4 ms 5612 KB Output is correct
8 Correct 162 ms 26860 KB Output is correct
9 Correct 368 ms 28652 KB Output is correct
10 Correct 251 ms 27884 KB Output is correct
11 Correct 296 ms 28524 KB Output is correct
12 Correct 330 ms 25324 KB Output is correct
13 Correct 324 ms 25236 KB Output is correct
14 Correct 248 ms 22636 KB Output is correct
15 Correct 425 ms 25964 KB Output is correct
16 Correct 389 ms 25868 KB Output is correct
17 Correct 454 ms 26092 KB Output is correct
18 Correct 35 ms 9196 KB Output is correct
19 Correct 43 ms 8428 KB Output is correct
20 Correct 47 ms 8940 KB Output is correct
21 Correct 28 ms 7916 KB Output is correct
22 Correct 43 ms 8428 KB Output is correct
23 Correct 52 ms 8908 KB Output is correct
24 Execution timed out 1591 ms 29420 KB Time limit exceeded
25 Halted 0 ms 0 KB -