CSES - HIIT Open 2016 - Results
Submission details
Task:DNA sequence
Sender:Team Purkka
Submission time:2016-05-28 11:48:55 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.20 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:27:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j <= s.length() - i; j++) {
                                       ^

Code

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int calc_hash(const string &s, int off, int len) {
  int r=0;
  for(int i=off;i<off+len;i++){
    char c=s[i];
    if(c=='A')c=1;
    else if(c=='T')c=2;
    else if(c=='G')c=3;
    else c=4;
    r=r*5+c;
  }
  return r;
}

int v[10000000];

int main () {
  string s;
  cin>>s;
  int n;
  cin>>n;
  for (int i = 1; i <= min(10, (int)s.length()); i++) {
    for (int j = 0; j <= s.length() - i; j++) {
	v[calc_hash(s, j, i)] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
      string x;
      cin>>x;
      if (v[calc_hash(x,0,x.length())]) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
  }
}

Test details

Test 1

Verdict: ACCEPTED

input
ACGCGGGCTCCTAGCGTTAGCAGTTGAGTG...

correct output
YES
YES
NO
NO
YES
...

user output
YES
YES
NO
NO
YES
...