Submission #866798

#TimeUsernameProblemLanguageResultExecution timeMemory
866798haraoSelling RNA Strands (JOI16_selling_rna)C++17
35 / 100
630 ms252484 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5e3+7; const int M = 2e5+7; const int base = 33; const int mod = 1e9+7; using ll = long long; string s[N]; ll ha1[N][N],ha2[N][N],h[N]; int n,m; ll get1(int i, int l, int r) { return (ha1[i][r] - ha1[i][l-1]*h[r-l+1] + 1ll*mod*mod)%mod; } ll get2(int i, int l, int r) { return (ha2[i][r] - ha2[i][l-1]*h[r-l+1] + 1ll*mod*mod)%mod; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; int max_len = 0; for(int i = 1; i <= n; i++) { cin>>s[i]; max_len = max(max_len,(int)s[i].size()); } for(int i = 1; i <= n; i++) { ha1[i][0] = 0; string st = s[i]; int sz = s[i].size(); s[i] = " " + s[i]; reverse(st.begin(),st.end()); st = " " + st; for(int j = 1; j <= sz; j++) { ha1[i][j] = (ha1[i][j-1]*base + s[i][j])%mod; ha2[i][j] = (ha2[i][j-1]*base + st[j])%mod; } } h[0] = 1; for(int i = 1; i <= max_len; i++) { h[i] = (h[i-1]*base)%mod; } for(int i = 1; i <= m; i++) { string s1,s2; cin>>s1>>s2; int sz1 = s1.size(), sz2 = s2.size(); reverse(s2.begin(),s2.end()); s1 = " " + s1, s2 = " " + s2; ll ha1 = 0, ha2 = 0; for(int j = 1; j <= sz1; j++) { ha1 = (ha1*1ll*base + s1[j])%mod; } for(int j = 1; j <= sz2; j++) { ha2 = (ha2*1ll*base + s2[j])%mod; } int cnt = 0; for(int i1 = 1; i1 <= n; i1++) { int sz = s[i1].size() - 1; if(get1(i1,1,sz1) == ha1 && get2(i1,1,sz2) == ha2) cnt++; } cout<<cnt<<"\n"; } return 0; }

Compilation message (stderr)

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:79:17: warning: unused variable 'sz' [-Wunused-variable]
   79 |             int sz = s[i1].size() - 1;
      |                 ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...