CSES - E4590 2016 6 - Results
Submission details
Task:DNA sequence
Sender:ivan
Submission time:2016-10-22 13:16:07 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.45 sdetails

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:16:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); ++i) {
                                ^
input/code.cpp:19:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (i + j >= s.size())
                                 ^

Code

#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

string s;
unordered_set<string> table;

int main(int argc, char *argv[])
{
    cin >> s;
    int n = 0;
    cin >> n;

    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < 10; ++j) {
            // [i..i+j]
            if (i + j >= s.size())
                break;

            string t = s.substr(i, j + 1);
            table.insert(t);
        }
    }

    for (int i = 0; i < n; ++i) {
        string t;
        cin >> t;

        if (table.find(t) == table.end()) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }


    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
ACGCGGGCTCCTAGCGTTAGCAGTTGAGTG...

correct output
YES
YES
NO
NO
YES
...

user output
YES
YES
NO
NO
YES
...