CSES - E4590 2016 6 - Results
Submission details
Task:DNA sequence
Sender:Ollie
Submission time:2016-10-22 14:23:23 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.76 sdetails

Code

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie();
#define ll long long
using namespace std;

#define A 124123423
#define B 283412834
#define C 582428341

map<ll, bool> hm;
map<ll, bool> hm2;

int main() { _
  string s;
  cin >> s;
  int n = s.length();
  for(int l=0;l<10;l++) {
    for(int i=0;i+l<n;i++) {
      ll h = 0, h2 = 0;
      for(int j=i;j<=i+l;j++) {
        h += s[j];
        h *= A;
        h %= B;
        h2 += s[j];
        h2 *= C;
        h2 %= B;
      }
      hm[h]=true;
      hm[h2]=true;
    }
  }
  int l; cin >> l;
  for(int i=0;i<l;i++) {
    string q;
    cin >> q;
    ll h = 0, h2=0;
    for(auto c : q) {
      h += c;
      h *= A;
      h %= B;
      h2 += c;
      h2 *= C;
      h2 %= B;
    }
    cout<<(hm[h]&&hm[h2]?"YES":"NO")<<endl;
  }
  return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
ACGCGGGCTCCTAGCGTTAGCAGTTGAGTG...

correct output
YES
YES
NO
NO
YES
...

user output
YES
YES
NO
NO
YES
...