Submission #950029

#TimeUsernameProblemLanguageResultExecution timeMemory
950029hotboy2703Copy and Paste 3 (JOI22_copypaste3)C++14
15 / 100
3098 ms64660 KiB
#include<bits/stdc++.h> using ll = long long; using namespace std; #define pll pair <ll,ll> #define fi first #define se second #define sz(a) (ll((a).size())) #define BIT(mask,i) (((mask) >> (i))&1) #define MASK(i) (1LL << (i)) #define MP make_pair ll t; string s; ll a,b,c; ll n; ll dp[2510][2510]; ll type[2510][2510]; int main(){ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); cin>>t; // while (t--){ cin>>s; cin>>a>>b>>c; n = sz(s); s = "x" + s; for (ll k = 1;k <= n;k ++){ ll ptr = 1; for (ll l = 1,r = k; r <= n; l++,r++){ for (ll l1 = 1,r1 = k; l1 < l; l1++,r1++){ bool ok = 1; for (ll j = 0;j < k;j ++){ if (s[j+l1] != s[j+l])ok = 0; } if (ok){type[k][l] = type[k][l1];break;} } if (type[k][l] == 0)type[k][l] = ptr++; // cout<<type[k][l]<<' '; } // cout<<'\n'; } for (ll k = 1;k <= n;k ++){ for (ll l = 1,r = k; r <= n; l++,r++){ dp[l][r] = (r-l+1)*a; for (ll l1 = l;l1 <= r;l1 ++){ for (ll r1 = l1;r1 <= r;r1 ++){ ll sz = r1-l1+1; ll sum = dp[l1][r1] + b; for (ll j = l;j <= r;j ++){ if (j + sz - 1 <= r && type[sz][j] == type[sz][l1]){ sum += c; j+=sz-1; } else{ sum += a; // j++; } } dp[l][r] = min(dp[l][r],sum); } } } } // cout<<dp[3][5]<<'\n'; cout<<dp[1][n]<<'\n'; // } }
#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...