# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170813 | ZwariowanyMarcin | Selling RNA Strands (JOI16_selling_rna) | C++14 | 496 ms | 214644 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 fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
using namespace std;
int n, m;
string s;
vector <string> v;
char S[100005];
int L;
map <char, int> g;
struct trie {
vector <int> v[2000111];
int cnt = 1;
int go[2000111][4];
void add(string &x, int ind) {
int node = 0;
for(int i = 0; i < ss(x); ++i) {
if(go[node][g[x[i]]] == 0)
go[node][g[x[i]]] = cnt++;
node = go[node][g[x[i]]];
v[node].pb(ind);
}
}
pair<int,int> q1(string &x) {
int node = 0;
for(int i = 0; i < ss(x); ++i) {
node = go[node][g[x[i]]];
if(!node) return {-1, -1};
}
return {v[node][0], v[node].back()};
}
int q2(int L, int R, string &x) {
int node = 0;
for(int i = 0; i < ss(x); ++i) {
node = go[node][g[x[i]]];
if(!node) return 0;
}
return (int) (upper_bound(v[node].begin(), v[node].end(), R) - lower_bound(v[node].begin(), v[node].end(), L));
}
} ja, on;
int main() {
g['A'] = 0;
g['C'] = 1;
g['G'] = 2;
g['U'] = 3;
scanf("%d %d", &n, &m);
FOR(i, n) {
scanf("%s", S);
L = strlen(S);
s = "";
for(int j = 0; j < L; ++j)
s.pb(S[j]);
v.pb(s);
}
sort(v.begin(), v.end());
FOR(i, n) {
s = v[i];
ja.add(s, i);
reverse(s.begin(), s.end());
on.add(s, i);
}
FOR(i, m) {
scanf("%s", S);
L = strlen(S);
s = "";
for(int j = 0; j < L; ++j)
s.pb(S[j]);
pair<int, int> w = ja.q1(s);
scanf("%s", S);
L = strlen(S);
s = "";
for(int j = 0; j < L; ++j)
s.pb(S[j]);
if(w == mp(-1, -1)) {
printf("0\n");
continue;
}
reverse(s.begin(), s.end());
printf("%d\n", on.q2(w.fi, w.se, s));
}
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... |