제출 #848985

#제출 시각아이디문제언어결과실행 시간메모리
848985alexddSelling RNA Strands (JOI16_selling_rna)C++17
35 / 100
1526 ms343992 KiB
#include<bits/stdc++.h> using namespace std; const long long MOD = 1e9+7; const int cst = 31; int n,m; vector<int> trie[2000005]; int mch[2000005][26]; int rez[100005]; int cnt; vector<int> suffs[2000005]; vector<pair<int,int>> qrys[2000005]; map<int,int> fr[2000005]; void dfs(int nod) { int heavy=-1,maxc=-1; for(auto adj:trie[nod]) { dfs(adj); if((int)fr[adj].size()>maxc) maxc=fr[adj].size(),heavy=adj; } if(heavy!=-1) { swap(fr[nod],fr[heavy]); for(auto adj:trie[nod]) if(adj!=heavy) { for(auto it:fr[adj]) fr[nod][it.first]+=it.second; fr[adj].clear(); } } for(auto x:suffs[nod]) fr[nod][x]++; for(auto x:qrys[nod]) { rez[x.second] = fr[nod][x.first]; } } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; string s,p,q; for(int i=1;i<=n;i++) { cin>>s; int nod=0; for(int j=0;j<s.size();j++) { if(mch[nod][s[j]-'A']==0) { cnt++; mch[nod][s[j]-'A']=cnt; trie[nod].push_back(cnt); } nod=mch[nod][s[j]-'A']; } int curaux=0,curp=1; for(int j=s.size()-1;j>=0;j--) { curaux = (curaux + (1LL*curp*(s[j]-'A'+1)%MOD))%MOD; curp=(curp*cst)%MOD; suffs[nod].push_back(curaux); } } for(int i=1;i<=m;i++) { cin>>p>>q; int nod=0; bool bl=0; for(int j=0;j<p.size();j++) { if(mch[nod][p[j]-'A']==0) { bl=1; break; } nod=mch[nod][p[j]-'A']; } if(!bl) { int curaux=0,curp=1; for(int j=q.size()-1;j>=0;j--) { curaux = (curaux + (1LL*curp*(q[j]-'A'+1)%MOD))%MOD; curp=(curp*cst)%MOD; } qrys[nod].push_back({curaux,i}); } } dfs(0); for(int i=1;i<=m;i++) cout<<rez[i]<<"\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j=0;j<s.size();j++)
      |                     ~^~~~~~~~~
selling_rna.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for(int j=0;j<p.size();j++)
      |                     ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...