# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061298 | kunzaZa183 | Copy and Paste 3 (JOI22_copypaste3) | C++17 | 0 ms | 0 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>
using namespace std;
#define int long long
map<string, int> msi;
int appear(string big, string small) {
int ct = 0;
for (int i = 0; i < big.size(); i++)
if (small == big.substr(i, small.size())) {
ct++;
i += small.size() - 1;
}
return ct;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
string s;
cin >> s;
int add, cut, paste;
cin >> add >> cut >> paste;
for (int i = 0; i < n; i++)
msi[s.substr(i, 1)] = add;
for (int i = 2; i <= n; i++) {
for (int j = 0; j < n; j++) {
if (!msi.count(s.substr(j, i))) {
int mini = add * i;
for (auto a : msi) {
int x = appear(s.substr(j, i), a.first);
mini = min(mini, a.second + cut + paste * x +
(i - x * int(a.first.size())) * add);
}
msi[s.substr(j, i)] = mini;
}
}
}
cout << msi[s] << "\n";
}