QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700210 | #5311. Master of Both | He_ng# | RE | 0ms | 3856kb | C++20 | 1.4kb | 2024-11-02 12:22:10 | 2024-11-02 12:22:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int N = 1e6;
const int M = 2e3;
int pr[26][26]; // 因为前i后j而产生差异的字符串数量
struct Trie {
Trie(int n) : son(n * 50), cnt(n * 50), nidx(0) {}
void insert(const vector<string> &vs) {
for (int k = 0; k < vs.size(); k++) {
int p = 0;
for (int i = 0; i < vs[k].size(); i++) {
int u = vs[k][i] - 'a';
if (!son[p][u]) {
son[p][u] = ++nidx;
}
for (int j = 0; j < 26; j++) {
if (j == u)
continue;
pr[j][u] += cnt[son[p][j]];
}
cnt[son[p][u]] += 1;
p = son[p][u];
}
}
}
int nidx;
vector<array<int, 26>> son;
vector<int> cnt;
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<string> vs(n);
Trie tr(n);
for (int i = 0; i < n; i++) {
cin >> vs[i];
}
tr.insert(vs);
string pp;
while (q--) {
cin >> pp;
int ans = 0;
for (int i = 0; i < 26; i++) {
for (int j = i + 1; j < 26; j++) {
ans += pr[pp[j] - 'a'][pp[i] - 'a'];
}
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
input:
5 3 aac oiputata aaa suikabudada aba abcdefghijklmnopqrstuvwxyz qwertyuiopasdfghjklzxcvbnm aquickbrownfxjmpsvethlzydg
output:
4 3 4
result:
ok 3 number(s): "4 3 4"
Test #2:
score: -100
Runtime Error
input:
100 100 spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...