이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define pill pair<ll, ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 211 + 1;
const ll hsh[2] = {1555555699, 1222222763};
const ll P = 113;
ll n;
string a;
ll dp[N][N], dp2[N];
ll A, B, C;
bool eq[N][N][N];
int main() {
speed;
cin >> n;
cin >> a;
cin >> A >> B >> C;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
dp[i][j] = 1e15;
for(int st = 1; st <= n; st++) {
if(a[i + st - 1] != a[j + st - 1])
break;
eq[i][j][st] = 1;
}
}
}
for(int k = 1; k <= n; k++) {
for(int i = 0; i + k - 1 < n; i++) {
dp[i][i + k - 1] = min(dp[i][i + k - 1], A * k + B);
for(int j = 0; j < n; j++) {
for(int z = j; z <= n; z++) {
dp2[z] = 1e15;
}
dp2[j] = dp[i][i + k - 1];
for(int z = j; z < n; z++) {
if(eq[i][z][k])
dp2[z + k] = min(dp2[z + k], dp2[z] + C);
dp2[z + 1] = min(dp2[z + 1], dp2[z] + A);
}
for(int z = j + 1; z <= n; z++) {
dp[j][z - 1] = min(dp[j][z - 1], dp2[z] + B);
}
}
}
}
cout << dp[0][n - 1] - B;
}
# | 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... |