QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515492 | #2269. To be Connected, or not to be, that is the Question | untitledtwo | WA | 0ms | 3860kb | C++17 | 825b | 2024-08-11 18:03:09 | 2024-08-11 18:03:10 |
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: 0ms
memory: 3860kb
input:
2 0 861866350 106689920
output:
0
result:
wrong answer 1st lines differ - expected: '106689920', found: '0'