Submission #710856

#TimeUsernameProblemLanguageResultExecution timeMemory
710856minhcoolCopy and Paste 3 (JOI22_copypaste3)C++17
15 / 100
3058 ms8740 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 2e3 + 5; const int mod = 1e9 + 7, oo = 1e18 + 7; int n, a, b, c; string s; int dp[N][N]; void process(){ cin >> n >> s >> a >> b >> c; s = '*' + s; for(int i = 1; i <= n; i++) dp[i][i] = a; for(int dist = 2; dist <= n; dist++){ for(int le = 1; le <= n; le++){ int ri = le + dist - 1; if(ri > n) break; dp[le][ri] = min(dp[le + 1][ri], dp[le][ri - 1]) + a; for(int i = le; i < ri; i++){ int total = dp[le][i] + b + c, itr = i + 1; while(itr <= ri){ string temp1 = s.substr(le, i - le + 1), temp2 = s.substr(itr, min(i - le + 1, ri - itr + 1)); if(temp1 != temp2){ itr++; total += a; } else{ itr += (i - le + 1); total += c; } } dp[le][ri] = min(dp[le][ri], total); } // cout << le << " " << ri << " " << dp[le][ri] << "\n"; } } cout << dp[1][n] << "\n"; } signed main(){ ios_base::sync_with_stdio(0); //freopen("KEK.inp", "r", stdin); //freopen("KEK.out", "w", stdout); cin.tie(0); process(); }
#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...