#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int N=2525;
int n,a,b,c,lcs[N][N],maxB[N][N];
ll dp[N][N];
string s;
void solve(){
cin>>n>>s;
s=" "+s;
cin>>a>>b>>c;
foru(i,1,n) foru(j,1,n) if(s[i]==s[j]) lcs[i][j]=lcs[i-1][j-1]+1;
foru(i,1,n){
foru(j,i,n){
int tmp=max(i+1, j-lcs[i][j]+1);
maxi(maxB[tmp][j],i);
}
}
foru(i,1,n) foru(j,1,n) maxi(maxB[i][j],maxB[i-1][j]);
memset(dp,0x3f,sizeof(dp));
foru(r,1,n){
dp[r][r]=a;
ford(l,r,1){
mini(dp[l-1][r], dp[l][r]+a);
mini(dp[l][r+1], dp[l][r]+a);
int len=r-l+1, lst=r, cnt=1;
while(true){
lst=maxB[lst-len+1][lst];
if(lst==0) break;
++cnt;
mini(dp[lst-len+1][r], dp[l][r] + b + 1LL*c*cnt + 1LL*a*(r-(lst-len+1)+1 - cnt*len));
}
}
}
cout<<dp[1][n]<<'\n';
}
int32_t main(){
#define task "test"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc=1; //cin>>tc;
foru(i,1,tc){
solve();
}
}
Compilation message (stderr)
copypaste3.cpp: In function 'int32_t main()':
copypaste3.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
copypaste3.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |