#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
#define MP make_pair
ll t;
string s;
ll a,b,c;
ll n;
ll dp[2510][2510];
ll type[2510][2510];
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
cin>>t;
// while (t--){
cin>>s;
cin>>a>>b>>c;
n = sz(s);
s = "x" + s;
for (ll k = 1;k <= n;k ++){
ll ptr = 1;
for (ll l = 1,r = k; r <= n; l++,r++){
for (ll l1 = 1,r1 = k; l1 < l; l1++,r1++){
bool ok = 1;
for (ll j = 0;j < k;j ++){
if (s[j+l1] != s[j+l])ok = 0;
}
if (ok){type[k][l] = type[k][l1];break;}
}
if (type[k][l] == 0)type[k][l] = ptr++;
// cout<<type[k][l]<<' ';
}
// cout<<'\n';
}
for (ll k = 1;k <= n;k ++){
for (ll l = 1,r = k; r <= n; l++,r++){
dp[l][r] = (r-l+1)*a;
for (ll l1 = l;l1 <= r;l1 ++){
for (ll r1 = l1;r1 <= r;r1 ++){
ll sz = r1-l1+1;
ll sum = dp[l1][r1] + b;
for (ll j = l;j <= r;j ++){
if (j + sz - 1 <= r && type[sz][j] == type[sz][l1]){
sum += c;
j+=sz-1;
}
else{
sum += a;
// j++;
}
}
dp[l][r] = min(dp[l][r],sum);
}
}
}
}
// cout<<dp[3][5]<<'\n';
cout<<dp[1][n]<<'\n';
// }
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4448 KB |
Output is correct |
2 |
Correct |
1 ms |
2400 KB |
Output is correct |
3 |
Execution timed out |
3098 ms |
64660 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
2516 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
2 ms |
4700 KB |
Output is correct |
27 |
Correct |
2 ms |
4604 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
2516 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
2 ms |
4700 KB |
Output is correct |
27 |
Correct |
2 ms |
4604 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
122 ms |
4924 KB |
Output is correct |
41 |
Correct |
1412 ms |
7764 KB |
Output is correct |
42 |
Execution timed out |
3047 ms |
7504 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
2516 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
2 ms |
4700 KB |
Output is correct |
27 |
Correct |
2 ms |
4604 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
122 ms |
4924 KB |
Output is correct |
41 |
Correct |
1412 ms |
7764 KB |
Output is correct |
42 |
Execution timed out |
3047 ms |
7504 KB |
Time limit exceeded |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
4448 KB |
Output is correct |
12 |
Correct |
1 ms |
2400 KB |
Output is correct |
13 |
Execution timed out |
3098 ms |
64660 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |