# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
938580 | Pannda | Copy and Paste 3 (JOI22_copypaste3) | C++17 | 1638 ms | 74076 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;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
int a, b, c;
cin >> n >> s >> a >> b >> c;
const long long INF = 2e18;
vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, INF));
vector<vector<int>> link(n, vector<int>(n + 1, n));
for (int begin = n - 1; begin >= 0; begin--) {
vector<int> z(n, 0);
for (int i = begin + 1, l = 0, r = 0; i < n; i++) {
while (s[begin + z[i]] == s[i + z[i]]) z[i]++;
}
dp[begin][begin] = 0;
for (int len = 1; len <= n - begin; len++) {
dp[begin][begin + len] = min(dp[begin][begin + len], dp[begin][begin + len - 1] + a);
dp[begin][begin + len] = min(dp[begin][begin + len], dp[begin + 1][begin + len] + a);
link[begin][len] = n;
for (int j = begin + len; j < n; j++) {
if (z[j] >= len) {
link[begin][len] = j;
break;
}
}
int cur = link[begin][len];
int cnt = 1;
while (cur < n) {
cnt++;
dp[begin][cur + len] = min(dp[begin][cur + len], dp[begin][begin + len] + b + 1LL * cnt * c + 1LL * (cur + len - begin - len * cnt) * a);
cur = link[cur][len];
}
}
}
cout << dp[0][n] << '\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... |