QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#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;
}
詳細信息
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...