QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703261#8334. GeneXiCen#ML 0ms0kbC++201.2kb2024-11-02 17:28:102024-11-02 17:28:11

Judging History

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

  • [2024-11-02 17:28:11]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-11-02 17:28:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N (int)2e5 + 5
#define pdd pair<double, double>
#define pii pair<int, int>

int a, b, c, d, x, y, n, m, t, k, q, l, r, z, h;
string s;
struct node {
    int son[27];
    int end = 0;
};
node tree[6000005];
int tot = 0;
void insert(string word) {
    int p = 0;
    for (char i : word) {
        int idx = i - 'a';
        if (tree[p].son[idx] == 0) tree[p].son[idx] = ++tot;
        p = tree[p].son[idx];
    }
    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]-'a']) ans += dfs(tree[now].son[s[i]-'a'], i + 1, kk);
    if (kk) {
        for (int j = 0; j < 27; j++) {
            if (j == s[i]-'a') continue;
            if (tree[now].son[j]) ans += dfs(tree[now].son[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: 0
Memory Limit Exceeded

input:

6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan

output:

2
2
1
0

result: