이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |