| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1309225 | thuhienne | Copy and Paste 3 (JOI22_copypaste3) | C++20 | 3096 ms | 49748 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define thuhien ""
#define re exit(0);
#define hash __hash__
int n;
string s;
int a,b,c;
const ll mod = 1e9 + 7,base = 31;
ll hash[2509],power[2509];
void createhash() {
power[0] = 1;
for (int i = 1;i <= n;i++) {
hash[i] = (hash[i - 1] * base + s[i] - 'a' + 1) % mod;
power[i] = power[i - 1] * base % mod;
}
}
int gethash(int l,int r) {
return (hash[r] - hash[l - 1] * power[r - l + 1] + mod * mod) % mod;
}
ll dp[2509][2509];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
if (fopen(thuhien".inp","r")) {
freopen(thuhien".inp","r",stdin);
freopen(thuhien".out","w",stdout);
}
cin >> n >> s >> a >> b >> c;
s = " " + s;
createhash();
memset(dp,0x3f3f,sizeof(dp));
for (int i = 1;i <= n;i++) dp[i][i] = a;
for (int len = 1;len <= n;len++) {
for (int i = 1;i + len - 1 <= n;i++) {
int l = i,r = i + len - 1;
dp[l][r] = min(dp[l][r],min(dp[l + 1][r],dp[l][r - 1]) + a);
}
for (int i = 1;i + len - 1 <= n;i++) {
int l = i,r = i + len - 1;
int cnt = 1,last = r;
for (int j = r + 1;j + len - 1 <= n;j++) {
int x = j,y = j + len - 1;
if (gethash(l,r) != gethash(x,y)) continue;
if (x > last) {
cnt++;
last = y;
}
dp[l][y] = min(dp[l][y],dp[l][r] + b + 1ll * c * cnt + 1ll * (y - l + 1 - cnt * len) * a);
// cout << ":D " << l << " " << r << " " << dp[l][r] << '\n';
}
}
}
cout << dp[1][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... | ||||
