This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 2505
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
//bool same[maxn][maxn][maxn];
int nxt[maxn][maxn];
ll dp[maxn][maxn], g[maxn][maxn];
int main() {
io
int n;
cin >> n;
string s;
cin >> s;
ll A, B, C;
cin >> A >> B >> C;
/*
for (int len = 1;len < n;len++) {
for (int i = 0;i <= n - len;i++) {
same[len][i][i] = 1;
for (int j = i + 1;j <= n - len;j++) {
if (s.substr(i, len) == s.substr(j, len)) {
same[len][i][j] = same[len][j][i] = 1;
if (!nxt[len][i]) nxt[len][i] = j;
}
}
}
}
*/
for (int i = 0;i <= n;i++) {
for (int j = 0;j <= n;j++) {
g[i][j] = inf;
for (int k = 0;k <= n;k++) dp[i][j] = inf;
}
}
ll ans = inf;
dp[0][0] = 0;
auto to = [&] (int i, int j, ll v) {
dp[i][j] = min(dp[i][j], v);
};
for (int j = 0;j <= n;j++) {
for (int i = 0;i <= n;i++) {
to(i+1, j, dp[i][j] + A);
if (i + j < maxn) to(i+j, j, dp[i][j] + C);
to(0, i, dp[i][j] + B);
if (i == n) ans = min(ans, dp[i][j]);
}
}
cout << ans << endl;
}
# | 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... |