#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define opa(x) cout << #x << " = " << x << ", ";
#define op(x) cout << #x << " = " << x << endl;
#define ops(x) cout << x;
#define entr cout << endl;
#define spac cout << ' ';
#define all(x) (x).begin(), (x).end()
#define STL(x) cout << #x << " : "; for(auto &qwe:x) cout << qwe << ' '; cout << endl;
#define arr(x, n) cout << #x << " : "; loop(qwe,0,n) cout << x[qwe] << ' '; cout << endl;
#define deb1 cout << "deb1" << endl;
#define deb2 cout << "deb2" << endl;
#define deb3 cout << "deb3" << endl;
#define deb4 cout << "deb4" << endl;
#define deb5 cout << "deb5" << endl;
using namespace std;
typedef long long ll;
const int mxn = 2510;
ll dp[mxn][mxn];
const ll INF = 1e18;
void solve(){
int n, A, B, C;
string s;
cin >> n >> s >> A >> B >> C;
loop(i,0,n+1){
loop(j,0,n+1){
dp[i][j] = INF;
}
}
priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> pq;
pq.push({0, {0, 0}});
dp[0][0] = 0;
while(!pq.empty()){
int i = pq.top().ss.ff;
int j = pq.top().ss.ss;
ll dis = pq.top().ff;
pq.pop();
if(dis != dp[i][j]) continue;
if(dp[0][i] > dis + B){ // cut
pq.push({dis + B, {0, i}});
dp[0][i] = dis + B;
}
if(i + 1 <= n){
if(dp[i+1][j] > dis + A){ // add 'a'
pq.push({dis + A, {i+1, j}});
dp[i+1][j] = dis + A;
}
}
if(i + j <= n){
if(dp[i+j][j] > dis + C){ // add 'a'
pq.push({dis + C, {i+j, j}});
dp[i+j][j] = dis + C;
}
}
}
ll ans = INF;
loop(i,0,n+1){
ans = min(ans, dp[n][i]);
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
// freopen("test_input.txt", "r", stdin);
int t = 1;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2500 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
482 ms |
47288 KB |
Output is correct |
4 |
Correct |
569 ms |
45852 KB |
Output is correct |
5 |
Correct |
746 ms |
78376 KB |
Output is correct |
6 |
Correct |
581 ms |
48220 KB |
Output is correct |
7 |
Correct |
1073 ms |
116748 KB |
Output is correct |
8 |
Correct |
673 ms |
49948 KB |
Output is correct |
9 |
Correct |
580 ms |
50136 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |