Submission #1004183

#TimeUsernameProblemLanguageResultExecution timeMemory
1004183De3b0oCopy and Paste 3 (JOI22_copypaste3)C++14
1 / 100
3087 ms2396 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second #define in insert #define pb push_back #define ppb pop_back() #define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define cans cout << ans << "\n"; #define yes cout << "Yes" << "\n"; #define no cout << "No" << "\n"; #define pll pair<ll,ll> #define lin cout << "\n"; #define sqr 340 #define mod 1000000007 #define mid ((l+r)/2) #define lc (2*x) #define rc (2*x+1) using namespace std; ll n; string s; ll A , B , C; bool e[39][39][39][39]; ll dp[39][39]; ll solve(ll l , ll r) { if(l>r) return 0; if(dp[l][r]) return dp[l][r]; ll ans = (r-l+1)*A; for(int i = l ; r>=i ; i++) { for(int j = i ; r>=j ; j++) { for(int i1 = j+1 ; r>=i1 ; i1++) { for(int j1 = i1 ; r>=j1 ; j1++) { if((j1-i1+1)%(j-i+1)!=0) continue; bool g = 0; for(int h = 0 ; (j1-i1+1)/(j-i+1)>h ; h++) { if(!e[i][j][i1+h*(j-i+1)][i1+(h+1)*(j-i+1)-1]) g=1; } if(g) continue; ll ans1 = (i-1-l+1)*A + solve(i,j) + B + C + A*(i1-j-1) + (j1-i1+1)/(j-i+1)*C + (r-(j1+1)+1)*A; ans=min(ans,ans1); } } } } dp[l][r]=ans; return ans; } int main() { d3 cin >> n; cin >> s; cin >> A >> B >> C; for(int i = 0 ; n>i ; i++) { for(int j = i ; n>j ; j++) { for(int i1 = j+1 ; n>i1 ; i1++) { for(int j1 = i1 ; n>j1 ; j1++) { if(j-i!=j1-i1) continue; e[i][j][i1][j1]=1; for(int h = i ; j>=h ; h++) { if(s[h]!=s[i1+(h-i)]) e[i][j][i1][j1]=0; } } } } } cout << solve(0,n-1); }
#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...