//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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
78 ms |
77852 KB |
Output is correct |
4 |
Correct |
92 ms |
86548 KB |
Output is correct |
5 |
Correct |
103 ms |
91196 KB |
Output is correct |
6 |
Correct |
95 ms |
94696 KB |
Output is correct |
7 |
Correct |
102 ms |
98404 KB |
Output is correct |
8 |
Correct |
101 ms |
98472 KB |
Output is correct |
9 |
Correct |
105 ms |
98380 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 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 |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |