# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
933055 | 2024-02-25T00:03:52 Z | vjudge1 | Selling RNA Strands (JOI16_selling_rna) | C++17 | 1500 ms | 1048576 KB |
#include <bits/stdc++.h> #define range(it, a, b) for (ll it = a; it < b; it++) #define all(x) begin(x), end(x) #define ll long long #define ull unsigned long long #define INF64 ((ll) 1 << 60) #define INF32 (1 << 30) #define mset multiset #define uset unordered_set #define umap unordered_map #define pqueue priority_queue #define ptr(A) shared_ptr<A> using namespace std; void setio (string name) { ios_base::sync_with_stdio(0); cin.tie(0); if (name.size()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } struct Trie { struct Node { ptr(Node) child[26]; set<ll> pre, suf; }; ptr(Node) root = ptr(Node) (new Node); void add(string& s, bool rev, ll i) { ptr(Node) node = root; if (rev) { for (auto it = s.rbegin(); it != s.rend(); it++) { if (!node->child[*it - 'A']) node->child[*it - 'A'] = ptr(Node) (new Node); node->child[*it - 'A']->suf.insert(i); node = node->child[*it - 'A']; } return; } for (auto it = s.begin(); it != s.end(); it++) { if (!node->child[*it - 'A']) node->child[*it - 'A'] = ptr(Node) (new Node); node->child[*it - 'A']->pre.insert(i); node = node->child[*it - 'A']; } } set<ll> get(string& s, bool rev) { ptr(Node) node = root; if (rev) { for (auto it = s.rbegin(); it != s.rend(); it++) { if (!node->child[*it - 'A']) return set<ll>(); node = node->child[*it - 'A']; } return node->suf; } for (auto it = s.begin(); it != s.end(); it++) { if (!node->child[*it - 'A']) return set<ll>(); node = node->child[*it - 'A']; } return node->pre; } }; ll sunion (set<ll> a, set<ll> b) { ll cnt = 0; for (const ll& it : a) { if (b.count(it)) cnt++; } return cnt; } ll n, m; string s, t; void solve() { cin >> n >> m; Trie tr; range(i, 0, n) { cin >> s; tr.add(s, 0, i); tr.add(s, 1, i); } while (m--) { cin >> s >> t; cout << sunion(tr.get(s, 0), tr.get(t, 1)) << '\n'; } } int main () { setio(""); ll t = 1; // cin >> t; while (t--) solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 756 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 739 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1553 ms | 12116 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 756 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Runtime error | 739 ms | 1048576 KB | Execution killed with signal 9 |
9 | Halted | 0 ms | 0 KB | - |