Submission #580874

#TimeUsernameProblemLanguageResultExecution timeMemory
580874Jarif_RahmanSelling RNA Strands (JOI16_selling_rna)C++17
35 / 100
1592 ms170588 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const int sq = 400; const int A = 976186659; const ll B = 988144425; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> pref, suff; unordered_map<ll, int> mp; for(int i = 0; i < n; i++){ str s; cin >> s; if(s.size() < sq){ int h = 0; for(int j = 0; j < s.size(); j++){ h = (ll(h)*A)%B; h = (ll(h)+s[j])%B; int hh = 0, p = 1; for(int k = int(s.size())-1; k >= 0; k--){ hh = (ll(p)*s[k]+hh)%B; p = (ll(p)*A)%B; mp[ll(1e9)*h+hh]++; } } } else{ pref.pb(vector<int>(s.size())), suff.pb(vector<int>(s.size())); int h = 0; for(int j = 0; j < s.size(); j++){ h = (ll(h)*A)%B; h = (ll(h)+s[j])%B; pref.back()[j] = h; } h = 0; int p = 1; for(int j = int(s.size())-1; j >= 0; j--){ h = (ll(p)*s[j]+h)%B; p = (ll(p)*A)%B; suff.back()[j] = h; } } } while(m--){ str p, q; cin >> p >> q; int h1 = 0, h2 = 0; for(int i = 0; i < p.size(); i++) h1 = (ll(h1)*A)%B, h1 = (ll(h1)+p[i])%B; for(int i = 0; i < q.size(); i++) h2 = (ll(h2)*A)%B, h2 = (ll(h2)+q[i])%B; int ans = mp[ll(1e9)*h1+h2]; int psz = p.size(), qsz = q.size(); for(int i = 0; i < pref.size(); i++){ int sz = pref[i].size(); if(max(psz, qsz) <= sz && pref[i][psz-1] == h1 && suff[i][sz-qsz] == h2) ans++; } cout << ans << "\n"; } }

Compilation message (stderr)

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:27:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             for(int j = 0; j < s.size(); j++){
      |                            ~~^~~~~~~~~~
selling_rna.cpp:41:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             for(int j = 0; j < s.size(); j++){
      |                            ~~^~~~~~~~~~
selling_rna.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int i = 0; i < p.size(); i++) h1 = (ll(h1)*A)%B, h1 = (ll(h1)+p[i])%B;
      |                        ~~^~~~~~~~~~
selling_rna.cpp:59:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int i = 0; i < q.size(); i++) h2 = (ll(h2)*A)%B, h2 = (ll(h2)+q[i])%B;
      |                        ~~^~~~~~~~~~
selling_rna.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int i = 0; i < pref.size(); i++){
      |                        ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...