Submission #1004302

#TimeUsernameProblemLanguageResultExecution timeMemory
1004302De3b0oCopy and Paste 3 (JOI22_copypaste3)C++14
25 / 100
415 ms50480 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; bitset<1600000090> e; ll dp[209][209]; vector<ll> idx[209][209]; ll gt(ll i , ll j , ll l1 , ll r1) { ll l = 0 , r = idx[i][j].size()-1; ll sum = 0; while(l<=r) { if(idx[i][j][mid]>r1) r=mid-1; else { sum=mid+1; l=mid+1; } } sum*=(j-i+1); return sum; } ll solve(ll l , ll r) { if(dp[l][r]) return dp[l][r]; ll ans = (r-l+1)*A; for(ll i = l ; r>i ; i++) { for(ll j = i ; r>j ; j++) { ll ans1 = solve(i,j) + B + (i-l)*A + C; ll y = gt(i,j,j+1,r); ans1+=y/(j-i+1)*C; ans1+=(r-j-y)*A; ans=min(ans,ans1); } } dp[l][r]=ans; return ans; } int main() { cin >> n; cin >> s; cin >> A >> B >> C; for(ll i = 0 ; n>i ; i++) { for(ll j = i ; n>j ; j++) { for(ll i1 = j+1 ; n>i1 ; i1++) { ll j1 = i1+(j-i); if(j1>=n) break; e[i+j*n+i1*n*n+j1*n*n*n]=1; for(ll h = i ; j>=h ; h++) { if(s[h]!=s[i1+(h-i)]) e[i+j*n+i1*n*n+j1*n*n*n]=0; } } for(int h = j+1 ; n>h ; h++) { ll i1 = h , j1 = h+j-i; if(j1>=n) break; if(e[i+j*n+i1*n*n+j1*n*n*n]) { idx[i][j].pb(j1); h=j1; } } } } ll ans = solve(0,n-1); cans }
#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...