| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 155199 | dolphingarlic | Selling RNA Strands (JOI16_selling_rna) | C++14 | 1564 ms | 45640 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 FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
const ll P = 7, M = 1e9 + 9;
map<char, int> ALPHA = {{'A', 1}, {'G', 2}, {'U', 3}, {'C', 4}};
vector<ll> hsh[100001][2];
ll pw[200001];
ll make_hsh(string s) {
ll hsh_val = 0;
FOR(i, 0, s.size()) {
hsh_val = (hsh_val + ALPHA[s[i]] * pw[i]) % M;
}
return hsh_val;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
pw[0] = 1;
FOR(i, 1, 200001) pw[i] = (pw[i - 1] * P) % M;
int n, q;
cin >> n >> q;
FOR(i, 0, n) {
string s;
cin >> s;
ll hsh_val = 0;
FOR(j, 0, s.size()) {
hsh_val = (hsh_val + ALPHA[s[j]] * pw[j]) % M;
hsh[i][0].push_back(hsh_val);
}
reverse(s.begin(), s.end());
hsh_val = 0;
FOR(j, 0, s.size()) {
hsh_val = (hsh_val + ALPHA[s[j]] * pw[j]) % M;
hsh[i][1].push_back(hsh_val);
}
}
while (q--) {
string a, b;
cin >> a >> b;
reverse(b.begin(), b.end());
ll hsh_a = make_hsh(a), hsh_b = make_hsh(b);
int cnt = 0;
FOR(i, 0, n) {
if (hsh[i][0][a.size() - 1] == hsh_a && hsh[i][1][b.size() - 1] == hsh_b) cnt++;
}
cout << cnt << '\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... | ||||
