QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515493 | #2273. Suffixes may Contain Prefixes | untitledtwo | WA | 1ms | 6060kb | C++17 | 825b | 2024-08-11 18:03:26 | 2024-08-11 18:03:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char st[100005];
int nxt[100005];
int f[2005][2005];
const int INF = 0x3f3f3f3f;
signed main() {
int n;
scanf("%s", st + 1);
scanf("%d", &n);
int len = strlen(st + 1);
for (int i = 2, j = 0; i <= len ; ++ i) {
while (j && st[i] != st[j + 1]) j = nxt[j];
if (st[j + 1] == st[i]) ++ j;
nxt[i] = j;
}
for (int i = 0; i <= n ; ++ i)
for (int j = 0; j <= len + 1 ; ++ j) f[i][j] = -INF;
f[0][0] = 0;
for (int i = 1; i <= n ; ++ i) {
for (int j = 0; j <= len ; ++ j)
if (i - (j - nxt[j]) >= 0) f[i][j] = max(f[i][j], f[i - (j - nxt[j])][nxt[j]] + j);
for (int j = len; j >= 0 ; -- j) f[i][j] = max(f[i][j], f[i][j + 1]);
}
int ans = 0;
for (int i = 0; i <= len ; ++ i) ans = max(ans, f[n][i]);
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6060kb
input:
fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...
output:
493
result:
wrong answer 1st lines differ - expected: '852', found: '493'