QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#352501 | #7994. 勿蹖宠物 | alpha1022 | WA | 154ms | 477760kb | C++14 | 2.4kb | 2024-03-13 11:48:38 | 2024-03-13 11:48:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
void add(int &x, int y) { if ((x += y - mod) < 0) x += mod; }
const int N = 333;
const int M = 1e3;
const int S = 600;
int n, m;
char str[S + 5];
int len[N + 5], st[N + 5], lenSum, pos[2][S + 5];
struct Trie {
struct node {
int ch[26];
bool end;
} trie[S + 5];
int tot = 1;
void insert(int &u, int c) {
if (!trie[u].ch[c]) trie[u].ch[c] = ++tot;
u = trie[u].ch[c];
}
} trie[2];
int f[M / 2 + 5][S + 5][S + 5], coef, ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
st[i] = lenSum, scanf("%s", str + st[i] + 1); lenSum += len[i] = strlen(str + st[i] + 1);
int u = 1;
for (int j = 1; j <= len[i]; ++j) trie[0].insert(u, str[st[i] + j] - 'a'), pos[0][st[i] + j] = u;
trie[0].trie[u].end = 1;
u = 1;
for (int j = len[i]; j; --j) trie[1].insert(u, str[st[i] + j] - 'a'), pos[1][st[i] + j] = u;
trie[1].trie[u].end = 1;
coef += len[i] == 1;
}
if (~m & 1) coef = 1;
f[0][1][1] = 1;
for (int l = 0; (l + 1) * 2 <= m; ++l)
for (int u = 1; u <= trie[0].tot; ++u)
for (int v = 1; v <= trie[1].tot; ++v)
if (f[l][u][v]) {
bool edu = trie[0].trie[u].end, edv = trie[1].trie[v].end;
for (int c = 0; c < 26; ++c) {
int du = trie[0].trie[u].ch[c], dv = trie[1].trie[v].ch[c];
int nu = !edu ? 0 : trie[0].trie[1].ch[c], nv = !edv ? 0 : trie[1].trie[1].ch[c];
if (du && dv) add(f[l + 1][du][dv], f[l][u][v]);
if (nu && dv) add(f[l + 1][nu][dv], f[l][u][v]);
if (du && nv) add(f[l + 1][du][nv], f[l][u][v]);
if (nu && nv) add(f[l + 1][nu][nv], f[l][u][v]);
}
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
ans = (ans + (ll)f[m / 2][pos[0][st[i] + len[i]]][pos[1][st[j] + 1]] * coef) % mod;
if (m & 1)
for (int i = 1; i <= n; ++i)
if (len[i] > 1)
for (int j = 1; j <= n; ++j)
if (len[j] > 1)
add(ans, f[m / 2][pos[0][st[i] + len[i] - 1]][pos[1][st[j] + 1]]),
add(ans, f[m / 2][pos[0][st[i] + len[i]]][pos[1][st[j] + 2]]);
for (int i = 1; i <= n; ++i)
for (int j = 1; j + (m & 1) < len[i]; ++j)
add(ans, f[m / 2][j ? pos[0][st[i] + j] : 1][j + 1 + (m & 1) <= len[i] ? pos[1][st[i] + j + 1 + (m & 1)] : 1]);
printf("%d\n", ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4020kb
input:
7 9 cats eel eve evil lee olive stack
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
2 2 a aa
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
6 12 aa aab no on pets step
output:
43
result:
ok single line: '43'
Test #4:
score: 0
Accepted
time: 8ms
memory: 35428kb
input:
26 1000 a b c d e f g h i j k l m n o p q r s t u v w x y z
output:
710955506
result:
ok single line: '710955506'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4624kb
input:
33 18 zrkodfkhhkfdokrzo ytcbwrgyygrwbcty makgiybggbyigkamc aptmvovgccgvovmtpa yydxdzhhhhzdxdyy iadqfexoxacojythvk iagcfiwlaalwifcgai rtfzhddzzddhzftrm vkreigbdyxfiuvyqid mbcgnvrvvrvngcbmc lywbtspuyyupstbwyl bmjxalsyyslaxjmb jrbminaooanimbrj wwrajerkkrejarww grocaiqccqiacorg efvibgurrugbivfec ilyzrft...
output:
9
result:
ok single line: '9'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4724kb
input:
33 18 babbababbbbababbab abbabaabaabaababba aaabbbaabbaabbbaaa aaabaababbabaabaaa ababbaabbbbaabbaba baababbbbbbbbabaab aababbbaaaabbbabaa bbbbbabaaaababbbbb aabbbaaaaaaaabbbaa aabbbabaaaababbbaa bbabbaabaabaabbabb aababbabbbbabbabaa baaaaaabbbbaaaaaab aaabababaabababaaa bbaabbaaaaaabbaabb bbbababab...
output:
33
result:
ok single line: '33'
Test #7:
score: 0
Accepted
time: 3ms
memory: 4472kb
input:
33 18 babababaaaabababa abbbabbaaaabbabbba bbaaaabbaabbaaaabb baabbbbaaaabbbbaab abbbaababbabaabbb aaababbabbabbabaaa abbbbbbabbabbbbbba bbaabaaaaaaaabaabb aaaaabaaaaaabaaaaa abbbaabbbbbbaabbba abbbbaaaaaaaabbbba bbbbbbbbaabbbbbbbb baabaabbbbaabaab bbaababaaaababaabb baaabaabbbbaabaaab bbaaaabbbbbba...
output:
27
result:
ok single line: '27'
Test #8:
score: 0
Accepted
time: 2ms
memory: 4424kb
input:
33 18 bbbababaabababbb abaabaaabbaaabaaba aaabbbbbbaaaabbbab aaabbababbababbaaa abbaaabaabaaaaabbb abababaaaaaabababa bbabaaaaaaaababb bababbaaaaaabbaba aaaaababbbbabaaaa aaabaababbabaabaa abbbbbabbabbbbbaa abbbbbaabbaabbbbba abaaabbabaabbbabbb aabaabbbaabbbaabaa aaababbbbbabababaa abaaabbaabbaaabab...
output:
8
result:
ok single line: '8'
Test #9:
score: -100
Wrong Answer
time: 154ms
memory: 477760kb
input:
199 999 lbl buei ieub uw wu impv vpmi yrek kery cw wc hjs sjh bct tcb up pu wh hw ftn ntf iv vi ejpj jpje qjgh hgjq kvny ynvk xo ox pr rp sdh hds go og qw wq bgt tgb czwk kwzc coqr rqoc af fa ms sm gs sg hnz znh rugm mgur lak kal xlv vlx na an fdoe eodf oixg gxio mb bm bjt tjb bto otb oxq qxo tg gt ...
output:
953799869
result:
wrong answer 1st lines differ - expected: '810133722', found: '953799869'