Submission #861005

#TimeUsernameProblemLanguageResultExecution timeMemory
861005willychanCopy and Paste 3 (JOI22_copypaste3)C++14
15 / 100
3055 ms1112 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; //#include<bits/extc++.h> //__gnu_pbds #define pt pair<pair<int,int>,pair<int,int> > #define xl first.first #define xr first.second #define yl second.first #define yr second.second const int N = 205; ll dp[N][N]; string s; int a,b,c; const int MOD = 1e9+7; int hsh[N]; int ppow[N]; int get(int l,int r){ ll ans = hsh[r]; ans = (ans-(1LL*hsh[l-1]*ppow[r-l+1])%MOD)%MOD; if(ans<0) ans+=MOD; return ans; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n;cin>>n; cin>>s; cin>>a>>b>>c; ppow[0]=1; for(int i=1;i<=n;i++){ hsh[i] = (1LL*hsh[i-1]*31)%MOD; hsh[i]+=(s[i-1]-'a'); hsh[i]%=MOD; ppow[i] = (31LL*ppow[i-1])%MOD; } for(int i=0;i<=n+1;i++){ for(int j=i;j<=n+1;j++) dp[i][j]=1LL*(j-i+1)*a+b; } for(int l=0;l<n;l++){ for(int i=1;i+l<=n;i++){ for(int l2=0;l2<l;l2++){ for(int j=1;j+l2<=n;j++){ ll re = 0; for(int h=i;h<=i+l;h++){ if(h+l2<=i+l && get(h,h+l2)==get(j,j+l2)){ h= h+l2; re+=c; }else{ re+=a; } } // if(dp[i][i+l]>re+dp[j][j+l2]+c){ // cout<<i<<" "<<i+l<<"<-"<<j<<" "<<j+l2<<"\n"; // } dp[i][i+l] = min(dp[i][i+l],re+dp[j][j+l2]+b); } } // cout<<dp[i][i+l]<<" "; } //cout<<"\n"; } cout<<dp[1][n]-b<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...