QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#842775#2273. Suffixes may Contain Prefixesmrkiencf#AC ✓76ms23568kbC++202.3kb2025-01-04 14:39:452025-01-04 14:39:50

Judging History

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

  • [2025-01-04 14:39:50]
  • 评测
  • 测评结果:AC
  • 用时:76ms
  • 内存:23568kb
  • [2025-01-04 14:39:45]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long

using namespace std;

const int O = 2e3 + 5;
const int mod = 998244353;
const int lim = 'z' - 'a';

bool lcp[O][O];
int n, m, f[O][O], nxt[27][O], weight[O];
string s;

void Maximize(int &x, int y){
    if (x < y) x = y;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    if (fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    cin >> s >> n;
    m = s.size(); s = " " + s;

    /*string cur = "";
    map<string, bool> dd;
    for (int i = 1; i <= m; ++ i){
        cur += s[i];
        reverse(cur.begin(), cur.end());
        dd[cur] = 1;
        reverse(cur.begin(), cur.end());
    }*/

    lcp[0][0] = true;
    for (int i = 1; i <= m; ++ i){
        lcp[i][0] = true;
        for (int j = 1; j <= i; ++ j){
            lcp[i][j] = (lcp[i - 1][j - 1] & (s[i] == s[j]));
        }
    }

    for (int i = 1; i <= m; ++ i){
        //cur = "";
        for (int j = 1; j <= i; ++ j){
            //cur += s[i - j + 1];
            weight[i] += lcp[i][j];
        }
        //cout << weight[i] << endl;
    }

    for (int i = 0; i <= m; ++ i){
        //cur += s[i];
        for (int j = 0; j <= lim; ++ j){
            /*string nw = "";
            nw += char(j + 'a');
            if (dd[nw]) nxt[j][i] = 1;
            for (int z = i; z >= 1; -- z){
                nw += s[z];
                if (dd[nw]){
                    Maximize(nxt[j][i], i - z + 2);
                }
            }*/
            for (int z = 0; z <= i; ++ z){
                if (j + 'a' == s[z + 1] && lcp[i][z]) Maximize(nxt[j][i], z + 1);
            }
        }
    }

    /*for (int i = 0; i <= 2; ++ i){
        for (int j = 0; j <= m; ++ j){
            cout << j << " " << char(i + 'a') << " " << nxt[i][j] << endl;
        }
    }*/

    memset(f, -1, sizeof(f));

    f[0][0] = 0;
    for (int i = 0; i < n; ++ i){
        for (int j = 0; j <= m; ++ j){
            if (f[j][i] == -1) continue;
            for (int z = 0; z <= lim; ++ z){
                Maximize(f[nxt[z][j]][i + 1], f[j][i] + weight[nxt[z][j]]);
            }
        }
    }

    int res = 0;
    for (int i = 0; i <= m; ++ i) Maximize(res, f[i][n]);

    cout << res;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 22172kb

input:

fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...

output:

852

result:

ok single line: '852'

Test #2:

score: 0
Accepted
time: 15ms
memory: 21316kb

input:

ddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttddddddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddt...

output:

5894

result:

ok single line: '5894'

Test #3:

score: 0
Accepted
time: 75ms
memory: 23272kb

input:

wswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswswswwwsswswswwwswswswwwswswsswswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswsws...

output:

10500

result:

ok single line: '10500'

Test #4:

score: 0
Accepted
time: 15ms
memory: 21876kb

input:

sjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjsspffsjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjssjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsj...

output:

4267

result:

ok single line: '4267'

Test #5:

score: 0
Accepted
time: 76ms
memory: 23240kb

input:

mmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpm...

output:

9536

result:

ok single line: '9536'

Test #6:

score: 0
Accepted
time: 14ms
memory: 21440kb

input:

pepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepepypgakpepypopepepypopepypopepepyzpepypopepepypepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepypopepepypopepypopepvplpepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepep...

output:

4033

result:

ok single line: '4033'

Test #7:

score: 0
Accepted
time: 72ms
memory: 23568kb

input:

fifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfyqnfifuurfifuugfifuurfifufifuurfifuugfifuurxvfifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuu...

output:

9452

result:

ok single line: '9452'

Test #8:

score: 0
Accepted
time: 10ms
memory: 20100kb

input:

gwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxrgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgwvgwgxlggwgxihdggw...

output:

3584

result:

ok single line: '3584'

Test #9:

score: 0
Accepted
time: 4ms
memory: 19692kb

input:

aabaacaabaa
101

output:

249

result:

ok single line: '249'

Test #10:

score: 0
Accepted
time: 0ms
memory: 21364kb

input:

aabaacaabaa
102

output:

251

result:

ok single line: '251'

Test #11:

score: 0
Accepted
time: 0ms
memory: 20540kb

input:

aabaacaabaa
103

output:

253

result:

ok single line: '253'

Test #12:

score: 0
Accepted
time: 0ms
memory: 20084kb

input:

aabaacaabaa
104

output:

255

result:

ok single line: '255'

Test #13:

score: 0
Accepted
time: 0ms
memory: 20888kb

input:

aabaacaabaa
105

output:

257

result:

ok single line: '257'

Test #14:

score: 0
Accepted
time: 3ms
memory: 19440kb

input:

cciccpccicc
2000

output:

4995

result:

ok single line: '4995'

Test #15:

score: 0
Accepted
time: 0ms
memory: 20064kb

input:

lkultxuuxtkltukllulxkltuutkuuttkuxutuuxuutuxtkxktklltllulkltxtttkkkxxtuxltkxtxtttlltttlkkkutkkuxulklxuuxullkkxtktlxtutuxlktkkllxutlllxkltkutxltxtlluxxlxxxklxlluuxllllxxlllluktkxtkutluktxkkukluktkkuktlkkultukulxlxkltlllkkluluutkxlxkuktktxxtkkkkkuxtxttkxtuxkkttklltulktltxkutluuulluxtuxlllltlutxulxxltk...

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 21048kb

input:

zrszgeggmmagjcibhsuuugohqppnncuuksrynidfbmhaqpnzswblenhttvtgadwjybijjwhixqppgzqajdqbmjrgaziljastkonutvyqrxtvshhoidkixodyrekyshlafxnikbgaqegxbgwmpgbxnpkdxhnhcocmbpimftogrlydyqitekbfvtimiztujfejkomujzztadjhrvdqlakxnbctuaubumwlwyibmyjabrrdznkvndghplgqjmcvqhmgbsrnpmjjbkkqmnvzczlpsrgdmsmmcgksbkhzatnpiwch...

output:

2

result:

ok single line: '2'

Test #17:

score: 0
Accepted
time: 2ms
memory: 20652kb

input:

xxiiixxhhhxxiiixx
1996

output:

4187

result:

ok single line: '4187'

Test #18:

score: 0
Accepted
time: 4ms
memory: 19976kb

input:

xxiiixxhhhxxiiixx
1997

output:

4190

result:

ok single line: '4190'

Test #19:

score: 0
Accepted
time: 0ms
memory: 19744kb

input:

xxiiixxhhhxxiiixx
1998

output:

4192

result:

ok single line: '4192'

Test #20:

score: 0
Accepted
time: 4ms
memory: 21400kb

input:

xxiiixxhhhxxiiixx
1999

output:

4194

result:

ok single line: '4194'

Test #21:

score: 0
Accepted
time: 3ms
memory: 21084kb

input:

xxiiixxhhhxxiiixx
2000

output:

4196

result:

ok single line: '4196'

Test #22:

score: 0
Accepted
time: 4ms
memory: 19580kb

input:

xxiiixxhhhxxiiixxicpcicpc
2000

output:

4196

result:

ok single line: '4196'

Test #23:

score: 0
Accepted
time: 2ms
memory: 20944kb

input:

c
123

output:

123

result:

ok single line: '123'

Test #24:

score: 0
Accepted
time: 0ms
memory: 20516kb

input:

p
2000

output:

2000

result:

ok single line: '2000'

Test #25:

score: 0
Accepted
time: 0ms
memory: 20660kb

input:

nananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananana
500

output:

40100

result:

ok single line: '40100'

Test #26:

score: 0
Accepted
time: 19ms
memory: 23260kb

input:

czgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczg...

output:

1717

result:

ok single line: '1717'

Test #27:

score: 0
Accepted
time: 71ms
memory: 23336kb

input:

fjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxx...

output:

201000

result:

ok single line: '201000'

Test #28:

score: 0
Accepted
time: 72ms
memory: 23272kb

input:

uuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxpp...

output:

134469

result:

ok single line: '134469'

Test #29:

score: 0
Accepted
time: 15ms
memory: 22580kb

input:

ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

440469

result:

ok single line: '440469'

Test #30:

score: 0
Accepted
time: 71ms
memory: 23176kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

2001000

result:

ok single line: '2001000'

Test #31:

score: 0
Accepted
time: 0ms
memory: 20924kb

input:

a
1

output:

1

result:

ok single line: '1'

Test #32:

score: 0
Accepted
time: 0ms
memory: 20560kb

input:

z
1

output:

1

result:

ok single line: '1'

Test #33:

score: 0
Accepted
time: 0ms
memory: 19760kb

input:

cc
1

output:

1

result:

ok single line: '1'

Test #34:

score: 0
Accepted
time: 0ms
memory: 19756kb

input:

gg
1

output:

1

result:

ok single line: '1'

Test #35:

score: 0
Accepted
time: 3ms
memory: 19420kb

input:

yx
2

output:

2

result:

ok single line: '2'

Test #36:

score: 0
Accepted
time: 2ms
memory: 20204kb

input:

tr
2

output:

2

result:

ok single line: '2'

Test #37:

score: 0
Accepted
time: 2ms
memory: 19488kb

input:

xxyxxyx
20

output:

49

result:

ok single line: '49'