QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#515012 | #2273. Suffixes may Contain Prefixes | AnotherDayofSun# | AC ✓ | 91ms | 38340kb | C++20 | 1.3kb | 2024-08-11 14:26:55 | 2024-08-11 14:26:56 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define foR(i,j,k) for(int i=(j);i>=(k);i--)
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define mkp make_pair
#define SZ(x) ((int)x.size())
#define int long long
using namespace std;
inline int read() {
char c;int res=0;bool flag=0;
while(c=getchar(),c<48)(c=='-')&&(flag=1);
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>47);
flag&&(res=-res); return res;
}
char c[2003];
int n,m,f[2003][2003],fa[2003],g[2003],to[2003][203],ans;
signed main(){
scanf("%s",c+1);
n=strlen(c+1);
m=read();
fa[0]=-1;
for(int i=1;i<=n;++i){
int x=fa[i-1];
while(x!=-1){
if(c[x+1]==c[i])break;
x=fa[x];
}
fa[i]=x+1;
g[i]=g[fa[i]]+1;
}
for(int j='a';j<='z';++j){
to[0][j]=0;
}
to[0][c[1]]=1;
for(int i=1;i<=n;++i){
for(int j='a';j<='z';++j){
if(j==c[i+1])to[i][j]=i+1;
else to[i][j]=to[fa[i]][j];
}
}
for(int i=0;i<=m;++i){
for(int j=0;j<=n;++j){
f[i][j]=-1e9;
}
}
f[0][0]=0;
for(int i=1;i<=m;++i){
for(int j=0;j<=n;++j){
for(int c='a';c<='z';++c){
if(f[i][to[j][c]]<f[i-1][j]+g[to[j][c]]){
f[i][to[j][c]]=f[i-1][j]+g[to[j][c]];
}
}
}
}
for(int i=0;i<=n;++i){
if(f[m][i]>ans)ans=f[m][i];
}
cout<<ans;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 10756kb
input:
fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...
output:
852
result:
ok single line: '852'
Test #2:
score: 0
Accepted
time: 19ms
memory: 27352kb
input:
ddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttddddddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddt...
output:
5894
result:
ok single line: '5894'
Test #3:
score: 0
Accepted
time: 91ms
memory: 38300kb
input:
wswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswswswwwsswswswwwswswswwwswswsswswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswsws...
output:
10500
result:
ok single line: '10500'
Test #4:
score: 0
Accepted
time: 11ms
memory: 22804kb
input:
sjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjsspffsjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjssjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsj...
output:
4267
result:
ok single line: '4267'
Test #5:
score: 0
Accepted
time: 91ms
memory: 38340kb
input:
mmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpm...
output:
9536
result:
ok single line: '9536'
Test #6:
score: 0
Accepted
time: 9ms
memory: 24360kb
input:
pepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepepypgakpepypopepepypopepypopepepyzpepypopepepypepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepypopepepypopepypopepvplpepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepep...
output:
4033
result:
ok single line: '4033'
Test #7:
score: 0
Accepted
time: 87ms
memory: 38232kb
input:
fifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfyqnfifuurfifuugfifuurfifufifuurfifuugfifuurxvfifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuu...
output:
9452
result:
ok single line: '9452'
Test #8:
score: 0
Accepted
time: 5ms
memory: 20544kb
input:
gwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxrgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgwvgwgxlggwgxihdggw...
output:
3584
result:
ok single line: '3584'
Test #9:
score: 0
Accepted
time: 0ms
memory: 7688kb
input:
aabaacaabaa 101
output:
249
result:
ok single line: '249'
Test #10:
score: 0
Accepted
time: 1ms
memory: 5760kb
input:
aabaacaabaa 102
output:
251
result:
ok single line: '251'
Test #11:
score: 0
Accepted
time: 0ms
memory: 5824kb
input:
aabaacaabaa 103
output:
253
result:
ok single line: '253'
Test #12:
score: 0
Accepted
time: 1ms
memory: 7884kb
input:
aabaacaabaa 104
output:
255
result:
ok single line: '255'
Test #13:
score: 0
Accepted
time: 0ms
memory: 7960kb
input:
aabaacaabaa 105
output:
257
result:
ok single line: '257'
Test #14:
score: 0
Accepted
time: 0ms
memory: 36584kb
input:
cciccpccicc 2000
output:
4995
result:
ok single line: '4995'
Test #15:
score: 0
Accepted
time: 0ms
memory: 8380kb
input:
lkultxuuxtkltukllulxkltuutkuuttkuxutuuxuutuxtkxktklltllulkltxtttkkkxxtuxltkxtxtttlltttlkkkutkkuxulklxuuxullkkxtktlxtutuxlktkkllxutlllxkltkutxltxtlluxxlxxxklxlluuxllllxxlllluktkxtkutluktxkkukluktkkuktlkkultukulxlxkltlllkkluluutkxlxkuktktxxtkkkkkuxtxttkxtuxkkttklltulktltxkutluuulluxtuxlllltlutxulxxltk...
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 0ms
memory: 8328kb
input:
zrszgeggmmagjcibhsuuugohqppnncuuksrynidfbmhaqpnzswblenhttvtgadwjybijjwhixqppgzqajdqbmjrgaziljastkonutvyqrxtvshhoidkixodyrekyshlafxnikbgaqegxbgwmpgbxnpkdxhnhcocmbpimftogrlydyqitekbfvtimiztujfejkomujzztadjhrvdqlakxnbctuaubumwlwyibmyjabrrdznkvndghplgqjmcvqhmgbsrnpmjjbkkqmnvzczlpsrgdmsmmcgksbkhzatnpiwch...
output:
2
result:
ok single line: '2'
Test #17:
score: 0
Accepted
time: 0ms
memory: 34976kb
input:
xxiiixxhhhxxiiixx 1996
output:
4187
result:
ok single line: '4187'
Test #18:
score: 0
Accepted
time: 3ms
memory: 34680kb
input:
xxiiixxhhhxxiiixx 1997
output:
4190
result:
ok single line: '4190'
Test #19:
score: 0
Accepted
time: 3ms
memory: 34744kb
input:
xxiiixxhhhxxiiixx 1998
output:
4192
result:
ok single line: '4192'
Test #20:
score: 0
Accepted
time: 0ms
memory: 36600kb
input:
xxiiixxhhhxxiiixx 1999
output:
4194
result:
ok single line: '4194'
Test #21:
score: 0
Accepted
time: 0ms
memory: 36468kb
input:
xxiiixxhhhxxiiixx 2000
output:
4196
result:
ok single line: '4196'
Test #22:
score: 0
Accepted
time: 0ms
memory: 34672kb
input:
xxiiixxhhhxxiiixxicpcicpc 2000
output:
4196
result:
ok single line: '4196'
Test #23:
score: 0
Accepted
time: 0ms
memory: 7856kb
input:
c 123
output:
123
result:
ok single line: '123'
Test #24:
score: 0
Accepted
time: 0ms
memory: 34804kb
input:
p 2000
output:
2000
result:
ok single line: '2000'
Test #25:
score: 0
Accepted
time: 2ms
memory: 14200kb
input:
nananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananana 500
output:
40100
result:
ok single line: '40100'
Test #26:
score: 0
Accepted
time: 2ms
memory: 9576kb
input:
czgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczg...
output:
1717
result:
ok single line: '1717'
Test #27:
score: 0
Accepted
time: 78ms
memory: 38100kb
input:
fjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxx...
output:
201000
result:
ok single line: '201000'
Test #28:
score: 0
Accepted
time: 73ms
memory: 38140kb
input:
uuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxpp...
output:
134469
result:
ok single line: '134469'
Test #29:
score: 0
Accepted
time: 12ms
memory: 23240kb
input:
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
output:
440469
result:
ok single line: '440469'
Test #30:
score: 0
Accepted
time: 73ms
memory: 38300kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
2001000
result:
ok single line: '2001000'
Test #31:
score: 0
Accepted
time: 0ms
memory: 5880kb
input:
a 1
output:
1
result:
ok single line: '1'
Test #32:
score: 0
Accepted
time: 1ms
memory: 5824kb
input:
z 1
output:
1
result:
ok single line: '1'
Test #33:
score: 0
Accepted
time: 1ms
memory: 5628kb
input:
cc 1
output:
1
result:
ok single line: '1'
Test #34:
score: 0
Accepted
time: 0ms
memory: 5828kb
input:
gg 1
output:
1
result:
ok single line: '1'
Test #35:
score: 0
Accepted
time: 1ms
memory: 5676kb
input:
yx 2
output:
2
result:
ok single line: '2'
Test #36:
score: 0
Accepted
time: 1ms
memory: 5820kb
input:
tr 2
output:
2
result:
ok single line: '2'
Test #37:
score: 0
Accepted
time: 1ms
memory: 5820kb
input:
xxyxxyx 20
output:
49
result:
ok single line: '49'