QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515493#2273. Suffixes may Contain PrefixesuntitledtwoWA 1ms6060kbC++17825b2024-08-11 18:03:262024-08-11 18:03:26

Judging History

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

  • [2024-08-11 18:03:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6060kb
  • [2024-08-11 18:03:26]
  • 提交

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'