#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";
}
Compilation message
copypaste3.cpp: In function 'long long int appear(std::string, std::string)':
copypaste3.cpp:7:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | for (int i = 0; i < big.size(); i++)
| ~~^~~~~~~~~~~~
copypaste3.cpp: In function 'int32_t main()':
copypaste3.cpp:3:13: error: expected primary-expression before 'long'
3 | #define int long long
| ^~~~
copypaste3.cpp:33:22: note: in expansion of macro 'int'
33 | (i - x * int(a.first.size())) * add);
| ^~~
copypaste3.cpp:33:21: error: expected ')' before 'long'
33 | (i - x * int(a.first.size())) * add);
| ~ ^
| )