Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 11:15:55
Task:DNA sequence
Sender:Anonyymit Algoritmistit
Submission time:2016-05-28 11:15:55
Status:READY
Result:ACCEPTED

Show test data

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";
  }
  
  
}