Submission #562988

# Submission time Handle Problem Language Result Execution time Memory
562988 2022-05-16T03:04:44 Z KoD Selling RNA Strands (JOI16_selling_rna) C++17
100 / 100
526 ms 143668 KB
#include <bits/stdc++.h>
using namespace std;

struct TrieNode {
    array<int, 4> child;
    vector<int> indices;
    TrieNode() { child.fill(-1); }
};

const string letters = "AGCU";

int main() {
    vector<TrieNode> node = {TrieNode()};
    const auto get_path = [&](const string& word) {
        int cur = 0;
        vector<int> path;
        for (const char c : word) {
            for (int k = 0; k < 4; ++k) {
                if (letters[k] == c) {
                    if (node[cur].child[k] == -1) {
                        node[cur].child[k] = size(node);
                        node.push_back(TrieNode());
                    }
                    cur = node[cur].child[k];
                    break;
                }
            }
            path.push_back(cur);
        }
        return path;
    };

    int N, M;
    cin >> N >> M;
    vector<string> S(N);
    for (auto& x : S) {
        cin >> x;
        reverse(begin(x), end(x));
    }
    sort(begin(S), end(S));
    for (int i = 0; i < N; ++i) {
        for (const int u : get_path(string(rbegin(S[i]), rend(S[i])))) {
            node[u].indices.push_back(i);
        }
    }

    while (M--) {
        string P, Q;
        cin >> P >> Q;
        reverse(begin(Q), end(Q));
        const auto& list = node[get_path(P).back()].indices;
        const auto get = [&](const int k) {
            return string(begin(S[k]), begin(S[k]) + min(size(S[k]), size(Q)));
        };
        const auto lowb =
            partition_point(begin(list), end(list), [&](const int k) { return Q > get(k); });
        const auto upb =
            partition_point(begin(list), end(list), [&](const int k) { return Q >= get(k); });
        cout << upb - lowb << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 19312 KB Output is correct
2 Correct 162 ms 18344 KB Output is correct
3 Correct 299 ms 143668 KB Output is correct
4 Correct 298 ms 137000 KB Output is correct
5 Correct 231 ms 118616 KB Output is correct
6 Correct 226 ms 118580 KB Output is correct
7 Correct 182 ms 16340 KB Output is correct
8 Correct 296 ms 65160 KB Output is correct
9 Correct 266 ms 65728 KB Output is correct
10 Correct 206 ms 67768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 3156 KB Output is correct
2 Correct 90 ms 2268 KB Output is correct
3 Correct 142 ms 2804 KB Output is correct
4 Correct 87 ms 2352 KB Output is correct
5 Correct 83 ms 2392 KB Output is correct
6 Correct 115 ms 2804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 159 ms 19312 KB Output is correct
9 Correct 162 ms 18344 KB Output is correct
10 Correct 299 ms 143668 KB Output is correct
11 Correct 298 ms 137000 KB Output is correct
12 Correct 231 ms 118616 KB Output is correct
13 Correct 226 ms 118580 KB Output is correct
14 Correct 182 ms 16340 KB Output is correct
15 Correct 296 ms 65160 KB Output is correct
16 Correct 266 ms 65728 KB Output is correct
17 Correct 206 ms 67768 KB Output is correct
18 Correct 122 ms 3156 KB Output is correct
19 Correct 90 ms 2268 KB Output is correct
20 Correct 142 ms 2804 KB Output is correct
21 Correct 87 ms 2352 KB Output is correct
22 Correct 83 ms 2392 KB Output is correct
23 Correct 115 ms 2804 KB Output is correct
24 Correct 209 ms 18464 KB Output is correct
25 Correct 288 ms 18816 KB Output is correct
26 Correct 187 ms 18240 KB Output is correct
27 Correct 353 ms 120900 KB Output is correct
28 Correct 526 ms 21228 KB Output is correct
29 Correct 345 ms 11992 KB Output is correct