Submission #92824

#TimeUsernameProblemLanguageResultExecution timeMemory
92824LittleFlowers__Selling RNA Strands (JOI16_selling_rna)C++14
10 / 100
1593 ms210552 KiB
#include <bits/stdc++.h> using namespace std; const int N=2000010; int n,m,G,Il,Ir; int Tl[N][4],Tr[N][4]; vector<int> Fl[N],Fr[N]; string s; void add(int i) { cin>>s; for(auto & c : s) { if(c=='G') c='B'; if(c=='U') c='D'; } G=0; for(auto & c : s) { if(!Tl[G][c-'A']) Tl[G][c-'A']=++Il; G=Tl[G][c-'A']; Fl[G].push_back(i); } reverse(s.begin(),s.end()); G=0; for(auto & c : s) { if(!Tr[G][c-'A']) Tr[G][c-'A']=++Ir; G=Tr[G][c-'A']; Fr[G].push_back(i); } } void get() { vector<int> A; G=0; cin>>s; for(auto & c : s) { if(c=='G') c='B'; if(c=='U') c='D'; } for(auto & c : s) { G=Tl[G][c-'A']; if(!G) break; } A.insert(A.end(),Fl[G].begin(),Fl[G].end()); G=0; cin>>s; for(auto & c : s) { if(c=='G') c='B'; if(c=='U') c='D'; } reverse(s.begin(),s.end()); for(auto & c : s) { G=Tr[G][c-'A']; if(!G) break; } A.insert(A.end(),Fr[G].begin(),Fr[G].end()); sort(A.begin(),A.end()); int ans=0; for(int i=0; i<(int)A.size()-1; ++i) ans+=A[i]==A[i+1]; cout<<ans<<"\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("RNA.inp","r",stdin); cin>>n>>m; for(int i=0; i<n; ++i) add(i); for(int i=0; i<m; ++i) get(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...