QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259731#2273. Suffixes may Contain PrefixesPixelCat#AC ✓96ms19808kbC++202.1kb2023-11-21 12:22:482023-11-21 12:22:48

Judging History

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

  • [2023-11-21 12:22:48]
  • 评测
  • 测评结果:AC
  • 用时:96ms
  • 内存:19808kb
  • [2023-11-21 12:22:48]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 2000;
const int INF = INT_MAX;

int dp[MAXN + 10][MAXN + 10];
vector<int> adj[MAXN + 10];
int val[MAXN + 10];

vector<int> build(string s) {
    vector<int> f(sz(s) + 1, 0);
    int k = 0;
    for(int i = 1; i < sz(s); i++) {
        while(k && s[k] != s[i]) k = f[k];
        if(s[k] == s[i]) k++;
        f[i + 1] = k;
    }
    return f;
}

vector<int> get_z(string s) {
    int n = sz(s);
    vector<int> Z(n);
    int l = 0, r = 0;
    for(int i = 0; i < n; i++) {
        Z[i] = max(min(Z[i - l], r - i), 0);
        while(i + Z[i] < sz(s) && s[Z[i]] == s[i + Z[i]]) {
            l = i; r = i + Z[i]; Z[i]++;
        }
        val[i + 1]++;
        val[i + Z[i] + 1]--;
    }
    val[1] = 1;
    for(int i = 1; i <= n; i++) val[i] += val[i - 1];
    // For(i, 0, n) cout << val[i] << " \n"[i == n];
    return Z;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s; cin >> s;
    int len; cin >> len;
    int n = sz(s);
    get_z(s);
    auto fail = build(s);
    for(int i = 0; i <= n; i++) {
        For(c, 0, 25) {
            int k = i;
            if(k == n) k = fail[k];
            while(k && char(c + 'a') != s[k]) k = fail[k];
            if(char(c + 'a') == s[k]) k++;
            adj[k].eb(i);
        }
    }
    For(i, 0, n) {
        sort(all(adj[i]));
        adj[i].erase(unique(all(adj[i])), adj[i].end());
        // cout << i << " ->";
        // for(auto &j:adj[i]) cout << " " << j;
        // cout << "\n";
    }
    For(i, 0, len) For(j, 0, n) dp[i][j] = -INF;
    dp[0][0] = 0;
    For(i, 1, len) For(j, 0, n) {
        for(auto &k:adj[j]) dp[i][j] = max(dp[i][j], dp[i - 1][k]);
        dp[i][j] += val[j];
    }
    int mx = 0;
    For(i, 0, n) mx = max(mx, dp[len][i]);
    cout << mx << "\n";
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 6624kb

input:

fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...

output:

852

result:

ok single line: '852'

Test #2:

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

input:

ddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttddddddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddt...

output:

5894

result:

ok single line: '5894'

Test #3:

score: 0
Accepted
time: 9ms
memory: 19508kb

input:

wswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswswswwwsswswswwwswswswwwswswsswswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswwswswwwswswswwwsswswswwwswswswwwswswwwswswswwwsswswswwwswswssswwswwswswwwswsws...

output:

10500

result:

ok single line: '10500'

Test #4:

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

input:

sjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjsspffsjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsjssjssjsspffsjsspfsjsspffsjssjsspffsjsspfsjsspffsjsspsjsspffsjsspfsjsspffsjssjfsjsspffsjsspfsjsspffsj...

output:

4267

result:

ok single line: '4267'

Test #5:

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

input:

mmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpmmpmmmpmmpmpmmpmmmppmmpmmmpmmpmpfmzmmpmmmmmpmmmmmpmmmmpmmmpmmpmpfmzmmpmmmmmpfqmmpmmmpmmpmpfmzmmpmmmmmpmmmpmmpmpm...

output:

9536

result:

ok single line: '9536'

Test #6:

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

input:

pepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepepypgakpepypopepepypopepypopepepyzpepypopepepypepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepypopepepypopepypopepvplpepypopepepypopepypopepepyzpepypopepepypoperpepypopepepypopepypopepepyzpepypopepep...

output:

4033

result:

ok single line: '4033'

Test #7:

score: 0
Accepted
time: 12ms
memory: 19808kb

input:

fifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfyqnfifuurfifuugfifuurfifufifuurfifuugfifuurxvfifuurfifuugfifuurfifufifuurfifuugfifuurfifuefifuurfifuugfifuurfifufifuurfifuugfiffifuurfifuu...

output:

9452

result:

ok single line: '9452'

Test #8:

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

input:

gwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgxlggwcgwgxrgwgxlggwgxihdggwgxlggwcgwgxlgwgxlmgwgxlgwgxlggwgxihdggwgxlggwcgwtxgwgxlggwgxihdggwgwvgwgxlggwgxihdggw...

output:

3584

result:

ok single line: '3584'

Test #9:

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

input:

aabaacaabaa
101

output:

249

result:

ok single line: '249'

Test #10:

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

input:

aabaacaabaa
102

output:

251

result:

ok single line: '251'

Test #11:

score: 0
Accepted
time: 1ms
memory: 5948kb

input:

aabaacaabaa
103

output:

253

result:

ok single line: '253'

Test #12:

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

input:

aabaacaabaa
104

output:

255

result:

ok single line: '255'

Test #13:

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

input:

aabaacaabaa
105

output:

257

result:

ok single line: '257'

Test #14:

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

input:

cciccpccicc
2000

output:

4995

result:

ok single line: '4995'

Test #15:

score: 0
Accepted
time: 1ms
memory: 3948kb

input:

lkultxuuxtkltukllulxkltuutkuuttkuxutuuxuutuxtkxktklltllulkltxtttkkkxxtuxltkxtxtttlltttlkkkutkkuxulklxuuxullkkxtktlxtutuxlktkkllxutlllxkltkutxltxtlluxxlxxxklxlluuxllllxxlllluktkxtkutluktxkkukluktkkuktlkkultukulxlxkltlllkkluluutkxlxkuktktxxtkkkkkuxtxttkxtuxkkttklltulktltxkutluuulluxtuxlllltlutxulxxltk...

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 1ms
memory: 3868kb

input:

zrszgeggmmagjcibhsuuugohqppnncuuksrynidfbmhaqpnzswblenhttvtgadwjybijjwhixqppgzqajdqbmjrgaziljastkonutvyqrxtvshhoidkixodyrekyshlafxnikbgaqegxbgwmpgbxnpkdxhnhcocmbpimftogrlydyqitekbfvtimiztujfejkomujzztadjhrvdqlakxnbctuaubumwlwyibmyjabrrdznkvndghplgqjmcvqhmgbsrnpmjjbkkqmnvzczlpsrgdmsmmcgksbkhzatnpiwch...

output:

2

result:

ok single line: '2'

Test #17:

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

input:

xxiiixxhhhxxiiixx
1996

output:

4187

result:

ok single line: '4187'

Test #18:

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

input:

xxiiixxhhhxxiiixx
1997

output:

4190

result:

ok single line: '4190'

Test #19:

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

input:

xxiiixxhhhxxiiixx
1998

output:

4192

result:

ok single line: '4192'

Test #20:

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

input:

xxiiixxhhhxxiiixx
1999

output:

4194

result:

ok single line: '4194'

Test #21:

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

input:

xxiiixxhhhxxiiixx
2000

output:

4196

result:

ok single line: '4196'

Test #22:

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

input:

xxiiixxhhhxxiiixxicpcicpc
2000

output:

4196

result:

ok single line: '4196'

Test #23:

score: 0
Accepted
time: 1ms
memory: 6084kb

input:

c
123

output:

123

result:

ok single line: '123'

Test #24:

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

input:

p
2000

output:

2000

result:

ok single line: '2000'

Test #25:

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

input:

nananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananana
500

output:

40100

result:

ok single line: '40100'

Test #26:

score: 0
Accepted
time: 27ms
memory: 4604kb

input:

czgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczgczg...

output:

1717

result:

ok single line: '1717'

Test #27:

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

input:

fjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxxfjlpvbnxxx...

output:

201000

result:

ok single line: '201000'

Test #28:

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

input:

uuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxppuuarrprirpprxpp...

output:

134469

result:

ok single line: '134469'

Test #29:

score: 0
Accepted
time: 12ms
memory: 12620kb

input:

ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

440469

result:

ok single line: '440469'

Test #30:

score: 0
Accepted
time: 96ms
memory: 19764kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

2001000

result:

ok single line: '2001000'

Test #31:

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

input:

a
1

output:

1

result:

ok single line: '1'

Test #32:

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

input:

z
1

output:

1

result:

ok single line: '1'

Test #33:

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

input:

cc
1

output:

1

result:

ok single line: '1'

Test #34:

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

input:

gg
1

output:

1

result:

ok single line: '1'

Test #35:

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

input:

yx
2

output:

2

result:

ok single line: '2'

Test #36:

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

input:

tr
2

output:

2

result:

ok single line: '2'

Test #37:

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

input:

xxyxxyx
20

output:

49

result:

ok single line: '49'