CSES - Practice Contest 2024 - Results
Submission details
Task:DNA sequence
Sender:asdf
Submission time:2024-09-28 13:54:33 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.17 sdetails

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:65:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int i = 1; i < s.size(); i++) {
      |                         ~~^~~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

string to_string(string s) {
    return '"' + s + '"';
}
 
string to_string(const char* s) {
    return to_string((string) s);
}
 
string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
 
void debug_out() {
    cerr << endl;
}
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;

string s;
unordered_set<string> st[11];
    
void solve() {
    cin >> s;

    for (int len = 1; len <= 10; len++) {
        auto& cur = st[len];
        string tmp = s.substr(0, len);
        cur.insert(tmp);
        for (int i = 1; i < s.size(); i++) {
            tmp.erase(0, 1);
            tmp += s[i];
            cur.insert(tmp);
        }
    }

    int q;
    cin >> q;

    while (q--) {
        string ss;
        cin >> ss;
        bool found = st[ss.size()].count(ss);
        cout << (found ? "YES\n" : "NO\n"); 
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
ACGCGGGCTCCTAGCGTTAGCAGTTGAGTG...

correct output
YES
YES
NO
NO
YES
...

user output
YES
YES
NO
NO
YES
...
Truncated