QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#515148 | #2273. Suffixes may Contain Prefixes | Cheek_support# | AC ✓ | 120ms | 36280kb | C++20 | 2.3kb | 2024-08-11 15:33:03 | 2024-08-11 15:33:04 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define DEBUG_VAR(x) { cerr << "* "#x" = " << x << endl; }
#define DEBUG_ARR(arr, l, r) { \
cerr << "* "#arr"[" << l << ", " << r << "]:"; \
for(auto it = l, itr = r; it <= itr; it++) \
cerr << arr[it] << ", "; \
cerr << endl; \
}
#define DEBUG_FMT(...) { cerr << "* "; fprintf(stderr, __VA_ARGS__); }
#define DEBUG_HERE { DEBUG_FMT("Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__); }
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template<class T>
inline void relax(T& x, const T& y) { x = (x > y) ? x : y; }
const int N = 2e3 + 5;
const LL INF = 0x3f3f3f3f3f3f3f3f;
struct Node
{
int ch[26];
int fail;
int len;
} t[4 * N];
int tot = 0;
void insert(char a[])
{
int cur = 0;
for(int i = 1; a[i]; i++) {
int& son = t[cur].ch[a[i] - 'a'];
if(!son) {
son = ++tot;
t[son].len = i;
}
cur = son;
}
}
void ACbuild()
{
queue<int> q;
for(int i = 0; i < 26; i++) {
if(t[0].ch[i]) q.push(t[0].ch[i]);
}
while(q.size()) {
int x = q.front(); q.pop();
for(int i = 0; i < 26; i++) {
if(t[x].ch[i]) {
t[t[x].ch[i]].fail = t[t[x].fail].ch[i];
q.push(t[x].ch[i]);
} else {
t[x].ch[i] = t[t[x].fail].ch[i];
}
}
}
}
int n, m;
char a[N];
LL f[N][N];
int dep[N];
int main()
{
// freopen("1.in", "r", stdin);
scanf("%s", a + 1);
scanf("%d", &m);
n = strlen(a + 1);
insert(a);
ACbuild();
dep[0] = 0;
for(int i = 1; i <= tot; i++) {
dep[i] = dep[t[i].fail] + 1;
}
memset(f, -0x3f, sizeof f);
f[0][0] = 0;
for(int i = 0; i < m; i++) {
for(int j = 0; j <= tot; j++) {
if(f[i][j] < 0) continue;
for(int c = 0; c < 26; c++) {
int son = t[j].ch[c];
relax(f[i + 1][son], f[i][j] + dep[son]);
}
}
}
LL ans = -INF;
for(int i = 0; i <= tot; i++) {
relax(ans, f[m][i]);
}
printf("%lld\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 35560kb
input:
fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...
output:
852
result:
ok single line: '852'
Test #2:
score: 0
Accepted
time: 32ms
memory: 35348kb
input:
ddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttddddddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddt...
output:
5894
result:
ok single line: '5894'
Test #3:
score: 0
Accepted
time: 116ms
memory: 35576kb
input:
wswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswswswwwsswswswwwswswswwwswswsswswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswsws...
output:
10500
result:
ok single line: '10500'
Test #4:
score: 0
Accepted
time: 21ms
memory: 35244kb
input:
sjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjsspffsjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjssjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsj...
output:
4267
result:
ok single line: '4267'
Test #5:
score: 0
Accepted
time: 120ms
memory: 35700kb
input:
mmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpm...
output:
9536
result:
ok single line: '9536'
Test #6:
score: 0
Accepted
time: 26ms
memory: 35228kb
input:
pepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepepypgakpepypopepepypopepypopepepyzpepypopepepypepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepypopepepypopepypopepvplpepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepep...
output:
4033
result:
ok single line: '4033'
Test #7:
score: 0
Accepted
time: 111ms
memory: 35488kb
input:
fifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfyqnfifuurfifuugfifuurfifufifuurfifuugfifuurxvfifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuu...
output:
9452
result:
ok single line: '9452'
Test #8:
score: 0
Accepted
time: 19ms
memory: 36120kb
input:
gwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxrgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgwvgwgxlggwgxihdggw...
output:
3584
result:
ok single line: '3584'
Test #9:
score: 0
Accepted
time: 3ms
memory: 35208kb
input:
aabaacaabaa 101
output:
249
result:
ok single line: '249'
Test #10:
score: 0
Accepted
time: 0ms
memory: 35812kb
input:
aabaacaabaa 102
output:
251
result:
ok single line: '251'
Test #11:
score: 0
Accepted
time: 0ms
memory: 35844kb
input:
aabaacaabaa 103
output:
253
result:
ok single line: '253'
Test #12:
score: 0
Accepted
time: 0ms
memory: 36280kb
input:
aabaacaabaa 104
output:
255
result:
ok single line: '255'
Test #13:
score: 0
Accepted
time: 0ms
memory: 35184kb
input:
aabaacaabaa 105
output:
257
result:
ok single line: '257'
Test #14:
score: 0
Accepted
time: 3ms
memory: 35144kb
input:
cciccpccicc 2000
output:
4995
result:
ok single line: '4995'
Test #15:
score: 0
Accepted
time: 3ms
memory: 35620kb
input:
lkultxuuxtkltukllulxkltuutkuuttkuxutuuxuutuxtkxktklltllulkltxtttkkkxxtuxltkxtxtttlltttlkkkutkkuxulklxuuxullkkxtktlxtutuxlktkkllxutlllxkltkutxltxtlluxxlxxxklxlluuxllllxxlllluktkxtkutluktxkkukluktkkuktlkkultukulxlxkltlllkkluluutkxlxkuktktxxtkkkkkuxtxttkxtuxkkttklltulktltxkutluuulluxtuxlllltlutxulxxltk...
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 3ms
memory: 35916kb
input:
zrszgeggmmagjcibhsuuugohqppnncuuksrynidfbmhaqpnzswblenhttvtgadwjybijjwhixqppgzqajdqbmjrgaziljastkonutvyqrxtvshhoidkixodyrekyshlafxnikbgaqegxbgwmpgbxnpkdxhnhcocmbpimftogrlydyqitekbfvtimiztujfejkomujzztadjhrvdqlakxnbctuaubumwlwyibmyjabrrdznkvndghplgqjmcvqhmgbsrnpmjjbkkqmnvzczlpsrgdmsmmcgksbkhzatnpiwch...
output:
2
result:
ok single line: '2'
Test #17:
score: 0
Accepted
time: 4ms
memory: 35208kb
input:
xxiiixxhhhxxiiixx 1996
output:
4187
result:
ok single line: '4187'
Test #18:
score: 0
Accepted
time: 4ms
memory: 35268kb
input:
xxiiixxhhhxxiiixx 1997
output:
4190
result:
ok single line: '4190'
Test #19:
score: 0
Accepted
time: 4ms
memory: 35180kb
input:
xxiiixxhhhxxiiixx 1998
output:
4192
result:
ok single line: '4192'
Test #20:
score: 0
Accepted
time: 4ms
memory: 35472kb
input:
xxiiixxhhhxxiiixx 1999
output:
4194
result:
ok single line: '4194'
Test #21:
score: 0
Accepted
time: 3ms
memory: 35820kb
input:
xxiiixxhhhxxiiixx 2000
output:
4196
result:
ok single line: '4196'
Test #22:
score: 0
Accepted
time: 4ms
memory: 35200kb
input:
xxiiixxhhhxxiiixxicpcicpc 2000
output:
4196
result:
ok single line: '4196'
Test #23:
score: 0
Accepted
time: 0ms
memory: 35480kb
input:
c 123
output:
123
result:
ok single line: '123'
Test #24:
score: 0
Accepted
time: 3ms
memory: 35440kb
input:
p 2000
output:
2000
result:
ok single line: '2000'
Test #25:
score: 0
Accepted
time: 7ms
memory: 35400kb
input:
nananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananana 500
output:
40100
result:
ok single line: '40100'
Test #26:
score: 0
Accepted
time: 0ms
memory: 35404kb
input:
czgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczg...
output:
1717
result:
ok single line: '1717'
Test #27:
score: 0
Accepted
time: 118ms
memory: 35424kb
input:
fjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxx...
output:
201000
result:
ok single line: '201000'
Test #28:
score: 0
Accepted
time: 112ms
memory: 35788kb
input:
uuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxpp...
output:
134469
result:
ok single line: '134469'
Test #29:
score: 0
Accepted
time: 24ms
memory: 35216kb
input:
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
output:
440469
result:
ok single line: '440469'
Test #30:
score: 0
Accepted
time: 116ms
memory: 35836kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
2001000
result:
ok single line: '2001000'
Test #31:
score: 0
Accepted
time: 0ms
memory: 35188kb
input:
a 1
output:
1
result:
ok single line: '1'
Test #32:
score: 0
Accepted
time: 0ms
memory: 35184kb
input:
z 1
output:
1
result:
ok single line: '1'
Test #33:
score: 0
Accepted
time: 0ms
memory: 35356kb
input:
cc 1
output:
1
result:
ok single line: '1'
Test #34:
score: 0
Accepted
time: 0ms
memory: 35252kb
input:
gg 1
output:
1
result:
ok single line: '1'
Test #35:
score: 0
Accepted
time: 3ms
memory: 35280kb
input:
yx 2
output:
2
result:
ok single line: '2'
Test #36:
score: 0
Accepted
time: 0ms
memory: 35176kb
input:
tr 2
output:
2
result:
ok single line: '2'
Test #37:
score: 0
Accepted
time: 0ms
memory: 35336kb
input:
xxyxxyx 20
output:
49
result:
ok single line: '49'