QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#703419 | #8334. Gene | XiCen | TL | 39ms | 331852kb | C++20 | 1.1kb | 2024-11-02 17:46:12 | 2024-11-02 17:46:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
string s;
struct node {
map<char, int> son;
int end = 0;
} tree[6000005];
int tot = 0;
void insert(string& word) {
int p = 0;
for (char& i : word) {
// int idx = i - 'a';
if (!tree[p].son.count(i)) tree[p].son[i] = ++tot;
p = tree[p].son[i];
}
tree[p].end++;
}
int dfs(int now, int i, int kk) {
if (i == m) return tree[now].end;
int ans = 0;
if (tree[now].son[s[i]]) ans += dfs(tree[now].son[s[i]], i + 1, kk);
if (kk) {
for (int j = 0; j < 27; j++) {
if (j == s[i]-'a') continue;
if (tree[now].son.count('a'+j)) ans += dfs(tree[now].son['a'+j], i + 1, kk - 1);
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// 注意根据数据量调整N的大小
cin >> n >> q >> m >> k;
for (int i = 1; i <= n; i++) cin >> s, insert(s);
while (q--) {
cin >> s;
cout << dfs(0, 0, k) << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 38ms
memory: 331852kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 2 1 0
result:
ok 4 number(s): "2 2 1 0"
Test #2:
score: 0
Accepted
time: 39ms
memory: 331740kb
input:
8 6 7 3 delphis aduncus peronii plumbea clymene hectori griseus electra delphis helpiii perphii clumeee eleelea ddlpcus
output:
1 1 2 2 1 2
result:
ok 6 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
300 300 9 10 dmzampmxe bteaudaxb fjfwhhsfq btnfzqtyp ijjrkbyht hkizlvgdc ukwsnhiff hacsdrwyl fbjabnhst ktsxbgbtg jopdbsdsr yxdxxjltd daechsouq klrglgwbn llzhqzlor ckdedutfn lkjxcryoe zvusjevtz cevrcdltg tdmmvvpkj davfsweem spcfhcitm aohsfqrqh lblehevpj soaqryimp tbxlulxmn tnlzbkhda ukfhjykuk eghpuua...