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

Code

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  string s;
  cin >> s;
  
  
  int n = s.length();
  int q;
  cin >> q;
  
  unordered_set<ll> hashes;
  
  for (int i = 1; i <= 10; ++i) {
    for (int j = 0; j < n - i; ++j) {
      int x = 1;
      int v = 0;
      for (int k = j; k < j+i; ++k) {
	if (s[k] == 'A')
	  v += x*1;
	else if (s[k] == 'C')
	  v += x*2;
	else if (s[k] == 'G')
	  v += x*3;
	else
	  v += x*4;
	x *= 10;
      }
      hashes.insert(v);
    }
  }
  
  for (int i = 0; i < q; ++i) {
    string t;
    cin >> t;
    int m = t.length();
    int v = 0;
    int x = 1;
    for (int k = 0; k < m; ++k) {
      if (t[k] == 'A')
	v += x*1;
      else if (t[k] == 'C')
	v += x*2;
      else if (t[k] == 'G')
	v += x*3;
      else
	v += x*4;
      x *= 10;
    }
    if (hashes.count(v))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  
  
}

Test details

Test 1

Verdict: ACCEPTED

input
ACGCGGGCTCCTAGCGTTAGCAGTTGAGTG...

correct output
YES
YES
NO
NO
YES
...

user output
YES
YES
NO
NO
YES
...