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

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

Test details

Test 1

Verdict: ACCEPTED

input
ACGCGGGCTCCTAGCGTTAGCAGTTGAGTG...

correct output
YES
YES
NO
NO
YES
...

user output
YES
YES
NO
NO
YES
...