QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#703419#8334. GeneXiCenTL 39ms331852kbC++201.1kb2024-11-02 17:46:122024-11-02 17:46:17

Judging History

你现在查看的是最新测评结果

  • [2024-11-02 17:46:17]
  • 评测
  • 测评结果:TL
  • 用时:39ms
  • 内存:331852kb
  • [2024-11-02 17:46:12]
  • 提交

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;
}

詳細信息

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...

output:


result: