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:55:23
Task:DNA sequence
Sender:Noname 01
Submission time:2016-05-28 11:55:23
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;


string s;

vector<int> ans[11];
int n;

void Load()
{
	cin >> s;
	n = s.length();
}


int Encode(string &s, int l, int r) {
	int ans = 0;
	for (int i = l; i < r; i++) {
		ans *= 4;
		if (s[i] == 'A') ans += 0;
		if (s[i] == 'T') ans += 1;
		if (s[i] == 'G') ans += 2;
		if (s[i] == 'C') ans += 3;
	}
	return ans;
}

void Solve() {
	int i, j;
	for (i = 1; i <= 10; i++) {
		ans[i].resize(1 << (2*i));
		for (j = 0; j < n - i; j++) {
		  ans[i][Encode(s, j, j+i)] = 1;
		}
	}
	cin >> j;
	for (i = 0; i < j; i++) {
		string ss;
		cin >> ss;
		int k = ss.length();
		if (ans[k][Encode(ss, 0, k)])
			cout << "YES\n";
		else
		  cout << "NO\n";
	}
}

int main(){
 Load(); 
 Solve();
 return 0;
}