Submission #101159

# Submission time Handle Problem Language Result Execution time Memory
101159 2019-03-17T06:59:49 Z autumn_eel Selling RNA Strands (JOI16_selling_rna) C++14
0 / 100
146 ms 50464 KB
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;

ll B=10007;
ll mul[200000];
struct rolling_hash{
	vector<ull>hsh;
	rolling_hash(){}
	rolling_hash(string&s){
		hsh=vector<ull>(s.size()+1);
		for(int i=1;i<=s.size();i++){
			hsh[i]=hsh[i-1]*B+s[i-1];
		}
	}
	ull get(){
		return hsh.back();
	}
	ull get(int l,int r){//[l,r)
		return hsh[r]-hsh[l]*mul[r-l];
	}
};

ll get_hash(string&s){
	ll res=0;
	for(char c:s){
		res=res*B+c;
	}
	return res;
}

char S[200000];
string s[200000],p[200000],q[200000];
rolling_hash rh[200000];

int main(){
	mul[0]=1;
	for(int i=1;i<200000;i++){
		mul[i]=(mul[i-1]*B)%MOD;
	}
	int n,m;scanf("%d%d",&n,&m);
	if(n>5000||m>5000)abort();
	rep(i,n){
		scanf("%s",S);
		s[i]=S;
		rh[i]=rolling_hash(s[i]);
	}
	rep(i,m){
		scanf("%s",S);p[i]=S;
		scanf("%s",S);q[i]=S;
		ll a=get_hash(p[i]),b=get_hash(q[i]);
		int cnt=0;
		rep(j,n){
			if(p[i].size()>s[j].size()||q[i].size()>s[j].size())continue;
			if(rh[j].get(0,p[i].size())==a&&
				rh[j].get(s[j].size()-q[i].size(),s[j].size())==b)cnt++;
		}
		printf("%d\n",cnt);
	}
}

Compilation message

selling_rna.cpp: In constructor 'rolling_hash::rolling_hash(std::__cxx11::string&)':
selling_rna.cpp:16:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1;i<=s.size();i++){
               ~^~~~~~~~~~
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:59:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(rh[j].get(0,p[i].size())==a&&
       ~~~~~~~~~~~~~~~~~~~~~~~~^~~
selling_rna.cpp:60:51: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     rh[j].get(s[j].size()-q[i].size(),s[j].size())==b)cnt++;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
selling_rna.cpp:45:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n,m;scanf("%d%d",&n,&m);
          ~~~~~^~~~~~~~~~~~~~
selling_rna.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",S);
   ~~~~~^~~~~~~~
selling_rna.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",S);p[i]=S;
   ~~~~~^~~~~~~~
selling_rna.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",S);q[i]=S;
   ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 25464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 45048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 50464 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 25464 KB Output isn't correct
2 Halted 0 ms 0 KB -