Submission #549011

#TimeUsernameProblemLanguageResultExecution timeMemory
549011colossal_pepeSelling RNA Strands (JOI16_selling_rna)C++17
10 / 100
1221 ms1048576 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...