Submission details
Task:DNA sequence
Sender:team_a
Submission time:2020-10-03 15:12:13 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.24 sdetails

Compiler report

input/code.cpp: In function 'int getH(std::__cxx11::string)':
input/code.cpp:25:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < s.size(); j++) {
                    ~~^~~~~~~~~~

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void gen(int *hs, string s) {
    int n = s.size();
    for (int i = 0; i < n; i++) {
        int h = 0;
        for(int j = 0; j < 10; j++) {
            if(i + j < n) {
                h = h + s[i + j];
                h *= 26;
            }
            hs[10*i + j] = h;
        }
    }
    sort(hs, hs + 10*n);
}

int getH(string s) {
    int h = 0;
    for(int j = 0; j < s.size(); j++) {
        h = h + s[j];
        h *= 26;
    }
    return h;
}

int contains(int *hs, int n, int h) {
    int a = 0;
    int b = n - 1;
    while(a < b) {
        int m = (b - a)/2 + a;
        if (hs[m] == h || hs[a] == h || hs[b] == h) return 1;
        else if (hs[m] < h) a = m + 1;
        else b = m - 1;
    }
    return (hs[a] == h);
}

int main() {
    std::string n;
    int q;
    cin >> n;

    int m = 10 * n.size();

    int *hs = new int[m];
    gen(hs, n);

    cin >> q;
    for(int i = 0; i < q; i++) {
        std::string s;
        cin >> s;
        if (contains(hs, m, getH(s)))
            cout << "YES" << endl;
        else 
            cout << "NO" << endl;
    }

    return 0;
}

Test details

Test 1

Verdict:

input
ACGCGGGCTCCTAGCGTTAGCAGTTGAGTG...

correct output
YES
YES
NO
NO
YES
...

user output
YES
YES
NO
NO
YES
...