#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
ll a, b, c;
cin >> a >> b >> c;
bool cmp[n][n]{};
for (int i = 0; i < n; i++) {
for (int j = 0; j + i < n; j++) {
cmp[i][j] = (0 <= i - 1? cmp[i - 1][j] : 1) && (s[i] == s[j + i]);
}
}
ll dp[n + 1]{};
for (int i = 0; i < n; i++) {
dp[i] = 1e18;
}
for (int i = n - 1; i >= 0; i--) {
dp[i] = dp[i + 1] + a;
ll dp2[n + 1]{};
for (int j = n - 1; j >= 0; j--) {
dp2[j] = min(dp2[j + 1] + a, dp[j]);
if (i - 1 >= 0 && cmp[i - 1][j] && j + i + 1 < n) {
dp2[j] = min(dp2[j], dp2[j + i + 1] + c);
}
}
dp[i] = min(dp[i], dp2[0] + b);
}
cout << dp[0] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
16 ms |
3752 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |