이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define MAXN 37
using namespace std;
const long long inf=1e15;
const long long mod=1000000000100011;
int n;
long long a,b,c;
char s[MAXN];
long long dp[MAXN][MAXN][MAXN][MAXN][2*MAXN];
bool li[MAXN][MAXN][MAXN][MAXN][2*MAXN];
long long hesh(int l,int r){
long long res=0;
for(int i=l;i<=r;i++){
res*=26; res+=s[i]-'a';
res%=mod;
}
return res;
}
long long ff(int l,int r,int ll,int rr,int step){
if(step>2*n)return inf;
if(l==1 and r==n)return 0;
if(li[l][r][ll][rr][step])return dp[l][r][ll][rr][step];
li[l][r][ll][rr][step]=true;
dp[l][r][ll][rr][step]=inf;
if(l==0 and r==0){
dp[l][r][ll][rr][step]=ff(ll,rr,ll,rr,step+1)+c;
for(int i=1;i<=n;i++){
dp[l][r][ll][rr][step]=min(dp[l][r][ll][rr][step],ff(i,i,ll,rr,step+1)+a);
}
return dp[l][r][ll][rr][step];
}
dp[l][r][ll][rr][step]=ff(0,0,l,r,step+1)+b;
if(r<n){
dp[l][r][ll][rr][step]=min(dp[l][r][ll][rr][step],ff(l,r+1,ll,rr,step+1)+a);
}
if(ll!=0 and r+(rr-ll+1)<=n and hesh(ll,rr)==hesh(r+1,r+(rr-ll+1))){
dp[l][r][ll][rr][step]=min(dp[l][r][ll][rr][step],ff(l,r+(rr-ll+1),ll,rr,step+1)+c);
}
return dp[l][r][ll][rr][step];
}
int main(){
cin>>n>>(s+1);
cin>>a>>b>>c;
cout<<ff(0,0,0,0,0)<<"\n";
return 0;
}
# | 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... |