# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
894446 | tamyte | Selling RNA Strands (JOI16_selling_rna) | C++14 | 1544 ms | 1048576 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 int int64_t
#define all(x) (x).begin(), (x).end()
#define UNIQUE(x) \
sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
using pii = std::pair<int, int>;
using namespace std;
void setIO(string name = "")
{
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (name.size())
{
freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
freopen((name + ".out").c_str(), "w", stdout);
}
}
int MOD = 1e9 + 7;
int oo = 1e18;
void solve() {
#define test1
int n, m;
cin >> n >> m;
map<string, vector<int>> preff;
map<pair<string, int>, bool> suff;
vector<string> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
string now = "";
for (auto& c : arr[i]) {
now += c;
preff[now].push_back(i);
}
reverse(arr[i].begin(), arr[i].end());
now = "";
for (auto& c : arr[i]) {
now += c;
suff[{now, i}] = true;
}
}
for (int i = 0; i < m; ++i) {
string p, q;
cin >> p >> q;
reverse(q.begin(), q.end());
if (preff.find(p) == preff.end()) {
cout << "0\n";
continue;
}
int cnt = 0;
for (auto& u : preff[p]) {
if (suff.find({q, u}) != suff.end()) {
cnt++;
}
}
cout << cnt << "\n";
}
}
int32_t main () {
setIO(""); int t = 1;
#ifdef test
cin >> t;
#endif
while (t--) solve();
}
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... |