Task: | DNA sequence |
Sender: | eax511 |
Submission time: | 2016-10-22 13:42:36 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.38 s | details |
Compiler report
input/code.cpp: In function 'll rhash(std::string&)': input/code.cpp:11:32: warning: array subscript has type 'char' [-Wchar-subscripts] for(auto& c : v)h<<=2,h|=cm[c]; ^ input/code.cpp: In function 'void cnthash(std::string&, int)': input/code.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if(v.size()<l)return; ^ input/code.cpp:20:41: warning: array subscript has type 'char' [-Wchar-subscripts] for(int i=0;i<l;++i)hh<<=2,hh|=cm[v[i]]; ^ input/code.cpp:22:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i=l;i<v.size();++i){ ^ input/code.cpp:24:16: warning: array subscript has type 'char' [-Wchar-subscripts] hh|=cm[v[i]]; ^
Code
#include <set> #include <string> #include <iostream> #include <vector> using namespace std; typedef long long ll; set<ll> h[10]; int cm[256]; ll rhash(std::string& v){ ll h=0; for(auto& c : v)h<<=2,h|=cm[c]; return h; } void cnthash(std::string& v,int l){ if(v.size()<l)return; ll hh=0; ll m=1; m<<=l<<1; --m; for(int i=0;i<l;++i)hh<<=2,hh|=cm[v[i]]; h[l-1].emplace(hh); for(int i=l;i<v.size();++i){ hh<<=2; hh|=cm[v[i]]; hh&=m; h[l-1].emplace(hh); } } int main(){ cm['A']=0; cm['G']=1; cm['C']=2; cm['T']=3; string v; cin>>v; for(int i=0;i<10;++i)cnthash(v,i+1); int m; cin>>m; for(int i=0;i<m;++i)cin>>v,cout<<(h[v.size()-1].count(rhash(v))?"YES":"NO")<<'\n'; return 0; }