QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515313 | #2273. Suffixes may Contain Prefixes | untitledtwo# | WA | 32ms | 3996kb | C++17 | 1.8kb | 2024-08-11 17:03:39 | 2024-08-11 17:03:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[2010], t[2010];
int bd[2010];
int hs[2010][2], ht[2010][2];
const int M = 137, mod1 = 998244353, mod2 = 1000000007;
int pw1[2010], pw2[2010];
inline bool Check(int u, int v, int len)
{
return 1ll * (hs[u + len - 1][0] - hs[u - 1][0] + mod1) * pw1[v] % mod1 == 1ll * (ht[v + len - 1][0] - ht[v - 1][0] + mod1) * pw1[u] % mod1
&& 1ll * (hs[u + len - 1][1] - hs[u - 1][1] + mod2) * pw2[v] % mod2 == 1ll * (ht[v + len - 1][1] - ht[v - 1][1] + mod2) * pw2[u] % mod2;
}
inline int LCP(int u, int v)
{
int L = 0, R = min(n - u + 1, m - v + 1);
while(L < R)
{
int mid = (L + R + 1) >> 1;
if(Check(u, v, mid))
L = mid;
else
R = mid - 1;
}
return L;
}
int main()
{
pw1[0] = pw2[0] = 1;
for(int i = 1; i <= 2000; i++)
{
pw1[i] = 1ll * pw1[i - 1] * M % mod1;
pw2[i] = 1ll * pw2[i - 1] * M % mod2;
}
scanf("%s", s + 1);
n = strlen(s + 1);
for(int i = 1; i <= n; i++)
{
ht[i][0] = hs[i][0] = (hs[i - 1][0] + 1ll * s[i] * pw1[i]) % mod1;
ht[i][1] = hs[i][1] = (hs[i - 1][1] + 1ll * s[i] * pw2[i]) % mod2;
}
for(int i = 1; i <= n; i++)
for(int j = 1; j < i; j++)
if(Check(1, i - j + 1, j))
bd[i] = j;
scanf("%d", &m);
int ans = 0;
for(int i = 1; i <= n; i++)
{
int tmp = (m - bd[i]) / (i - bd[i]), r = tmp * (i - bd[i]) + bd[i];
for(int j = 1; j <= r; j++)
t[j] = s[(j - 1) % (i - bd[i]) + 1];
for(int j = r + 1; j <= m; j++)
t[j] = s[j - r];
for(int i = 1; i <= m; i++)
{
ht[i][0] = (ht[i - 1][0] + 1ll * t[i] * pw1[i]) % mod1;
ht[i][1] = (ht[i - 1][1] + 1ll * t[i] * pw2[i]) % mod2;
}
int tot = 0;
for(int i = 1; i <= m; i++)
tot += LCP(1, i);
ans = max(ans, tot);
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 3996kb
input:
fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...
output:
852
result:
ok single line: '852'
Test #2:
score: -100
Wrong Answer
time: 32ms
memory: 3852kb
input:
ddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttddddddttddttddttddddtdddttddttddttdddddttddttddtddttddttddttddddtdddttddttddttdddddttddttddttddttddttddttddddtdddttddttddttdddddttddttddt...
output:
5893
result:
wrong answer 1st lines differ - expected: '5894', found: '5893'