QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#28259 | #2273. Suffixes may Contain Prefixes | Suika_predator# | AC ✓ | 543ms | 37392kb | C++20 | 1.6kb | 2022-04-12 23:04:21 | 2022-04-29 09:21:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod1=998244353;
const int mod2=1000000007;
const int base1=97;
const int base2=37;
ll h1[2050],h2[2050];
ll pw1[2050],pw2[2050];
string str;
ll val[2050][30],nxt[2050][30];
ll dp[2050][2050];
int n,m;
void upd(ll &a,ll b){if (a<=b) a=b;}
void prepare(){
pw1[0]=1;
for (int i=1;i<=2000;i++) pw1[i]=pw1[i-1]*base1%mod1;
pw2[0]=1;
for (int i=1;i<=2000;i++) pw2[i]=pw2[i-1]*base2%mod2;
}
ll geth1(int l,int r){
if (l>r) return 0;
return (h1[r]-h1[l-1]*pw1[r-l+1]%mod1+mod1)%mod1;
}
ll geth2(int l,int r){
if (l>r) return 0;
return (h2[r]-h2[l-1]*pw2[r-l+1]%mod2+mod2)%mod2;
}
int main(){
ios_base::sync_with_stdio(false);
prepare();
cin >> str;
m=str.length();
str=" "+str;
cin >> n;
for (int i=1;i<=m;i++){
h1[i]=(h1[i-1]*base1+str[i]-'a')%mod1;
h2[i]=(h2[i-1]*base2+str[i]-'a')%mod2;
}
for (int i=0;i<=m;i++){
for (int c=0;c<26;c++){
for (int len=1;len<=i+1 && len<=m;len++){
ll tmph1=(geth1(i+1-len+1,i)*base1+c)%mod1;
ll tmph2=(geth2(i+1-len+1,i)*base2+c)%mod2;
if (tmph1==h1[len] && tmph2==h2[len]){
nxt[i][c]=len;
val[i][c]++;
}
}
}
}
for (int i=0;i<=n+10;i++)
for (int j=0;j<=m+10;j++) dp[i][j]=-1e9;
dp[0][0]=0;
for (int i=1;i<=n;i++)
for (int j=0;j<=m;j++)
for (int c=0;c<26;c++) upd(dp[i][nxt[j][c]],dp[i-1][j]+val[j][c]);
/*
for (int i=1;i<=n;i++){
for (int j=0;j<=m;j++) cerr << dp[i][j] << " ";
cerr << "\n";
}
*/
ll ans=0;
for (int j=0;j<=m;j++) ans=max(ans,dp[n][j]);
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 74ms
memory: 10144kb
input:
fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...
output:
852
result:
ok single line: '852'
Test #2:
score: 0
Accepted
time: 79ms
memory: 23084kb
input:
ddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttddddddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddt...
output:
5894
result:
ok single line: '5894'
Test #3:
score: 0
Accepted
time: 543ms
memory: 36756kb
input:
wswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswswswwwsswswswwwswswswwwswswsswswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswsws...
output:
10500
result:
ok single line: '10500'
Test #4:
score: 0
Accepted
time: 45ms
memory: 22552kb
input:
sjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjsspffsjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjssjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsj...
output:
4267
result:
ok single line: '4267'
Test #5:
score: 0
Accepted
time: 542ms
memory: 36788kb
input:
mmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpm...
output:
9536
result:
ok single line: '9536'
Test #6:
score: 0
Accepted
time: 34ms
memory: 22576kb
input:
pepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepepypgakpepypopepepypopepypopepepyzpepypopepepypepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepypopepepypopepypopepvplpepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepep...
output:
4033
result:
ok single line: '4033'
Test #7:
score: 0
Accepted
time: 537ms
memory: 37392kb
input:
fifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfyqnfifuurfifuugfifuurfifufifuurfifuugfifuurxvfifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuu...
output:
9452
result:
ok single line: '9452'
Test #8:
score: 0
Accepted
time: 21ms
memory: 18924kb
input:
gwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxrgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgwvgwgxlggwgxihdggw...
output:
3584
result:
ok single line: '3584'
Test #9:
score: 0
Accepted
time: 3ms
memory: 4152kb
input:
aabaacaabaa 101
output:
249
result:
ok single line: '249'
Test #10:
score: 0
Accepted
time: 2ms
memory: 7860kb
input:
aabaacaabaa 102
output:
251
result:
ok single line: '251'
Test #11:
score: 0
Accepted
time: 4ms
memory: 6040kb
input:
aabaacaabaa 103
output:
253
result:
ok single line: '253'
Test #12:
score: 0
Accepted
time: 3ms
memory: 6204kb
input:
aabaacaabaa 104
output:
255
result:
ok single line: '255'
Test #13:
score: 0
Accepted
time: 2ms
memory: 7796kb
input:
aabaacaabaa 105
output:
257
result:
ok single line: '257'
Test #14:
score: 0
Accepted
time: 3ms
memory: 32020kb
input:
cciccpccicc 2000
output:
4995
result:
ok single line: '4995'
Test #15:
score: 0
Accepted
time: 11ms
memory: 3864kb
input:
lkultxuuxtkltukllulxkltuutkuuttkuxutuuxuutuxtkxktklltllulkltxtttkkkxxtuxltkxtxtttlltttlkkkutkkuxulklxuuxullkkxtktlxtutuxlktkkllxutlllxkltkutxltxtlluxxlxxxklxlluuxllllxxlllluktkxtkutluktxkkukluktkkuktlkkultukulxlxkltlllkkluluutkxlxkuktktxxtkkkkkuxtxttkxtuxkkttklltulktltxkutluuulluxtuxlllltlutxulxxltk...
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 22ms
memory: 5872kb
input:
zrszgeggmmagjcibhsuuugohqppnncuuksrynidfbmhaqpnzswblenhttvtgadwjybijjwhixqppgzqajdqbmjrgaziljastkonutvyqrxtvshhoidkixodyrekyshlafxnikbgaqegxbgwmpgbxnpkdxhnhcocmbpimftogrlydyqitekbfvtimiztujfejkomujzztadjhrvdqlakxnbctuaubumwlwyibmyjabrrdznkvndghplgqjmcvqhmgbsrnpmjjbkkqmnvzczlpsrgdmsmmcgksbkhzatnpiwch...
output:
2
result:
ok single line: '2'
Test #17:
score: 0
Accepted
time: 1ms
memory: 31672kb
input:
xxiiixxhhhxxiiixx 1996
output:
4187
result:
ok single line: '4187'
Test #18:
score: 0
Accepted
time: 5ms
memory: 32084kb
input:
xxiiixxhhhxxiiixx 1997
output:
4190
result:
ok single line: '4190'
Test #19:
score: 0
Accepted
time: 4ms
memory: 31896kb
input:
xxiiixxhhhxxiiixx 1998
output:
4192
result:
ok single line: '4192'
Test #20:
score: 0
Accepted
time: 1ms
memory: 31900kb
input:
xxiiixxhhhxxiiixx 1999
output:
4194
result:
ok single line: '4194'
Test #21:
score: 0
Accepted
time: 0ms
memory: 31736kb
input:
xxiiixxhhhxxiiixx 2000
output:
4196
result:
ok single line: '4196'
Test #22:
score: 0
Accepted
time: 0ms
memory: 32028kb
input:
xxiiixxhhhxxiiixxicpcicpc 2000
output:
4196
result:
ok single line: '4196'
Test #23:
score: 0
Accepted
time: 4ms
memory: 7868kb
input:
c 123
output:
123
result:
ok single line: '123'
Test #24:
score: 0
Accepted
time: 3ms
memory: 32064kb
input:
p 2000
output:
2000
result:
ok single line: '2000'
Test #25:
score: 0
Accepted
time: 12ms
memory: 13988kb
input:
nananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananana 500
output:
40100
result:
ok single line: '40100'
Test #26:
score: 0
Accepted
time: 448ms
memory: 8028kb
input:
czgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczg...
output:
1717
result:
ok single line: '1717'
Test #27:
score: 0
Accepted
time: 527ms
memory: 36936kb
input:
fjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxx...
output:
201000
result:
ok single line: '201000'
Test #28:
score: 0
Accepted
time: 524ms
memory: 36776kb
input:
uuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxpp...
output:
134469
result:
ok single line: '134469'
Test #29:
score: 0
Accepted
time: 60ms
memory: 21088kb
input:
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
output:
440469
result:
ok single line: '440469'
Test #30:
score: 0
Accepted
time: 530ms
memory: 36736kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
2001000
result:
ok single line: '2001000'
Test #31:
score: 0
Accepted
time: 3ms
memory: 5796kb
input:
a 1
output:
1
result:
ok single line: '1'
Test #32:
score: 0
Accepted
time: 3ms
memory: 5672kb
input:
z 1
output:
1
result:
ok single line: '1'
Test #33:
score: 0
Accepted
time: 3ms
memory: 5788kb
input:
cc 1
output:
1
result:
ok single line: '1'
Test #34:
score: 0
Accepted
time: 2ms
memory: 3796kb
input:
gg 1
output:
1
result:
ok single line: '1'
Test #35:
score: 0
Accepted
time: 0ms
memory: 5768kb
input:
yx 2
output:
2
result:
ok single line: '2'
Test #36:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
tr 2
output:
2
result:
ok single line: '2'
Test #37:
score: 0
Accepted
time: 3ms
memory: 5856kb
input:
xxyxxyx 20
output:
49
result:
ok single line: '49'