Submission #633180

#TimeUsernameProblemLanguageResultExecution timeMemory
633180IwanttobreakfreeSelling RNA Strands (JOI16_selling_rna)C++17
10 / 100
1587 ms42168 KiB
#include <iostream> #include <vector> using namespace std; #define int long long #define pii pair<int,int> const int mod=1e9+7,t=70,mod2=1e9+9,sz=101; vector<vector<int>> pre_hash; vector<int> pre; int get_hash(int a,int sz,int i){ int ans=(pre_hash[i][a+sz]-1ll*pre_hash[i][a]*pre[sz])%mod; if(ans<0)ans+=mod; return ans; } signed main(){ int n,m; cin>>n>>m; string s,st; pre_hash=vector<vector<int>> (n,vector<int>(sz)); pre=vector<int> (sz); pre[0]=1; vector<int> siz(n); for(int i=1;i<sz;i++)pre[i]=(pre[i-1]*t)%mod; for(int i=0;i<n;i++){ cin>>s; siz[i]=s.size(); for(int j=0;j<s.size();j++){ pre_hash[i][j+1]=(pre_hash[i][j]*t+s[j]-'A'+1)%mod; } } /*for(int i=0;i<n;i++){ for(int j=0;j<=siz[i];j++)cout<<pre_hash[i][j]<<' '; cout<<'\n'; }*/ while(m--){ cin>>s>>st; int hash1=0,hash2=0; for(int i=0;i<s.size();i++){ hash1=(hash1*t+s[i]-'A'+1)%mod; } for(int i=0;i<st.size();i++){ hash2=(hash2*t+st[i]-'A'+1)%mod; } //cout<<hash1<<' '<<hash2<<'\n'; int ans=0; for(int i=0;i<n;i++){ if(siz[i]>=max(s.size(),st.size())&&hash1==get_hash(0,s.size(),i)&&hash2==get_hash(siz[i]-st.size(),st.size(),i))ans++; } cout<<ans<<'\n'; } }

Compilation message (stderr)

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:26:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for(int j=0;j<s.size();j++){
      |                     ~^~~~~~~~~
selling_rna.cpp:37:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int i=0;i<s.size();i++){
      |                     ~^~~~~~~~~
selling_rna.cpp:40:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i=0;i<st.size();i++){
      |                     ~^~~~~~~~~~
selling_rna.cpp:46:22: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'const long unsigned int' [-Wsign-compare]
   46 |             if(siz[i]>=max(s.size(),st.size())&&hash1==get_hash(0,s.size(),i)&&hash2==get_hash(siz[i]-st.size(),st.size(),i))ans++;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...