| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 332616 | casperwang | Selling RNA Strands (JOI16_selling_rna) | C++14 | 1588 ms | 54460 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 long long
#define pb push_back
using namespace std;
const int MAXN = 100000;
const int BLOCK = 1000;
const int MOD = 998244353;
const int K = 1311;
int n, m;
string s[MAXN];
vector <int> pre_hash[MAXN];
vector <int> suf_hash[MAXN];
string p, q;
int now, ans;
bool pre(int a, int b, int len) {
return pre_hash[a][len-1] == b;
}
bool suf(int a, int b, int len) {
return suf_hash[a][len-1] == b;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort(s, s+n);
for (int i = 0; i < n; i++) {
int h = 0;
for (int j = 0; j < s[i].size(); j++) {
h = (h * K + s[i][j]) % MOD;
pre_hash[i].pb(h);
}
h = 0;
for (int j = s[i].size()-1; j >= 0; j--) {
h = (h * K + s[i][j]) % MOD;
suf_hash[i].pb(h);
}
}
for (int i = 0; i < m; i++) {
cin >> p >> q;
int hp = 0;
for (int j = 0; j < p.size(); j++)
hp = (hp * K + p[j]) % MOD;
int hq = 0;
for (int j = q.size()-1; j >= 0; j--)
hq = (hq * K + q[j]) % MOD;
now = lower_bound(s, s+n, p) - s;
ans = 0;
while (now < n && pre(now, hp, p.size())) {
if (suf(now, hq, q.size())) ans++;
now++;
}
cout << ans << "\n";
}
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... | ||||
