# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568025 | dantoh000 | Copy and Paste 3 (JOI22_copypaste3) | C++14 | 3078 ms | 41300 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
int n;
string s;
int a,b,c;
int dp[4505][4505];
int hsh[4505][4505];
int mod = 1000000007;
int GRP[4505];
int H = 29;
map<int, vector<int> > groups;
main(){
scanf("%lld",&n);
cin >> s;
scanf("%lld%lld%lld",&a,&b,&c);
for (int i = 0; i < n; i++){
hsh[i][i] = 0;
for (int j = i+1; j <= n; j++){
hsh[i][j] = (hsh[i][j-1]*H + (s[j-1]-'a'+1))%mod;
}
}
for (int i = 0; i <= n; i++){
dp[i][i] = 0;
for (int j = i+1; j <= n; j++){
dp[i][j] = INF;
}
}
for (int i = 1; i <= n; i++){
for (int j = 0; j+i <= n; j++){
dp[j][j+i] = min(dp[j][j+i], min(dp[j+1][j+i], dp[j][j+i-1]) + a);
}
if (i <= n/2){
groups.clear();
for (int j = 0; j+i <= n; j++){
GRP[j] = hsh[j][j+i];
groups[GRP[j]].push_back(j);
}
for (int j = 0; j+i <= n; j++){
int G = GRP[j];
auto cur = j;
int idx = 0;
int ct = 0;
int dpValue = dp[j][j+i];
while (true){
ct++;
int L = j;
int R = cur + i;
dp[L][R] = min(dp[L][R], dpValue + b + ct*c + (R-L - i*ct)*a);
while (idx < groups[G].size() && groups[G][idx] < R) idx++;
if (idx == groups[G].size()) break;
cur = groups[G][idx];
}
}
}
}
printf("%lld\n",dp[0][n]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |