답안 #549011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549011 2022-04-15T00:34:57 Z colossal_pepe Selling RNA Strands (JOI16_selling_rna) C++17
10 / 100
1221 ms 1048576 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <unordered_map>
using namespace std;

unordered_map<char, int> id = {{'A', 0}, {'G', 1}, {'C', 2}, {'U', 3}};

struct Node {
    int children[4];
    bitset<5000> members;
    Node() {
        memset(children, -1, sizeof(children));
        members.reset();
    }
};

struct Trie {
    vector<Node> trie;
    Trie() {
        trie = {Node()};
    }
    void insert(const string& s, int x) {
        int node = 0, sz = s.size();
        for (int i = 0; i < sz; i++) {
            trie[node].members[x] = 1;
            if (trie[node].children[id[s[i]]] == -1) {
                trie[node].children[id[s[i]]] = trie.size();
                trie.push_back(Node());
            }
            node = trie[node].children[id[s[i]]];
        }
        trie[node].members[x] = 1;
    }
    bitset<5000> getMembers(const string& s) {
        int node = 0, sz = s.size();
        for (int i = 0; i < sz; i++) {
            if (trie[node].children[id[s[i]]] == -1) return bitset<5000>();
            node = trie[node].children[id[s[i]]];
        }
        return trie[node].members;
    }
};

int n, q;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    Trie trie_pref = Trie();
    Trie trie_suf = Trie();
    cin >> n >> q;
    while (n--) {
        string s;
        cin >> s;
        trie_pref.insert(s, n);
        reverse(s.begin(), s.end());
        trie_suf.insert(s, n);
    }
    while (q--) {
        string pref, suf;
        cin >> pref >> suf;
        bitset<5000> members = trie_pref.getMembers(pref);
        reverse(suf.begin(), suf.end());
        members &= trie_suf.getMembers(suf);
        cout << members.count() << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1221 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Runtime error 1221 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -