제출 #788046

#제출 시각아이디문제언어결과실행 시간메모리
788046Ahmed57Selling RNA Strands (JOI16_selling_rna)C++17
100 / 100
626 ms865720 KiB
#include<bits/stdc++.h> using namespace std; //TRIE struct node{ node *nxt[26]; int cnt = 0; node(){ cnt = 0; for(int i = 0;i<26;i++){ nxt[i] = NULL; } } }; struct node2{ node2 *nxt[26]; int ma = -1e9 , mi = 1e9; node2(){ ma = -1e9;mi = 1e9; for(int i = 0;i<26;i++){ nxt[i] = NULL; } } }; void inser(string w,node *root,node *nroot){ bool ss = 1; for(auto ch:w){ if(nroot->nxt[ch-'A']==NULL){ nroot->nxt[ch-'A'] = new node(); } if(ss){ nroot->cnt = root->cnt; for(int i = 0;i<26;i++){ if(root->nxt[i]==NULL)continue; if((ch-'A')!=i)nroot->nxt[i] = root->nxt[i]; } if(root->nxt[ch-'A']==NULL){ ss = 0; }else root = root->nxt[ch-'A']; } nroot-> cnt++; nroot = nroot->nxt[ch-'A']; } if(ss){ nroot->cnt = root->cnt; for(int i = 0;i<26;i++){ if(root->nxt[i]==NULL)continue; nroot->nxt[i] = root->nxt[i]; } } nroot-> cnt++; } void inser2(string w,int idx,node2 *root){ root->ma = max(root->ma,idx); root->mi = min(root->mi,idx); for(auto ch:w){ if(root->nxt[ch-'A']==NULL){ root->nxt[ch-'A'] = new node2(); } root = root->nxt[ch-'A']; root->ma = max(root->ma,idx); root->mi = min(root->mi,idx); } } void print(node *root){ for(int i = 0;i<26;i++){ if(root->nxt[i]==NULL)continue; cout<<char('A'+i)<<","<<root->nxt[i]->cnt<<" "; print(root->nxt[i]); } } node * version[100001]; int serach1(string w,node * r,node * l){ bool ss = 1; for(auto ch:w){ if(r->nxt[ch-'A']==NULL)return 0; r = r->nxt[ch-'A']; if(!ss)continue; if(l->nxt[ch-'A']==NULL){ ss = 0; continue; }else l = l->nxt[ch-'A']; } if(ss)return r->cnt-l->cnt; else return r->cnt; } int search2(string w,string lol,node2 * root){ for(auto ch:w){ if(root->nxt[ch-'A']==NULL){ return 0; } root = root->nxt[ch-'A']; } int l = root->mi ,r = root->ma; if(l>r)return 0; return serach1(lol,version[r],version[l-1]); } int main(){ int n,m; cin>>n>>m; vector<string> v; for(int i = 0;i<n;i++){ string s;cin>>s; v.push_back(s); } sort(v.begin(),v.end()); version[0] = new node(); node2 *root = new node2(); for(int i = 0;i<v.size();i++){ version[i+1] = new node(); string xd = v[i]; reverse(xd.begin(),xd.end()); inser(xd,version[i],version[i+1]); inser2(v[i],i+1,root); } while(m--){ string a,b; cin>>a>>b; reverse(b.begin(),b.end()); cout<<search2(a,b,root)<<endl; } }

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

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:108:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i = 0;i<v.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...