# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1034692 | baotoan655 | Selling RNA Strands (JOI16_selling_rna) | C++17 | 1585 ms | 377668 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define REV(i, b, a) for(int i = (b); i >= (a); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define fi first
#define se second
using namespace std;
set<int> empty_set;
int n, q;
int num[26];
struct trie {
struct node {
node* con[4];
set<int> se;
node() {
for(int i = 0; i < 4; ++i) con[i] = NULL;
se.clear();
};
};
node* root;
trie() {
root = new node();
};
void add_string(const string &s, int id) {
node* pos = root;
for(char ch : s) {
int c = num[ch - 'A'];
if(pos->con[c] == NULL) pos->con[c] = new node();
pos = pos->con[c];
pos->se.insert(id);
}
};
set<int> get(const string &s) {
node* pos = root;
for(char ch : s) {
int c = num[ch - 'A'];
if(pos->con[c] == NULL) return empty_set;
pos = pos->con[c];
}
return pos->se;
}
} tr1, tr2;
void solve(int tc) {
num['A' - 'A'] = 0;
num['U' - 'A'] = 1;
num['G' - 'A'] = 2;
num['C' - 'A'] = 3;
cin >> n >> q;
string str;
FOR(i, 1, n) {
cin >> str;
tr1.add_string(str, i);
reverse(str.begin(), str.end());
tr2.add_string(str, i);
}
while(q--) {
string s1, s2;
cin >> s1 >> s2;
reverse(s2.begin(), s2.end());
set<int> se1 = tr1.get(s1);
set<int> se2 = tr2.get(s2);
int ans = 0;
for(int x : se1) {
if(se2.find(x) != se2.end()) ++ans;
}
cout << ans << '\n';
}
return;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
file("A");
int tc = 1;
// cin >> tc;
for(int i = 1; i <= tc; ++i) solve(tc);
return (0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |