#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL << 60;
int dp[2501][2501];
int chmin(int& x, int y){
return x = min(x, y);
}
const int a = 32913, m = 1e9 + 7;
int pw[2501], h[2501];
int ha(int l, int len){
return ((h[l + len] - h[l] * pw[len]) % m + m) % m;
}
int H[2501][2501];
int32_t main(){
int n; string s; cin >> n >> s;
int A, B, C; cin >> A >> B >> C;
pw[0] = 1;
for(int i = 0; i < n; i++)
pw[i + 1] = pw[i] * a % m, h[i + 1] = (h[i] * a + s[i]) % m;
for(int l = 0; l < n; l++){
for(int r = l; r < n; r++){
H[l][r] = ha(l, r - l + 1);
}
}
for(int sz = 2; sz <= n; sz++){
for(int l = 0; l <= n - sz; l++){
dp[l][l + sz - 1] = INF;
}
}
for(int sz = 1; sz <= n; sz++){
if(sz != 1){
for(int l = 0; l <= n - sz; l++){
int r = l + sz - 1;
dp[l][r] = min(dp[l][r], min(dp[l][r - 1], dp[l + 1][r]) + A);
}
}else{
for(int l = 0; l < n; l++) dp[l][l] = A;
}
unordered_map<int, vector<int>> M;
for(int l = 0; l <= n - sz; l++){
M[ha(l, sz)].push_back(l);
}
for(auto& [h, v] : M){
int k = v.size();
for(int l = 0; l < k; l++){
int _acc = 0, _max = -1;
for(int r = l; r < k; r++){
if(v[r] > _max){
_acc++; _max = v[r] + sz - 1;
dp[v[l]][_max] = min(dp[v[l]][_max], dp[v[l]][v[l] + sz - 1] + (_max - v[l] + 1 - _acc * sz) * A + B + _acc * C);
}
}
}
}
}
cout << dp[0][n - 1] << endl;
}
Compilation message
copypaste3.cpp: In function 'int32_t main()':
copypaste3.cpp:54:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | for(auto& [h, v] : M){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1095 ms |
41204 KB |
Output is correct |
4 |
Correct |
1318 ms |
46844 KB |
Output is correct |
5 |
Correct |
1499 ms |
53168 KB |
Output is correct |
6 |
Correct |
1840 ms |
59948 KB |
Output is correct |
7 |
Correct |
2284 ms |
67344 KB |
Output is correct |
8 |
Correct |
2371 ms |
67412 KB |
Output is correct |
9 |
Correct |
2347 ms |
67340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
432 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
564 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
568 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
568 KB |
Output is correct |
28 |
Correct |
1 ms |
568 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
564 KB |
Output is correct |
32 |
Correct |
1 ms |
560 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
432 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
564 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
568 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
568 KB |
Output is correct |
28 |
Correct |
1 ms |
568 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
564 KB |
Output is correct |
32 |
Correct |
1 ms |
560 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
948 KB |
Output is correct |
41 |
Correct |
3 ms |
2232 KB |
Output is correct |
42 |
Correct |
4 ms |
2232 KB |
Output is correct |
43 |
Correct |
4 ms |
2260 KB |
Output is correct |
44 |
Correct |
4 ms |
2228 KB |
Output is correct |
45 |
Correct |
4 ms |
2272 KB |
Output is correct |
46 |
Correct |
4 ms |
2260 KB |
Output is correct |
47 |
Correct |
3 ms |
2260 KB |
Output is correct |
48 |
Correct |
4 ms |
2260 KB |
Output is correct |
49 |
Correct |
4 ms |
2260 KB |
Output is correct |
50 |
Correct |
4 ms |
2228 KB |
Output is correct |
51 |
Correct |
3 ms |
2264 KB |
Output is correct |
52 |
Correct |
3 ms |
2260 KB |
Output is correct |
53 |
Correct |
4 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
432 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
564 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
568 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
568 KB |
Output is correct |
28 |
Correct |
1 ms |
568 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
564 KB |
Output is correct |
32 |
Correct |
1 ms |
560 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
948 KB |
Output is correct |
41 |
Correct |
3 ms |
2232 KB |
Output is correct |
42 |
Correct |
4 ms |
2232 KB |
Output is correct |
43 |
Correct |
4 ms |
2260 KB |
Output is correct |
44 |
Correct |
4 ms |
2228 KB |
Output is correct |
45 |
Correct |
4 ms |
2272 KB |
Output is correct |
46 |
Correct |
4 ms |
2260 KB |
Output is correct |
47 |
Correct |
3 ms |
2260 KB |
Output is correct |
48 |
Correct |
4 ms |
2260 KB |
Output is correct |
49 |
Correct |
4 ms |
2260 KB |
Output is correct |
50 |
Correct |
4 ms |
2228 KB |
Output is correct |
51 |
Correct |
3 ms |
2264 KB |
Output is correct |
52 |
Correct |
3 ms |
2260 KB |
Output is correct |
53 |
Correct |
4 ms |
2260 KB |
Output is correct |
54 |
Correct |
17 ms |
5436 KB |
Output is correct |
55 |
Correct |
181 ms |
16212 KB |
Output is correct |
56 |
Correct |
91 ms |
16332 KB |
Output is correct |
57 |
Correct |
86 ms |
16312 KB |
Output is correct |
58 |
Correct |
85 ms |
16212 KB |
Output is correct |
59 |
Incorrect |
96 ms |
16324 KB |
Output isn't correct |
60 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1095 ms |
41204 KB |
Output is correct |
14 |
Correct |
1318 ms |
46844 KB |
Output is correct |
15 |
Correct |
1499 ms |
53168 KB |
Output is correct |
16 |
Correct |
1840 ms |
59948 KB |
Output is correct |
17 |
Correct |
2284 ms |
67344 KB |
Output is correct |
18 |
Correct |
2371 ms |
67412 KB |
Output is correct |
19 |
Correct |
2347 ms |
67340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
308 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
432 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
316 KB |
Output is correct |
38 |
Correct |
1 ms |
564 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
568 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
568 KB |
Output is correct |
45 |
Correct |
1 ms |
568 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
564 KB |
Output is correct |
49 |
Correct |
1 ms |
560 KB |
Output is correct |
50 |
Correct |
1 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
948 KB |
Output is correct |
58 |
Correct |
3 ms |
2232 KB |
Output is correct |
59 |
Correct |
4 ms |
2232 KB |
Output is correct |
60 |
Correct |
4 ms |
2260 KB |
Output is correct |
61 |
Correct |
4 ms |
2228 KB |
Output is correct |
62 |
Correct |
4 ms |
2272 KB |
Output is correct |
63 |
Correct |
4 ms |
2260 KB |
Output is correct |
64 |
Correct |
3 ms |
2260 KB |
Output is correct |
65 |
Correct |
4 ms |
2260 KB |
Output is correct |
66 |
Correct |
4 ms |
2260 KB |
Output is correct |
67 |
Correct |
4 ms |
2228 KB |
Output is correct |
68 |
Correct |
3 ms |
2264 KB |
Output is correct |
69 |
Correct |
3 ms |
2260 KB |
Output is correct |
70 |
Correct |
4 ms |
2260 KB |
Output is correct |
71 |
Correct |
17 ms |
5436 KB |
Output is correct |
72 |
Correct |
181 ms |
16212 KB |
Output is correct |
73 |
Correct |
91 ms |
16332 KB |
Output is correct |
74 |
Correct |
86 ms |
16312 KB |
Output is correct |
75 |
Correct |
85 ms |
16212 KB |
Output is correct |
76 |
Incorrect |
96 ms |
16324 KB |
Output isn't correct |
77 |
Halted |
0 ms |
0 KB |
- |